Multiple inheritances in C++ language
class A
{
””””””””””””””””
};
class B{
………………………
}
class C access_specifier A, acces_Specifier B//inherit properties from classes A and B
Program 1
Explanation is above program
#include <iostream>
using namespace std;
class cost //start of class cost
{
protected://access modifier – protected
int cp;
public://access modifier – public
void getcp()
{
cout << “Enter the cost prize:” << endl;
cin >>cp;
}
}; //end of class cost
class sell
{ //start of class sell
protected: //access modifier – protected
int sp;
public:
void getsp()
{
cout << “Enter the selling prize:” << endl;
cin >>sp;
}
}; //end of class sell
class profit:cost,sell
{ //start of class profit and which is inherits property from parant class cost, sell
private: //access modifier – private
int pf;
public: //access modifier – public
void profits()
{
getcp();
getsp();
pf=sp-cp;
cout << “profit is:” <<pf<<endl;
cin >>sp;
}
}; //end of class profit
int main()
{
profit o; //create object for class profit
o.profits(); //call method profit through object
return 0;
}
Similar post