Answer to Question #329917 in C++ for Ashwathi

Question #329917

Write a C++ program to enter salary and output income tax and net salary using multiple inheritance concept.

1
Expert's answer
2022-04-19T03:08:20-0400






#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;
}














Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS