C++ program to illustrate hybrid inheritance concept using student database creation. - Computer Programming

Latest

C C++ Java Python Perl Programs Examples with Output -useful for Schools & College Students

Thursday, August 31, 2017

C++ program to illustrate hybrid inheritance concept using student database creation.

Write a C++ program to illustrate hybrid inheritance concept using student database creation as an example.


Program:

#include<iostream.h>
class tests;
class sports;
class result;
class Student{
protected :int rn;
public:
void get()
{cout<<"\n\nEnter roll no.:";
cin>>rn;}
void put()
{
cout<<"\nRoll no.:"<<rn<<endl;
}
};
class tests:public Student
{
protected:
float sub1,sub2;
public:
void get_m()
{cout<<"\nenter marks:";
cin>>sub1>>sub2;}
void put_m()
{
cout<<"\nMarks in subject 1="<<sub1<<endl;
cout<<"\nMarks in subject 2="<<sub2<<endl;
}
};
class sports
{
protected:
char g;
public:
void get_g()
{
cout<<"Enter the grade:";
cin>>g;
}
void put_g()
{
cout<<"\nGrade in sports:"<<g<<endl;
}
};
class result:private tests,private sports
{
public:
void res()
{
get();
get_m();
get_g();
cout<<"\n------\nRESULT\n------\n";
put();
put_m();
put_g();
float total=sub1+sub2;
cout<<"TOTAL="<<total;
}
};
void main()
{
result s1;
s1.res();

}


Sample Input and Output:

Enter roll no.:100
Enter Marks: 89 90
Enter the Grade: A
Result
roll no.:100
Marks in subject 1=89
Marks in subject 2=90
Grade in sports: A
Total= 179

No comments:

Post a Comment