Answer to Question #190748 in C++ for ffghjh

Question #190748

Write a program having a base class Student with data member rollno and member 

functions getnum() to input rollno and putnum() to display rollno. A class Test is derived from class Student with data member marks and member functions getmarks() to input marks and putmarks() to display marks. Class Sports is also derived from class Student with data member score and member functions getscore to input score and putscore() to display score. The class Result is inherited from two base classes, class Test and class Sports with data member total and a member function display() to display rollno, marks, score and the total(marks + score). 




1
Expert's answer
2021-05-08T09:15:30-0400
#include <iostream>
using namespace std;
class Student{
    protected:
        int rollno;
    public:
        Student(){}
        void getnum(){
            cout<<"Input rollno: ";
            cin>>rollno;
        }
        void putnum(){
            cout<<rollno<<endl;
        }
};
class Test: public Student{
    protected:
        int marks;
    public:
        Test(): Student(){}
        void getmarks(){
            cout<<"Input marks: ";
            cin>>marks;
        }
        void putmarks(){
            cout<<marks<<endl;
        }
};
class Sports: public Student{
    protected:
        int score;
    public:
        Sports(): Student(){}
        void getscore(){
            cout<<"Input score: ";
            cin>>score;
        }
        void putscore(){
            cout<<score<<endl;
        }
};
class Result: public Sports, public Test{
    int total;
    public:
        Result(): Sports(), Test(){
            Test::getnum();
            getmarks();
            getscore();
            total = score + marks;
        }
        void display(){
            cout<<"Rollno: "; Test::putnum();
            cout<<"Marks: "; Test::putmarks();
            cout<<"Score: "; Sports::putscore();
            cout<<"Total: "<<total<<endl;
        }
};
int main(){
    Result result;
    result.display();
    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