1 / 7

Hybrid Inheritence

Hybrid Inheritence. Nazia Hossain Lecturer Stamford University. Hybrid Inheritance is the combination of two or more inheritances : single, multiple,multilevel or hierarchical Inheritances.

erol
Download Presentation

Hybrid Inheritence

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Hybrid Inheritence Nazia Hossain Lecturer Stamford University

  2. Hybrid Inheritance is the combination of two or more inheritances : single, multiple,multilevel or hierarchical Inheritances. • The following is a C++ Program to for Calculating the marks secured by a student.A Parent class with student identification is created and another class called marks is inherited from the main class.This class marks is further inherited by another class called sports and finally the sports class is inherited by the percentage class to calculated the percentage of marks.

  3. #include<iostream.h> #include<conio.h> #include<stdio.h> #include<string.h> void main() { intcont; percentage pc; clrscr(); do { pc.calculate(); clrscr(); pc.display_totp(); cout<<"\n\nDo You Want to Continue?(1-YES/0-NO)"; cin>>cont; }while(cont==1); getch(); }

  4. class student_id { //c-madeeasy.blogspot.com intrno; char name[20]; public: void read_id() { cout<<"\n\nEnter the Name of the Student : "; gets(name); cout<<"\n\nEnter the Roll No. : "; cin>>rno; } void display_nr() { cout<<"\n\n\t\tSTUDENT REPORT\n\nNAME : "; puts(name); cout<<"\n\nROLL NO. : "<<rno; } };

  5. class marks:publicstudent_id { public: inti,mark[3]; void read_m() { read_id(); for(i=0;i<3;i++) { cout<<"\n\nEnter the Marks Secured in SUBJECT "<<i+1<<" out of 100 : "; cin>>mark[i]; } } void display_m() { display_nr(); cout<<"\n\n\tMarks Secured "; for(i=0;i<3;i++) cout<<"\n\nSUBJECT "<<i+1<<" : "<<mark[i]; } };

  6. class sports { public: intsm; void read_sportm() { cout<<"\n\nEnter the marks in SPORTS out of 10 : "; cin>>sm; } };

  7. class percentage:publicmarks,public sports { public: float total,prcntge; void calculate() { read_m(); read_sportm(); total=0; for(i=0;i<3;i++) { total+=mark[i]; } total+=sm; prcntge=(total/310)*100; } void display_totp() { display_m(); cout<<"\n\nTOTAL = "<<total; cout<<"\n\nPERCENTAGE = "<<prcntge; } };

More Related