CS Electrical And Electronics
@cselectricalandelectronics

Write a Cpp program to calculate electricity bill

All QuestionsCategory: Cpp LanguageWrite a Cpp program to calculate electricity bill
CS Electrical And Electronics Staff asked 4 years ago

info

1 Answers
CS Electrical And Electronics Staff answered 4 years ago

Code

#include<iostream>
using namespace std;

class Electric
{
float unit;
char name[20];
public:
void accept()
{
cout<<“\n Enter Name : “;
cin>>name;
cout<<“\n No. Of Units : “;
cin>>unit;
}
void print_bill();
};
void Electric::print_bill()
{
int bill=0;
if(unit>=100 && unit<=300)
bill=(500+(unit*0.40));
else if(unit>100 && unit<=300)
bill=(500+(unit*0.40)+(unit*0.50));
else if(unit>300)
bill=(500+(unit*0.60));
if(bill>250)
bill=(bill+(bill*(15/100)));
cout<<“\n Bill = “<<bill<<“\t”<<name;
}
int main()
{
Electric e[10];
int i,cnt;
cout<<“\n Enter How Many Customers You Want? : “;
cin>>cnt;
for(i=0; i<cnt; i++)
e[i].accept();
for(i=0; i<cnt; i++)
e[i].print_bill();
return 0;
}

Output:

 

Enter How Many Customers You Want? : 2

Enter Name : Chetan

No. Of Units : 102

Enter Name : Akshay

No. Of Units : 200

Bill = 540 Chetan

Bill = 580 Akshay