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
Prerequisites
Before starting with this tutorial we assume that you are best aware of the following C++ programming topics:
- Basic C++ programming.
- Operators.
- Basic input/output.
- Basic mathematics calculation.
- Precedence.
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
#include<iostream> using namespace std; int main() { int m,p,c,h,e,total=0; // declaring variables float per; cout<<"Enter 5 Subject marks :\n "; cin>>m>>p>>c>>h>>e; // taking values from user total=m+p+c+h+e; cout<<"Sum of 5 Subjects is ="<<total; per=total/5; // calculating the percentage if(per>85) // calculating grades.. { cout<<"\nA grade"; } else if(per<85 && per>=75) { cout<<"\nB grade"; } else if(per<75 && per>=50) { cout<<"\nC grade"; } else if(per<50 && per>=30) { cout<<"\nD grade"; } else { cout<<"\nFail"; } return 0; } |
Output
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.