Create class PI with data members roll and name. Create another class AI with data members sub1 and sub2. Derive a class Student from PI and AI classes. Student class has one data member total to calculate the sum of sub1 and sub2.
#include <iostream>
using namespace std;
class PI{
protected:
int roll;
string name;
};
class AI{
protected:
int sub1;
int sub2;
};
class Student: public PI, public AI{
private:
int total;
public:
void displayTotal(){
cout<<"\nEnter sub 1: ";
cin>>sub1;
cout<<"\nEnter sub 2: ";
cin>>sub2;
total=sub1+sub2;
cout<<"\nTotal = "<<total;
}
};
int main()
{
Student s;
s.displayTotal();
return 0;
}
Comments
Leave a comment