Write a C++ program to enter salary and output income tax and net salary using multiple inheritance concept.
#include <iostream>
using namespace std;
class NetS
{
private:
double nt;//Net sallary
public:
NetS(double pr)
{
this->nt=pr;
}
double getNetSallary()const
{
return this->nt;
}
};
class TaxS
{
private:
double tx;
public:
//Constructor
TaxS(double s)
{
this->tx=s;
}
//getTaxSallary
double getTaxSallary()const
{
return this->tx;
}
};
//Inheritanc
class Sallary:public TaxS,public NetS
{
private:
double sal;
public:
//Constructor
Sallary(double a,double b):NetS(a),TaxS(a)
{
this->sal=a+b;
}
//getSallary
double getSallary()const
{
return this->sal;
}
//print to stream
friend ostream& operator<<(ostream& os,Sallary& sal)
{
os<<sal.getSallary()<<"$";
return os;
}
};
int main() {
double a;
double b;
cout<<"Net Sallary: ";
cin>>a;
cout<<"Tax sallary:";
cin>>b;
Sallary sal(a,b);
cout<<sal<<endl;
return 0;
}
Comments
Leave a comment