code for multiple inheritance using public scope and use of protected access specifiers
Mon Oct 02 2023 04:30:13 GMT+0000 (Coordinated Universal Time)
Saved by
@rahulk
#include <iostream>
using namespace std;
class stu
{
int id;
char name[10];
public:
void get_data()
{
cout<<"enter student name:";
cin>>name;
cout<<"enter student id:";
cin>>id;
}
void put_data()
{
cout<<"name="<<name;
cout<<"id="<<id;
}
};
class marks
{
protected:
int m1,m2,m3;
public:
void getmarks()
{
cout<<"enter three sub marks:";
cin>>m1>>m2>>m3;
}
void putmarks()
{
cout<<"m1="<<m1;
cout<<"m2="<<m2;
cout<<"m3="<<m3;
}
};
class result:public stu,public marks
{
int total;
float avg;
public:
void show()
{
getmarks();
total= m1+m2+m3;
cout<<"total marks:"<<total<<endl;;
avg=total/3.0;
cout<<"average marks scored:"<<avg<<endl;
}
};
int main()
{
result r[3];
for (int i=0;i<3;i++)
{
cout<<"data of student"<<i+1<<":"<<endl;
r[i].show();
}
return 0;
}
content_copyCOPY
Comments