/******** IMPLEMENTATION OF HYBRID INHERITANCE ********/
#include< iostream.h>
#include< conio.h>
class student
{
private :
int rn;
char na[20];
public:
void getdata()
{
cout< < "Enter Name And Roll No : ";
cin>>na>>rn;
}
void putdata()
{
cout< < endl< < na< < "\t"< < rn< < "\t";
}
};
class test : public student
{
protected:
float m1,m2;
public:
void gettest()
{
cout< < endl< < "Enter your marks In CP 1 And Cp 2 :";
cin>>m1>>m2;
}
void puttest()
{
cout< < m1< < "\t"< < m2< < "\t";
}
};
class sports
{
protected:
float score;
public:
void getscore()
{
cout< < endl< < "Enter your score :";
cin>>score;
}
void putscore()
{
cout< < score< < "\t";
}
};
class results : public test , public sports
{
private :
float total;
public :
void putresult()
{
total = m1+m2+score;
cout< < total;
}
};
void main()
{
results s[5];
clrscr();
for(int i=0;i< 5;i++)
{
s[i].getdata();
s[i].gettest();
s[i].getscore();
}
cout< < "______________________________________________"< < endl;
cout< < endl< < "Name\tRollno\tCP 1\tCP 2\tScore\tTotal"< < endl;
cout< < "----------------------------------------------"< < endl;
for(i=0;i< 5;i++)
{
s[i].putdata();
s[i].puttest();
s[i].putscore();
s[i].putresult();
}
cout< < endl< < "----------------------------------------------";
getch();
}
/********** OUTPIUT **********
Enter Name And Roll No : Lionel
1
Enter your marks In CP 1 And Cp 2 :45
Enter your score :45
Enter Name And Roll No : Cyril
65
Enter your marks In CP 1 And Cp 2 :49
42
Enter your score :45
Enter Name And Roll No : Mayank
40
Enter your marks In CP 1 And Cp 2 :41
43
Enter your score :46
Enter Name And Roll No : Dylan
78
Enter your marks In CP 1 And Cp 2 :23
24
Enter your score :25
Enter Name And Roll No : Ansha
39
Enter your marks In CP 1 And Cp 2 :45
45
Enter your score :45
______________________________________________
Name Rollno CP 1 CP 2 Score Total
----------------------------------------------
Lionel 1 45 23 45 113
Cyril 65 49 42 45 136
Mayank 40 41 43 46 130
Dylan 78 23 24 25 72
Ansha 39 45 45 45 135
----------------------------------------------
*/
Related Articles: