An electricity board charges the following rates to users
-for first 100 units:40p per unit
-for next 200 units: 50p per unit
-for beyond 300 units :60p per unit
all user are charged a minimum of Rs.150. if the total cost is more
than Rs.250 then an additional charges of 15% are added.
write a c++ program using class to read the name of user and number
of units consumed and printout charges with names.(use array of object)
#include<conio.h>
#include<iostream.h>
class elec
{
char name[20];
int nou;
float charge;
public:void accept()
{
cout<<"\n enter name:-";
cin>>name;
cout<<"\n enter number of unit:-";
cin>>nou;
}
void calc()
{
if(nou<100)
charge=nou*0.4;
else
if(nou<=300)
{
int temp=nou-100;
charge=100*0.4;
charge=(float)charge+(temp*0.5);
}
else
if(nou>300)
charge=nou*0.6;
if(charge<150)
charge=150;
else
if(charge>250)
charge=(float)charge+(charge*0.15);
}
void display()
{
cout<<"\n name="<<name;
cout<<"\n charges="<<charge;
}
};
int main()
{
elec e[3];
clrscr();
for(int i=0;i<3;i++)
{
e[i].accept();
e[i].calc();
}
for(i=0;i<3;i++)
e[i].display();
getch();
return 0;
}
=============================================
OUTPUT:-
enter name:-XYZ
enter number of unit:-122
enter name:-ABC
enter number of unit:-302
enter name:-PQR
enter number of unit:-1000
name=XYZ
charges=150
name=ABC
charges=181.199997
name=PQR
charges=690
-for first 100 units:40p per unit
-for next 200 units: 50p per unit
-for beyond 300 units :60p per unit
all user are charged a minimum of Rs.150. if the total cost is more
than Rs.250 then an additional charges of 15% are added.
write a c++ program using class to read the name of user and number
of units consumed and printout charges with names.(use array of object)
#include<conio.h>
#include<iostream.h>
class elec
{
char name[20];
int nou;
float charge;
public:void accept()
{
cout<<"\n enter name:-";
cin>>name;
cout<<"\n enter number of unit:-";
cin>>nou;
}
void calc()
{
if(nou<100)
charge=nou*0.4;
else
if(nou<=300)
{
int temp=nou-100;
charge=100*0.4;
charge=(float)charge+(temp*0.5);
}
else
if(nou>300)
charge=nou*0.6;
if(charge<150)
charge=150;
else
if(charge>250)
charge=(float)charge+(charge*0.15);
}
void display()
{
cout<<"\n name="<<name;
cout<<"\n charges="<<charge;
}
};
int main()
{
elec e[3];
clrscr();
for(int i=0;i<3;i++)
{
e[i].accept();
e[i].calc();
}
for(i=0;i<3;i++)
e[i].display();
getch();
return 0;
}
=============================================
OUTPUT:-
enter name:-XYZ
enter number of unit:-122
enter name:-ABC
enter number of unit:-302
enter name:-PQR
enter number of unit:-1000
name=XYZ
charges=150
name=ABC
charges=181.199997
name=PQR
charges=690