Friday, 22 June 2012

rwrite a c+++ program an electricity board charges the following rates to uses

/*
rwrite a c+++ program an electricity board charges the following rates to uses
-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 totalcost 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<<"\nenter name:-";
       cin>>name;
       cout<<"\nenter 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<<"\nname="<<name;
       cout<<"\ncharges="<<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;
}
/*

enter name:-peer                                                               
                                                                               
enter number of unit:-122                                                      
                                                                               
enter name:-zxz                                                                
                                                                               
enter number of unit:-302                                                      
                                                                               
enter name:-peeass                                                             
                                                                               
enter number of unit:-1000                                                     
                                                                               
name=peer                                                                      
charges=150                                                                    
name=zxz                                                                       
charges=181.199997                                                             
name=peeass
charges=690
*/

No comments: