Design a C++ program having a base class Student with data member rollno and member functions getnum() to input rollno and putnum() to display rollno. The class Test is derived from class Student with data member marks (Three subject marks) and member functions getmarks() to input marks and putmarks() to display marks. The class Sports is also derived from class Student with data member score (range between 100) 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).
#include<iostream>
using namespace std;
class Student{
public:
string rollNo;
public:
void getNum(){
cout<<"Enter roll number: ";
cin>>rollNo;
}
void putNum(){
cout<<"\nRoll number is "<<rollNo;
}
};
class Test:public Student{
protected:
int marks1,marks2,marks3;
public:
void getMarks(){
cout<<"\nEnter marks 1: ";
cin>>marks1;
cout<<"\nEnter marks 2: ";
cin>>marks2;
cout<<"\nEnter marks 3: ";
cin>>marks3;
}
void putMarks(){
putNum();
cout<<"\nMarks 1 is "<<marks1;
cout<<"\nMarks 2 is "<<marks2;
cout<<"\nMarks 3 is "<<marks3;
}
};
class Sports:public Student{
protected:
int score;
public:
void getScore(){
cout<<"\nEnter score, range between 100:";
cin>>score;
}
void putScore(){
cout<<"\nThe score is "<<score;
}
};
class Result:public Test,public Sports{
private:
int total;
public:
void display (){
putMarks();
putScore();
cout<<"\nTotal is "<<marks1+marks2+marks3+score;
}
};
int main()
{
Student d;
d.getNum();
d.putNum();
Test t;
t.getMarks();
t.putMarks();
Sports s;
s.getScore();
s.putScore();
Result r;
r.display();
return 0;
}
Comments
Leave a comment