In: Computer Science
Please program in C++
Create two classes, HUSBAND (Family Member 1) and WIFE (Family Member 2). Make WIFE as friend class of HUSBAND. The structure of classes are given below.
class WIFE;
class HUSBAND
{
private:
string Husband_fname;
string Husband_lname;
int Husband_income;
public:
HUSBAND(string f1, string l1, int inc):Husband_fname(f1), Husband_lname(l1), Husband_income(inc);
HUSBAND();
{
// Default initializations of data members
}
int getIncome();
};
class WIFE
{
private:
string Wife_fname;
string Wife_lname;
int Wife_income;
int tax_rate;
public:
WIFE(string f2, string l2, int inc, int tr) ;
WIFE()
{
//Default initializations of private data members;
}
float calcTax(HUSBAND &f);
float getTaxRate();
int getIncome();
};
int main()
{
HUSBAND obj1("Albert","John",55026);
WIFE obj2("Mary","Chin",120000,5);
//Task1: Display the tax rate;
// Task2: Display income of HUSBAND;
// Task3: Display income of WIFE;
// Task4: Display total family income;
// Task5: Display total Tax Amount;
system("pause");
return 0;
}
#include <iostream>
using namespace std;
class HUSBAND
{
private:
string Husband_fname;
string Husband_lname;
int Husband_income;
friend class WIFE;
public:
HUSBAND(string f1, string l1, int inc);
HUSBAND();
int getIncome();
};
HUSBAND::HUSBAND(string f1, string l1, int inc):Husband_fname(f1), Husband_lname(l1), Husband_income(inc)
{}
HUSBAND::HUSBAND()
{}
int HUSBAND::getIncome()
{
return Husband_income;
}
class WIFE
{
private:
string Wife_fname;
string Wife_lname;
int Wife_income;
int tax_rate;
public:
WIFE(string f2, string l2, int inc, int tr) ;
WIFE();
float calcTax(HUSBAND &f);
float getTaxRate();
int getIncome();
};
WIFE::WIFE(string f2, string l2, int inc, int tr) : Wife_fname(f2), Wife_lname(l2), Wife_income(inc), tax_rate(tr)
{}
WIFE::WIFE()
{}
float WIFE::calcTax(HUSBAND &f)
{
return(((getIncome()+f.getIncome())*getTaxRate())/100);
}
int WIFE::getIncome()
{
return Wife_income;
}
float WIFE::getTaxRate()
{
return tax_rate;
}
int main() {
HUSBAND obj1("Albert","John",55026);
WIFE obj2("Mary","Chin",120000,5);
//Task1: Display the tax rate;
cout<<"Tax Rate : "<<obj2.getTaxRate()<<endl;
// Task2: Display income of HUSBAND;
cout<<"Husband Income : "<<obj1.getIncome()<<endl;
// Task3: Display income of WIFE;
cout<<"Wife Income : "<<obj2.getIncome()<<endl;
// Task4: Display total family income;
cout<<"Total family Income : "<<(obj1.getIncome()+obj2.getIncome())<<endl;
// Task5: Display total Tax Amount;
cout<<"Total Tax Amount : "<<obj2.calcTax(obj1)<<endl;
system("pause");
return 0;
}
//end of program
Output: