Answer to Question #280813 in C++ for amna

Question #280813

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.


1
Expert's answer
2021-12-17T14:01:26-0500


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




}

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