//A C++ Program to calculate electricity bill using Constructor, Destructor, and Member functions

//Including the header files
#include<iostream.h>
#include<conio.h>
class electricity          //Declaration of the class
{
private:
int mn, pr, cr, n;        //Declaration of variables
float bill;
public:
electricity()            //Constructor
{
bill=0;                 //Initializing bill value to zero
}
void Getdata (void);     //Member function declaration
int Process (void);
void Calculate (void);
void Display (void);
~electricity(){}             // destructor
};                           // Class body ends here

void electricity::Getdata(void)     // Member function declaration outside the class using scope resolution operator(::)
cout<<"Enter meter No:";
cin>>mn;
cout<<"\n Enter previous readings:";   // Taking user inputs
cin>>pr;
cout<<"\n Enter current readings:";
cin>>cr;
}
int electricity::Process(void)
{
if(cr>pr)
n=cr-pr;                     //Calculating the difference
return(1);
}
else
return(0);                  //User would be agained asked to enter the values
void electricity::Calculate(void)
{
int dn;            //Creating a temporary variable
dn=n;
if(dn<=50)
(
bill=bill+(dn*2);
}
else
(
bill-bill+(50*2);
if (dn<=200)
{
dn=dn-50;
bill=bill+(dn*3.5);
}
else
{
bill=bill+(150*3.5);
if(dn<=500)
{
dn=dn-200;
bill=bill+(dn*4.5);
}
else
{
bill=bill+(300*4.5);
dn=dn-500;
bill=bill+(dn*5);
}
}
}
}
void electricity::Display(void)
cout<<"\n Meter no:"<<mn;
cout<<"\n Previous readings:"<<pr;
cout<<"\n Current readings:" <<cr;
cout<<"\n No. of units consumed is cr-pr:"<<n;
cout<<"\n Bill in Rs:"<<bill;
}
void main()          //Main function (returning no value)
{
electricity E;      //Creating object
int a;
abc:clrscr();       //LABEL
E.Getdata();       // Calling member function for the object
a=E.process();
if(a==0)
{
cout<<"\n Wrong data Reenter: ";
goto abc;         //Going to label abc
}
else
{
E.Calculate();
E.Display();
}
getch();
}