Categories: C++

Program To Find the grade of the student

Find the grade of the student based on the marks obtained in five subjects.

Let the grade be calculated based on the following pattern:

Average Mark RangeGrade
91-100A1
81-90A2
71-80B1
61-70B2
51-60C1
41-50C2
33-40D
21-32E1
0-20E2

To calculate a student’s grade based on total marks in C++ programming, you must ask the user to enter marks from five subjects. Add the marks from all five subjects and divide by five to get the average. And then, using the table above, calculate the grade based on the average mark:

Program Code:

#include<iostream>
using namespace std;
int main()
{
    int i;
    float mark, sum=0, avg;
    cout<<"Enter Marks obtained in 5 Subjects: ";
    for(i=0; i<5; i++)
    {
        cin>>mark;
        sum = sum+mark;
    }
    avg = sum/5;
    cout<<"\nGrade = ";
    if(avg>=91 && avg<=100)
        cout<<"A1";
    else if(avg>=81 && avg<91)
        cout<<"A2";
    else if(avg>=71 && avg<81)
        cout<<"B1";
    else if(avg>=61 && avg<71)
        cout<<"B2";
    else if(avg>=51 && avg<61)
        cout<<"C1";
    else if(avg>=41 && avg<51)
        cout<<"C2";
    else if(avg>=33 && avg<41)
        cout<<"D";
    else if(avg>=21 && avg<33)
        cout<<"E1";
    else if(avg>=0 && avg<21)
        cout<<"E2";
    else
        cout<<"Invalid!";
    cout<<endl;
    return 0;
}

Output:

Enter Marks obtained in 5 Subjects: 
23
78
99
56
44
Grade = C2

Note: also read about Swap Two Numbers Without Using Third Variable

Follow Me

Please follow me to read my latest post on programming and technology if you like my post.

https://www.instagram.com/coderz.py/

https://www.facebook.com/coderz.py

Share
Published by
Rabecca Fatima

Recent Posts

What is object oriented design patterns

A design pattern is a reusable solution to a commonly occurring problem in software design. They…

1 month ago

Factory Method Design Pattern in OODP

Factory Method is a creational design pattern that deals with the object creation. It separates…

1 month ago

Find Intersection of Two Singly Linked Lists

You are given two singly linked lists that intersect at some node. Your task is…

7 months ago

Minimum Cost to Paint Houses with K Colors

A builder plans to construct N houses in a row, where each house can be…

7 months ago

Longest Absolute Path in File System Representation

Find the length of the longest absolute path to a file within the abstracted file…

8 months ago

Efficient Order Log Storage

You manage an e-commerce website and need to keep track of the last N order…

8 months ago