NAME: ROLL NO.

:
PROGRAM: TO implement HYBRID INHERITANCE. #include<iostream.h> #include<conio.h> class person { int age; char name[20]; public: void readperson() { cout<<"Name of the person: "; cin>>name; cout<<"Age of the person: "; cin>>age; } void showperson() { cout<<"PERSON'S NAME: "<<name<<"AGE: "<<age; } };

DATE: SIGN:

class student: public virtual person { char branch[3]; int roll_no; public: void readdata() { cout<<"\n\nEnter student roll no.: "; cin>>roll_no; cout<<"Enter branch: "; cin>>branch; } void showdata() { cout<<"ROLL NO.: "<<roll_no<<"\nBRANCH: "<<branch; } }; class exam: public student { int sub1, sub2; public: void readdata() { student::readdata(); cout<<"Enter marks in sub 1: "; cin>>sub1; cout<<"Enter marks in sub 2: "; cin>>sub2; } void showdata() { student::showdata(); cout<<"\nSUB1: "<<sub1<<"\nSUB2:"<<sub2<<"\nTOTAL MARKS: "<<sub1+sub2; }

getch(). public sports { public: void readdata() {readperson().float totalmarks() { return(sub1+sub2). void main() { clrscr(). } }. class sports: public virtual person { char gamename[20]. r. cout<<"Enter game score: ". public: void readdata() { cout<<"Enter game name: ".showdata(). } }. cin>>gamescore. r. class result: public student. } }. result r. cin>>gamename. exam::readdata(). cout<<t. int gamescore. } float percentage() { float t. } . t=(exam::totalmarks()+sportsscore())/3. sports::showdata(). } void showdata() {showperson().percentage(). r. sports::readdata(). } void showdata() { cout<<"\nGAME NAME: "<<gamename<<"\nGAME SCORE: "<<gamescore. exam::showdata().readdata(). } float sportsscore() { return(gamescore).

OUTPUT: .

Sign up to vote on this title
UsefulNot useful