In this tutorial you will learn about the C++ Program to Calculate Student Grade and its application with practical example.
In this tutorial, we will learn to create a c++ program that will Calculate Student Grade using c++ programming
Before starting with this tutorial we assume that you are best aware of the following C++ programming topics:
- Basic C++ programming.
- Basic input/output.
- Basic mathematics calculation.
C++ Program to Calculate Student Grade .
In this program we will Calculate Student Grade. We would first declared and initialized the required variables. Next, we would prompt user to input Subject numbers. Later we will find the grade of that student.
using namespace std;
int m,p,c,h,e,total=0; // declaring variables
cout<<"Enter 5 Subject marks :\n ";
cin>>m>>p>>c>>h>>e; // taking values from user
cout<<"Sum of 5 Subjects is ="<<total;
per=total/5; // calculating the percentage
if(per>85) // calculating grades..
else if(per<85 && per>=75)
else if(per<75 && per>=50)
else if(per<50 && per>=30)
In the above program, we have first declared and initialized a set variables required in the program.
- m = holds value of math.
- p = holds value of physics.
- c = holds value of chemistry
- h = holds value of Hindi.
- e= holds value of English.
- total = calculate sum of value.
- per= it will hold percentage.
In the next statement user will be prompted to enter the five subject marks which will be assigned to variable ‘m’,’p’,’c’,’h’,’e’.
after that we add all given values in variable total ( total =m+p+c+h+e ).Now, we calculated the percentage (per=total/5).Grades must be calculated based on following conditions.
If percentage > 85 then A grade.
elseIf (percentage < 85 && percentage >= 75) print B grade
else If percentage < 75 && percentage >= 50 print C grade
else If percentage > 30 && percentage <= 50 print D grade
else percentage <30 print fail.
First we take subject marks of student as inputted we find the total and percentage.and after that for grade compare the percentage with different criteria as mentioned in the program.