Saturday, 23 March 2019

CPP-EX59



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 elebill
{
            char name[20];
            float unit;
            float surchase;
            float tc;
            float total_cost;

            public:

                        void get()
                        {

                                    cout<<"\n\nEnter USER name :-";
                                    cin>>name;

                                    cout<<"\n\nEnter Number of Units Consumed:-";
                                    cin>>unit;
                        }

                        void display()
                        {
                                    surchase=0;
                                    tc=0;
                                    //MANIPULATION
                                    if(unit<=100)
                                        tc=unit*0.40;
                                    else if(unit<=200)
                                        tc=unit*0.50;
                                    else
                                        tc=unit*0.60;

                                    if(tc>250)
                                        surchase=tc*0.15;


                                    total_cost = 150 + surchase + tc;
                                    cout<<"\nUSER name :-"<<name;
                                    cout<<"\n\nYOUR BILL AMOUNT IS "<<total_cost<<"\n";
                        }

};


void main()
{
            elebill e1[10];
            int i,n,plrNum;
            clrscr();
            cout<<"\n\n\n\tElectricity Board Charges\n";
            cout<<"\n\tTo Discourage Large Consumption of energy\n\n";

            cout<<"\nHow many user data you want to enter? ";
            cin>>plrNum;
                        if(plrNum > 10)
                        {
                                    cout<<"You can not enter more than 10 user data";
                                    // exit(0);
                        }
                        else{
                                                for(int i=0;i<plrNum;i++)
                                                {
                                                            e1[i].get();
                                                }

                                                for(int j=0;j<plrNum;j++)
                                                {
                                                            e1[j].display();
                                                }
                        }
           
            getch();
}