Answer to Question #274502 in C++ for Sonam

Question #274502

Program to generate electricity bill using multilevel inheritance


1
Expert's answer
2021-12-02T18:29:45-0500


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

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