# C++ program for electricity board charges.

Q20. An electricity board charges according to following rates:
For the first 100 units – 40 P per unit  (P-Paise)

For the next 200 units – 50 P per unit

Beyond 300 units – 60 P per unit.

All users are charged meter charge also which is R50/-.

Write a program to read the names of users and number of units consumed, and print out the charges with names.

Ans.

#include<iostream.h>

#include<conio.h>  //for clrscr();

//A class called customer to hold all the information related to customer

class customer

{

char name[20];

int units;

float charge;

//Member functions of class customer

public:

//A function of class customer to read name and number of units of customer

{

cout<<“\n Enter the name of customer: “;

cin>>name;

cout<<“\n Enter the number of units consumed: “;

cin>>units;

}

//A function of class customer to calculate the charge of customer

void calculate()

{

float cal;

if(units<=100)

{

cal=0.40;

}

else

{

if(units<=300)

{

cal=0.50;

}

else

{

cal=0.60;

}

}

charge= 50+cal;

}

//A function of class customer to print the details of cutomers

void print()

{

cout<<“\n Customer name: “<<name;

cout<<“\n Number of units consumed: “<<units;

cout<<“\n Charge: Rs.”<<charge;

}

};

//End of class customer

//Main function

void main()

{

clrscr();  //for clear screen

//Class Variable

customer x[31];

//for loop to read the details of 3 customers

for(int i=0;i<3;i++)

{

}

//for loop to print the details of 3 customers

for (i=0;i<3;i++)

{

x[i].calculate();

x[i].print();

}

//To hold the screen

getch();

}

//End of main() function

Output:

Enter the name of customer: Anita

Enter the number of units consumed: 200

Enter the name of customer: Babita

Enter the number of units consumed: 777

Enter the name of customer: Ganesha

Enter the number of units consumed: 300

Customer name: Anita

Number of units consumed: 200

Charge: Rs.50.5

Customer name: Babita

Number of units consumed: 777

Charge: Rs.50.599998

Customer name: Ganesha

Number of units consumed: 300

Charge: Rs.50.5

45 Views