C++ Program For Multiple Inheritance
Master C++ with Real-time Projects and Kickstart Your Career Start Now!!
Program 1
// Program for method overloading
#include<iostream>
#define clrscr() system("cls")
using namespace std;
class Student
{
protected:
int rno;
char name[50];
public:
// Student()
// {
// cout<<"\n constructor of student class";
// }
void getStudent();
};
void Student::getStudent()
{
cout<<"\n Enter roll no :";
cin>>rno;
cout<<"\n Enter name: ";
cin>>name;
}
class Mark
{
protected:
int h,m,e,c;
public:
// Mark()
// {
// cout<<"\n constructor of mark class";
// }
void getMark();
};
void Mark::getMark()
{
cout<<"\n Enter marks of hindi";
cin>>h;
cout<<"\n Enter marks of english";
cin>>e;
cout<<"\n Enter marks of maths";
cin>>m;
cout<<"\n Enter marks of computer";
cin>>c;
}
class Result:public Mark,public Student
{
int total,per;
public:
// Result()
// {
// cout<<"\n constructor of result class";
// }
void calculate()
{
total=h+e+m+c;
per=total/4;
}
void displayResult()
{
cout<<"Roll No: "<<rno << " " <<"Name: "<<name<<"\n";
cout<<"Hindi: "<<h<<" English: "<<e<<" Maths: "<<m<<" Computer: "<<c;
cout<<"\n Total Marks: "<<total<<" "<<"Percentage: "<<per<<"%";
}
};
int main()
{
clrscr();
Result R;
R.getStudent();
R.getMark();
R.calculate();
R.displayResult();
return 0;
}
Your 15 seconds will encourage us to work even harder
Please share your happy experience on Google

