Friday, 27 April 2012

Program Of Hybrid Inheritance In C++

#include<iostream.h>
#include<conio.h>
class student
{
private:
int rollno;
char name[20];
public:
void read()
{
cout<<"\n Enter roll no.";
cin>>rollno;
cout<<"\n Enter Name=";
cin>>name;
}
void show()
{
cout<<"\n Roll No.="<<rollno;
cout<<"\n Name="<<name;
}
};
class exam_internal: public student
{
protected:
int sub1_marks;
int sub2_marks;
public:
{
cout<<"\n Enter Internal MArks1=";
cin>>sub1_marks;
cout<<"\n Enter Internal MArks2=";
cin>>sub2_marks;
}
{
cout<<"\n Intrenal marks1 ="<<sub1_marks;
cout<<"\n Internal marks2= "<<sub2_marks;
}
};

class exam_external
{
protected:
int sub1_exmarks;
int sub2_exmarks;
public:
void read_marks()
{
cout<<"\n Enter EXternal MArks1=";
cin>>sub1_exmarks;
cout<<"n Enter External MArks2=";
cin>>sub2_exmarks;
}
void display_marks()
{
cout<<"\n EXtrenal marks1 ="<<sub1_exmarks;
cout<<"\n External marks2= "<<sub2_exmarks;
}
};
class result : public exam_external,public exam_internal
{
private:
int total_marks;
public:
void cal_result()
{
total_marks=sub1_marks+sub2_marks+sub1_exmarks+sub2_exmarks;
cout<<"\n Total marks="<<total_marks;
}
};
main()
{
clrscr();
result r1;
cout<<"\n********************** Enter Information***********************";
r1.read();
cout<<"\n********************** Enter marks of Internal Examination*******";
r1.exam_internal::read_marks();
//r1.read_marks1();
cout<<"\n********************** Enter marks of Exterrnal Examination***********";
r1.exam_external::read_marks();
cout<<"\n********************** Displaying student Detail*******************";
r1.show();
r1.exam_internal::display_marks();
r1.exam_external::display_marks();
cout<<"\n********************** Calculating & Displaying Marks***************";
r1.cal_result();
getch();
}
-----------------------------------------
Hybrid Inheritance

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.This is the best example for Hybrid 

Inheritance in c++



No comments:

Post a Comment