Page 70 - C++
P. 70

Amount can be calculated accordingto the following conditions:

                             No_of_units Cost

                                                    First 50 units                     Free
                                                    Next 100 units                   0.80 @ unit
                                                    Next 200 units                   1.00 @ unit
                                                    Remaining units                1.20 @ unit

                             Public members:

                                     *  A function Accept( ) which allows user to enter Cname,
                                         Pnumber, No_of_units and invoke function Calc_Amount().
                                     *  A function Display( ) to display the values of all the data members
                                         on the screen.

                      Ans.
                             class Ele_Bill
                             {
                                   char Cname[20];
                                   long Pnumber;
                                   int No_of_units;
                                   float Amount;
                                   void Calc_Amount( );
                                public:
                                   void Accept();
                                   void Display();
                             };

                                   void Ele_Bill : : Calc_Amount( )
                                   {
                                                 if(No_of_units<=50)
                                                 {
                                                             Amount=0;
                             }
                             else if(No_of_units<=150)
                                                  {
                                                               Amount=(No_of_units-50)*0.80;
                             }
                                                 else if(No_of_units<=350)
                                                   {
                                                               Amount=80+(No_of_units-150)*1.00;
                             }
                                                    else
                                                    {
                                                               Amount=80+200+(No_of_units-350)*1.20;
                                                    }
                                      }
                                void Ele_Bill :: Accept( )

                                                              6
   65   66   67   68   69   70   71   72   73   74   75