Write a Cpp program for multiple inheritance? Read student details such as id, name, marks and then calculate total marks, average marks. and display then using multilevel inheritance concept?

All QuestionsCategory: Cpp LanguageWrite a Cpp program for multiple inheritance? Read student details such as id, name, marks and then calculate total marks, average marks. and display then using multilevel inheritance concept?
Chetan Shidling Staff asked 5 years ago

I need code.

1 Answers
Chetan Shidling Staff answered 5 years ago

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;
}
};