70 likes | 212 Views
Hybrid Inheritence. Nazia Hossain Lecturer Stamford University. Hybrid Inheritance is the combination of two or more inheritances : single, multiple,multilevel or hierarchical Inheritances.
E N D
Hybrid Inheritence Nazia Hossain Lecturer Stamford University
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.
#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(); }
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; } };
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]; } };
class sports { public: intsm; void read_sportm() { cout<<"\n\nEnter the marks in SPORTS out of 10 : "; cin>>sm; } };
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; } };