C++ Program For Hybrid Inheritance
Free C++ course with real-time projects Start Now!!
Program 1
// Program for hybridge inheritance with multilevel and multiple #include<iostream> #define clrscr() system("cls") using namespace std; class Student { protected: int rno; char name[50]; public: void getStudent() { cout<<"\n Enter roll no"; cin>>rno; cout<<"\n Enter name"; cin>>name; } }; class Mark :public Student { protected: int h,e,c,m; public: void getMark() { cout<<"\n Enter Marks of Hindi: "; cin>>h; cout<<"\n Enter Marks of Maths: "; cin>>m; cout<<"\n Enter Marks of English: "; cin>>e; cout<<"\n Enter Marks of Computer: "; cin>>c; } }; class Sports { protected: int sp; public: void getSports() { cout<<"\n Enter Marks of sports"; cin>>sp; } }; class Result:public Mark ,public Sports { int total,per; public: void calclauteResult() { total=h+e+c+m+sp; per=total/5; } void display() { cout<<"\nRoll No: "<<rno; cout<<"\nName: "<<name; cout<<"\nTotal Marks: "<<total; cout<<"\nPercentage : "<<per; } }; int main() { clrscr(); Result r; r.getStudent(); r.getMark(); r.getSports(); r.calclauteResult(); r.display(); return 0; }
Program 2
// Program for Dimond Problem in Inheritance #include<iostream> #define clrscr() system("cls") using namespace std; class One { public: void display() { cout<<"\nThis is display of One class"; } }; class Two:public virtual One { }; class Three: public virtual One { }; class Four:public Two,public Three { }; int main() { Four F; F.display(); return 0; }
Did you know we work 24x7 to provide you best tutorials
Please encourage us - write a review on Google