C++ program to calculate students mark and grade

C++ program to calculate students marks and grades. Find a student’s grade based on their performance in five subjects. Using a user-defined function, determine a student‘s grade based on marks earned in all subjects. The user can enter an unlimited number of subjects here.

A floating-point value is expressed as a mantissa plus an exponent or as a whole plus fractional digits (like decimal values). Float8 and double precision are synonyms for float. Four or eight bytes are used to store floating-point integers. Eight-byte integers are internally rounded to fifteen decimal digits.

#include<iostream>
using namespace std;
int main()
{
int marks[5], i;
float sum=0,avg;
cout<<"\n Enter the students marks\n";
cout<<"\n Geography";
cin>>marks[0];
cout<<"\n English";
cin>>marks[1];
cout<<"\n Maths";
cin>>marks[2];
cout<<"\n History";
cin>>marks[3];
cout<<"\n Science";
cin>>marks[4];

for(i=0;i<5;i++)
{
sum=sum+marks[i];
}
cout<<"\n Total marks of student"<<sum;
avg=sum/5;
cout<<"\n Average = "<<avg;
cout<<"\n Grade = ";
if(avg>80)
{
cout<<"A";
}
else if(avg>60 && avg<=80)
{
cout<<"B";
}
else if(avg>40 && avg<=60)
{
cout<<"C";
}
else
{
cout<<"D";
}
return 0;
}

Output:

Enter the student’s marks

Geography99

English88

Maths66

History67

Science56

Total marks of student376
Average = 75.2
Grade = B

What is purpose of namespace in c++

You may specify the context in which names are defined by using namespace. A namespace, in essence, establishes a scope. C++ includes a standard library that contains common features like containers and algorithms that you’ll utilise in your programmes.