Saved Bookmarks
| 1. |
Define a class Ele_Bill in C++ with the following descriptions:Private members:Cname of type character arrayPnumber of type longNo_of_units of type integerAmount of type float.Calc_Amount( ) This member function should calculate the amount as No_of_units*Cost .Amount can be calculated according to the following conditions:No_of_units CostFirst 50 units FreeNext 100 units 0.80 @ unitNext 200 units 1.00 @ unitRemaining units 1.20 @ unitPublic 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. |
|
Answer» 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( ) { gets(Cname); cin>Pnumber>>No_of_units; Calc_Amount( ); } void Ele_Bill :: Display( ) { cout<<Cname<<Pnumber<<No_of_units<<Amount; } |
|