Answer to Question #214846 in C++ for Charan

Question #214846

Design four classes: Student, Exam ,Sports and Result.  The Student class has data members such as reg. number, name. Create Exam by inheriting the Student. The Exam class adds data members representing the marks scored in 3 subjects. Create Sports by inheriting the Student. The Sports class adds data members representing the marks scored in indoor and outdoor games. Derive the Result from the Exam , Sports and Result  has its own data member of Total mark. Write an interactive program with appropriate member functions to model this relationship.


1
Expert's answer
2021-07-07T12:55:01-0400
#include <iostream>
#include <string>
using namespace std;
class Student{
    protected:
        string name;
        int regno;
    public:
        Student(){}
        void getDetails(){
            cout<<"Input regno: ";
            cin>>regno;
            cout<<"Input name: ";
            cin>>name;
        }
        void putDetails(){
            cout<<"Regno: "<<regno<<endl;
            cout<<"Name: "<<name<<endl;
        }
};
class Exam: public Student{
    protected:
        int s1, s2, s3;
    public:
        Exam(): Student(){}
        void getmarks(){
            cout<<"Input marks: \n";
            cout<<"Subject 1: ";
            cin>>s1;
            cout<<"Subject 2: ";
            cin>>s2;
            cout<<"Subject 3: ";
            cin>>s3;
        }
        void putmarks(){
            cout<<"Subject 1: "<<s1<<endl;
            cout<<"Subject 2: "<<s2<<endl;
            cout<<"Subject 3: "<<s3<<endl;
        }
};
class Sports: public Student{
    protected:
        int indoor, outdoor;
    public:
        Sports(): Student(){}
        void getscore(){
            cout<<"Input score: \n";
            cout<<"Indoor: ";
            cin>>indoor;
            cout<<"Outdoor: ";
            cin>>outdoor;
        }
        void putscore(){
            cout<<"Indoor: "<<indoor<<endl;
            cout<<"Outdoor: "<<outdoor<<endl;
        }
};
class Result: public Sports, public Exam{
    int total;
    public:
        Result(): Sports(), Exam(){
            Exam::getDetails();
            getmarks();
            getscore();
            total = indoor + outdoor + s1 + s2 + s3;
        }
        void display(){
            Exam::putDetails();
            cout<<"Exam Marks: \n"; Exam::putmarks();
            cout<<"Sports Scores: \n"; 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

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS