1 Answers
Code:
#include <iostream>
using namespace std;
class stud //base class
{
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 : public stud //marks is derived
{ //student is base
protected:
int m1, m2, m3;
public:
void getmarks()
{
cout<<“Enter 3 subject marks”;
cin>>m1>>m2>>m3;
}
void putmarks()
{
cout<<“M1 :”<<m1<<“\nM2 :”<<“\nM3 :”<<m3<<endl;
}
};
class result: public marks //result is derived
{ //marks is intermediate class
int total;
float avg;
public:
void show()
{
total = m1+m2+m3;
avg = total/3.0;
cout<<“Total :”<<total<<endl;
cout<<“Avg :”<<avg;
}
};