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.
#include <iostream>
using namespace std;
class EB_amount{
protected:
int unit_used;
double bill;
public:
void setUnit_used(int u){
unit_used=u;
}
double get_bill(){
if(unit_used>0&&unit_used<=200){
bill=3*unit_used;
}
else if(unit_used>=201 &&unit_used<=500){
bill=4*unit_used;
}
if(unit_used>500){
bill=5.5*unit_used;
}
return bill;
}
void display_bill(){
cout<<"\nBill = "<<get_bill();
}
};
class Salary{
protected:
double basic,DA,HRA;
public:
void setBasicSalary(double b){
basic=b;
DA=1.04*basic;
HRA=0.1*basic;
}
double get_salary(){
return (basic+DA+HRA);
}
void displaySalary(){
cout<<"\nTotal Salary = "<<get_salary();
}
};
class Budget: public EB_amount, public Salary{
private:
double income, tuition_fee, house_rent, saving, grocery, eb_bill;
public:
void setIncome(){
income=get_salary();
}
void setEb_bill(){
eb_bill=get_bill();
}
};
int main()
{
EB_amount e;
e.setUnit_used(236);
e.display_bill();
Salary s;
s.setBasicSalary(300000);
s.displaySalary();
Budget b;
b.setIncome();
b.setEb_bill();
return 0;
}
Output:
Bill = 944
Total Salary = 642000
Comments
Leave a comment