Program to generate electricity bill using multilevel inheritance
#include <iostream>
using namespace std;
class Company{
protected:
double cost_per_watt;
};
class household:public Company{
protected:
double no_watts_used;
public:
void setCostPerWatt(double c){
cost_per_watt=c;
}
void setNoWattsused(double n){
no_watts_used=n;
}
double getCostPerWatt(){
return cost_per_watt;
}
double getNoWattsused(){
return no_watts_used;
}
};
class Bill: public household{
public:
void CalculateElectBill(){
double total=getCostPerWatt()*getNoWattsused();
cout<<"\nTotal electricity bill = "<<total;
}
};
int main()
{
Bill b;
b.setCostPerWatt(14.65);
b.setNoWattsused(34.55);
b.CalculateElectBill();
return 0;
}
Comments
Leave a comment