Answer to Question #204521 in C++ for harshitha p

Question #204521

we want to store the marks of a student and print his final sgpa grade. create a base class Marks to convert the marks to grade. create derived classes Test-1 to store the marks of 1st test, Test-2 to store the marks of 2nd test, and SEE_marks to store the marks of final exam. Print the final SGPA after designing the appropriate input and output functions


1
Expert's answer
2021-06-08T09:32:56-0400




#include <iostream>


using namespace std;


class Marks{
    //convert the marks to grade
    public:
        void getGrades(int n){
            char ch;
            if (n>=80 and n<=100)
                cout<<"\nGrade is A\n";
            else if (n>=60 and n<80)
                cout<<"\nGrade is B\n";
            else if (n>=50 and n<60)
                cout<<"\nGrade is C\n";
            else if (n>=40 and n<50)
                cout<<"\nGrade is D\n";
            else if (n>=0 and n<40)
                cout<<"\nGrade is E\n";
        }
};
class Test_1: public Marks{
    // store the marks of 1st test 
    int test1_marks;
    public:
        int getMarks1(){
            cout<<"Enter test one marks:";
            cin>>test1_marks;
            return test1_marks;
        }
};
class Test_2: public Marks{
    // store the marks of 2st test 
    int test2_marks;
    public:
        char getMarks2(){
            cout<<"Enter test two marks:";
            cin>>test2_marks;
            return test2_marks;
        }
};
class SEE_marks: public Marks{
    //store the marks of final exam 
    int fnExams_marks;
    public:
        int getMarks3(){
            cout<<"Enter final exams marks:";
            cin>>fnExams_marks;
            return fnExams_marks;
        }
};
int main()
{
    Marks m;
    Test_1 t1;
    Test_2 t2;
    SEE_marks s;
    int m1=t1.getMarks1();
    int m2=t2.getMarks2();
    int m3=s.getMarks3();
    int total=m1+m2+m3;
    int avg=total/3;
    cout<<"\nFinal SGPA is: "<<avg;
    m.getGrades(avg);
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog