Code:
#include <iostream>
using namespace std;
class stud
{
int id;
char name[20];
public:
void getstud()
{
cout<<“Enter student id, name : \n”;
cin>>id>>name;
}
void putstud()
{
cout<<“Stud id : “<<id<<endl;
cout<<“Stud name : “<<name<<endl;
}
};
class marks
{
protected:
int m1, m2, m3;
public:
void getmarks()
{
cout<<“Enter 3 subject marks :\n”;
cin>>m1>>m2>>m3;
}
void putmarks()
{
cout<<“M1 : “<<m1<<“M2 : “<<m2<<“M3 : “<<m3<<endl;
}
};
class result:public stud, public marks
{
int total;
float avg;
public:
void show()
{
total = m1+m2+m3;
avg = total/3.0;
cout<<“total : “<<total<<endl;
cout<<“Avg : “<<avg;
}
};
int main()
{
result r;
r.getstud();
r.getmarks();
r.putstud();
r.putmarks();
r.show();
return 0;
}
Output:
Enter student id, name :
420
ChetanShidling
Enter 3 subject marks :
99
88
98
Stud id: 420
Stud Name : ChetanShidling
M1 : 99M2 : 88M3 : 98
total : 285
Avg : 95