CS Electrical And Electronics
@cselectricalandelectronics

Write a Cpp program to read students details such as name, id, marks, and calculate total marks & average using multiple inheritance concept?

All QuestionsCategory: Cpp LanguageWrite a Cpp program to read students details such as name, id, marks, and calculate total marks & average using multiple inheritance concept?
CS Electrical And Electronics Staff asked 4 years ago

I need code.

1 Answers
CS Electrical And Electronics Staff answered 4 years ago

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