GRADE

Muthumari_B · updated September 08, 2021 · C++
// Find the grade of a student using nested if statement with class


#include <iostream>
using namespace std;
class Grade
{
    int m1,m2,m3,Total,Avg;
    public:
    void input();
    void check();
};
void Grade::input()
{
    cout<<"\n Enter a Marks : ";
    cin>>m1>>m2>>m3;
    cout<<m1<<" ,  "<<m2<<" ,  "<<m3<<endl;
    cout<<"\n Mark1 : "<<m1<<endl;
    cout<<"\n Mark2 : "<<m2<<endl;
    cout<<"\n Mark3 : "<<m3<<endl;
}
void Grade:: check()
{
    Total=m1 + m2 + m3;
    cout<<"\n Total Marks : "<<Total<<endl;
    Avg=Total/3;
    cout<<"\n Average : "<<Avg<<endl;
    if(Avg>=35)
    {
        if(Avg>80)
            cout<<"\n  Grade : A "<<endl;
        else if (Avg<=80 && Avg>60)   
            cout<<"\n  Grade : B "<<endl;
        else if (Avg<=60 && Avg>45) 
            cout<<"\n  Grade : C "<<endl;
        else
            cout<<"\n  Grade : D "<<endl;
    }
    else
    {
        cout<<"\n Grade : E "<<endl;
    }
}    
int main()
{
    Grade s;
    s.input();
    s.check();
    return 0;
}

Comments

Please sign up or log in to contribute to the discussion.