Pages

100 Contemporary Living Room Designs

Monday, September 3, 2012

C++ PROGRAM TO DO ELECTRICITY BILL CALCULATION

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 300 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.h>
#include<conio.h>
class electricity
{
  protected:
  float unit;
  float cost;
  public:
  void bill()
  {
    cout<<"\n enter the no. of units"<<endl;
    cin>>unit;
    if(unit<=100)
    {
      cost=0.50*unit;
      cout<<"cost up to 100 unit is Rs."<<cost<<endl;
    }
    else
    {
      if(unit>300)
      {
        cost=0.60*unit;
        cout<<"Beyond 300 units is Rs"<<cost;
      }
    }
  }
};
class more_electricity:public electricity
{
  float surcharge,diff,total_cost;
  public:
  void bill()
  {
    electricity::bill();
    if(cost>250.00)
    {
      diff=cost-250;
      surcharge=diff*0.15;
      total_cost=cost+surcharge;
      cout<<" Bill amount with surcharge is Rs"<<total_cost;
    }
    else
    {
      cout<<"Bill amout is Rs."<<cost;
    }

  }
};
void main()
{

  clrscr();
  more_electricity me;
  me.bill();

  getch();
}



OUTPUT



1 comment:

  1. its an wrong concept of bill , here program will not give 200 units output . Question given is also wrong, there must be condition to use units between 100 and 300 also.

    ReplyDelete