An electricity board charges the following rates to domestic users to
discourage large consumption of energy.
For the first 100 units − 50 P per unit
Beyond 100 units − 60 P per unit
If the total cost is more than Rs.250.00 then an additional surcharge of
15% is added on the difference. Define a class Electricity in which the
function Bill computes the cost. Define a derived class More_Electricity
and override Bill to add the surcharge.
#include<iostream>
using namespace std;
class Electricity{
public:
virtual double Bill(double unit)
{
if (unit <100){
return unit * 50;
}
return 100 * 50+ (unit-100) * 60;
}
};
class More_Electricity:public Electricity{
public:
double Bill(double unit)
{
double totalCost=Electricity::Bill(unit);
if (totalCost > 250){
totalCost += totalCost * 0.15;
}
return totalCost;
}
};
int main(){
double unit;
More_Electricity more_Electricity;
cout<<"Enter number of units: ";
cin >> unit;
cout << "Bill: "<<more_Electricity.Bill(unit)<<"\n\n";
cin>>unit;
}
Comments
Leave a comment