Multiple Inheritance is one type of inheritance in object oriented programming, In this program we are going to inherit two base classes in derived class, the purpose of multiple inheritance is we need two seperate classes with different properties to be included in one derived class.
C++ Program To Implement Multiple Inheritance
#include<stdio.h>
#include<conio.h>
#include<iostream.h>
class test
{
public:
float marks1;
void get_test()
{
cout<<"Enter marks in test"<<endl;
cin>>marks1;
}
void test_marks()
{
cout<<"Marks in test are"<<marks1<<endl;
}
};
class pract
{
public:
float mark;
void get_pract()
{
cout<<"Enter practical marks"<<endl;
cin>>mark;
}
void pract_marks()
{
cout<<"marks in practical are"<<mark<<endl;
}
void pract_result()
{
cout<<"marks in practical are"<<mark<<endl;
}
};
class result:public test,public pract
{
public:
int finalmarks;
void result1()
{
finalmarks=marks1+mark;
cout<<"final result is "<<finalmarks;
}
};
int main()
{
clrscr();
result ob;
ob.get_test();
ob.get_pract();
ob.test_marks();
ob.pract_marks();
ob.result1();
getch();
return 1;
}
/*
Enter marks in test
89
Enter practical marks
94
Marks in test are89
marks in practical are94
final result is 183
*/
0 comments:
Post a Comment