Answer to Question #213310 in C++ for Hemambar

Question #213310

Create a class named EB_amount. It has the data members units_used and bill. Use member

function to set unit_used. Upto 200 units 3 rupees per unit, 201 to 500, 4 rupees per and above 500

5.5 rupees per unit are allotted by EB. Calculate the bill amount and display the amount. Create

another class Salary with basic, DA and HRA. Set basic by a member function. 104 percent of basic

is assigned as DA and 10 percent is allotted as HRA. Display the total salary. Derive a class Budget

contains income, tuition_fee, house_rent, saving, grocery, eb_bill as data members. Set the values

and get the values of income and eb_bill from parent classes. Display the budget details.


1
Expert's answer
2021-08-02T07:10:57-0400
#include <iostream>
using namespace std;


class EB_amount{
private:
	int units_used;
	float bill;
public:
	void set_units_used(int us){
		this->units_used = us;
		// Calculate the bill amount and display the amount.
		//Upto 200 units 3 rupees per unit, 201 to 500, 4 rupees per and above 500
		//5.5 rupees per unit are allotted by EB
		if (this->units_used <= 200){
			bill = 3 * this->units_used;
		}else if (this->units_used >= 201 && this->units_used < 500){
			this->bill = 4 * this->units_used;
		}else{
			bill = 5.5 * this->units_used;
		}
		cout << "The bill amount: " << bill<<"\n";
	}
	float getBill(){
		return this->bill;
	}
};
// class Salary with basic, DA and HRA
class Salary{
private:
	float basic;
	float DA;
	float HRA;
	float totalSalary;
public:


	void set_basic(float newBasic){
		this->basic = newBasic;
		//104 percent of basic is assigned as DA and 10 percent is allotted as HRA. 
		this->DA = (this->basic*104)/100;
		this->HRA = (this->basic *10)/ 100;
		totalSalary=this->basic+DA-HRA;
		//Display the total salary. 
		cout << "The total salary: "<<totalSalary<<" rupees\n";
	}
	float getTotalSalary(){
		return this->totalSalary;
	}
};
//Derive a class Budget contains income, tuition_fee, house_rent, saving, grocery, eb_bill as data members. 
class Budget: public EB_amount,public Salary{
private:
	float income;
	float tuition_fee;
	float house_rent;
	float saving;
	float grocery;
	float eb_bill;


public:
	Budget(float tuition_fee, float house_rent, float saving, float grocery){
		//Set the values and get the values of income and eb_bill from parent classes. Display the budget details.
		this->tuition_fee=tuition_fee;
		this->house_rent=house_rent;
		this->saving=saving;
		this->grocery=grocery;




	}
	void displaybudgetDetails(){
		cout << "The tuition fee: " << this->tuition_fee << " rupees\n";
		cout << "The house rent: " << this->house_rent << " rupees\n";
		cout << "The saving: " << this->saving << " rupees\n";
		cout << "The grocery: " << this->grocery << " rupees\n";
		this->eb_bill = getBill();
		this->income=getTotalSalary();
		this->income-=this->tuition_fee+this->house_rent+this->saving+this->grocery+this->eb_bill;
		cout << "The income: " << this->income << " rupees\n";
	}
};




int main(){
	int k;


	Budget newBudget(250,520,350,500);
	newBudget.set_units_used(150);
	newBudget.set_basic(4000);
	cout<<"\n";
	newBudget.displaybudgetDetails();


	cin>>k;


	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