+3 votes
in Class 12 by kratos

Define a class Ele_Bill in C++ with the following descriptions:

Private members:

Cname of type character array

Pnumber of type long

No_of_units of type integer

Amount 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 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.

1 Answer

+5 votes
by kratos
 
Best 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;

}

...