7. An electricity board charges the following rates to users – For first 100 units : 40p per unit – For next 200 units : 50p per unit – Beyond 300 units : 60p per unit All users are charged a minimum of Rs.150. If the total cost is more than Rs.250.00 then an additional charges of 15% are added. Write a C++ program using class to read the name of users & number of units consumed & print out the charges with names.(Use Array of Objects)


#include<iostream.h>
#include<conio.h>
class electricity
{
char name[20];
int unit;
float Rs;
public:
void get()
{
cout<<“\nEnter the Name & Unit’s of Electricity user: \n”;
cin>>name>>unit;
}
void check()
{
if(unit<=100)
{
Rs=unit*0.40;
Rs=Rs+150;
}
else if(unit<=200||unit>100)
{
Rs=unit*0.50;
Rs=Rs+150;
}
else if(unit<=300||unit>200)
{
Rs=unit*0.60;
Rs=Rs+150;
}
}
void disp()
{
if(Rs>=250)
{
Rs=Rs+0.15;
}
cout<<name<<” \t”<<Rs<<endl;
}
};
void main()
{
int n,i;
electricity e[10];
clrscr();
cout<<“\nHow many electricity User: \n”;
cin>>n;
for(i=0;i<n;i++)
{
e[i].get();
e[i].check();
}
cout<<“\nElectricity User’s: \n”;
cout<<“\nName\t Total cost(Rs)\n”;
cout<<“=================================\n”;
for(i=0;i<n;i++)
{
e[i].disp();
}
getch();
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s