Answer to Question #205181 in C++ for Ahmad

Question #205181

Design a software system for FESCO-WAPDA for 2014 from which they calculate the monthly bill of

Electricity.

Write a class Bill having the following attributes and behavior

 Int Units

 Int per_unit_cost

 Float bill

Pure virtual functions:

 Monthly_bill()

 Bill_display()

Derived the following classes from the base class Bill:

 January_bill

 February_bill

 March_bill

 April_bill

Perform the functionality:-

 Calculate the monthly bills for every month.

 Show the results on the console using Display () function.

 Write destructor when you realize that this is the end of program.

 Use virtual destructor concept in the above hierarchy.

Note:

 Use virtual Member functions for derived classes.

 Use appropriate values for per unit cost of monthly bills.

 User appropriate data types.


1
Expert's answer
2021-06-10T15:24:27-0400
#include<iostream>
using namespace std;
class Bill
{  public:
    int Units;
    int per_unit_cost;
    float bill;
    Bill(int Units,int per_unit_cost)
    {
        this->Units=Units;
        this->per_unit_cost=per_unit_cost;
    }
    virtual void Monthly_bill() =0;
    virtual void Bill_display()=0;
    virtual ~Bill()
    {
        cout<<"Destructing Bill \n";
    }
};
class January_bill: public Bill
{
public:
    January_bill(int Units,int per_unit_cost):Bill(Units,per_unit_cost)
    {
    }
    void Monthly_bill()
    {
        this->bill=this->Units*this->per_unit_cost;
    }
    void Bill_display()
    {
        cout<<"*Display*"<<endl;
        cout<<"Units:"<<Units<<endl;
        cout<<"Per Unit Cost:"<<per_unit_cost<<endl;
        cout<<"Monthly Bill:"<<bill<<endl;  }
        ~January_bill()
        {
            cout<<"Destructing January_bill \n";
        }
};
class February_bill :public Bill
{
public:
    February_bill(int Units,int per_unit_cost):Bill(Units,per_unit_cost)
    {
    }
    void Monthly_bill()
    {   this->bill=this->Units*this->per_unit_cost;
    }
    void Bill_display()
    {
        cout<<"*Display*"<<endl;
        cout<<"Units:"<<Units<<endl;
        cout<<"Per Unit Cost:"<<per_unit_cost<<endl;
        cout<<"Monthly Bill:"<<bill<<endl;
    }
    ~February_bill()
    {
        cout<<"Destructing February_bill \n";
    }
};
class March_bill :public Bill
{
public:
    March_bill(int Units,int per_unit_cost):Bill(Units,per_unit_cost)
    {
    }
    void Monthly_bill()
    {
        this->bill=this->Units*this->per_unit_cost;
    }
    void Bill_display()
    {
        cout<<"*Display*"<<endl;
        cout<<"Units:"<<Units<<endl;
        cout<<"Per Unit Cost:"<<per_unit_cost<<endl;
        cout<<"Monthly Bill:"<<bill<<endl;
    }
    ~March_bill()
    {
        cout<<"Destructing March_bill \n";
    }
};
class April_bill :public Bill
{
public:
    April_bill(int Units,int per_unit_cost):Bill(Units,per_unit_cost)
    {
    }
    void Monthly_bill()
    {
        this->bill=this->Units*this->per_unit_cost;
    }
    void Bill_display()
    {
        cout<<"*Display*"<<endl;
        cout<<"Units:"<<Units<<endl;
        cout<<"Per Unit Cost:"<<per_unit_cost<<endl;
        cout<<"Monthly Bill:"<<bill<<endl;
    }
    ~April_bill()
    {
        cout<<"Destructing April_bill \n";
    }
};
int main()
{
    int units,perunitcost;
    cout<<"**For January**"<<endl;
    cout<<"Enter Units:";
    cin>>units;
    cout<<"Enter Per Unit Cost:";
    cin>>perunitcost;
    January_bill *jan=new January_bill(units,perunitcost);
    jan->Monthly_bill();
    jan->Bill_display();
    delete jan;
    cout<<"**For February**"<<endl;
    cout<<"Enter Units:";
    cin>>units;
    cout<<"Enter Per Unit Cost:";
    cin>>perunitcost;
    February_bill *feb=new February_bill(units,perunitcost);
    feb->Monthly_bill();
    feb->Bill_display();
    delete feb;
    cout<<"**For March**"<<endl;
    cout<<"Enter Units:";
    cin>>units;
    cout<<"Enter Per Unit Cost:";
    cin>>perunitcost;
    March_bill *mar=new March_bill(units,perunitcost);
    mar->Monthly_bill();
    mar->Bill_display();
    delete mar;
    cout<<"**For April**"<<endl;
    cout<<"Enter Units:";
    cin>>units;
    cout<<"Enter Per Unit Cost:";
    cin>>perunitcost;
    April_bill *apr=new April_bill(units,perunitcost);
    apr->Monthly_bill();
    apr->Bill_display();
    delete apr;
}

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