Page

Hybrid Inheritance Example in C++

#include<iostream.h>  
 #include<conio.h>  
 #include<stdio.h>  
 #include<string.h>  
 class student_id  
 {   
 int rno;  
 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:public student_id  
 {  
 public:  
 int i,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:  
 int sm;  
 void read_sportm()  
 {  
 cout<<"\n\nEnter the marks in SPORTS out of 10 : ";  
 cin>>sm;  
 }  
 };  
 class percentage:public marks,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;  
 }  
 };  
 void main()  
 {  
 int cont;  
 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();  
 }  

No comments:

Post a Comment