In this tutorial, we will discuss the Program to Electricity bill calculation using OOP in C++ language
In this topic, we are going to learn how to calculate the usage of electricity bill using OOP in C++ language
We can calculate monthly electric power usage using different methods in cpp language
In this tutorial, we will discuss two methods for calculating electricity bill using OOP in C++ language
Before we write a program to calculate the electricity bill, we must understand electricity charges and rates.
/*1 - 100 unit - 1/= 101-200 unit - 2/= 201-300 unit - 3/= above 300 - 5/=*///for example
Example
This program has the following explanations of calculating electricity bill
In this program, we will discuss how to calculate electricity bill using class in C++ language
Program 1
#include <iostream> #include <conio.h> using namespace std; class EleBill { private: int cur_Unit,pre_Unit,amt,unit; //variable drclaration public://function declaration as public void get(); void printAmt(); }; void EleBill::get()//function definition { cout << "Enter previous unit:" << endl; cin>>pre_Unit;//takes input from the user cout << "Enter current unit:" << endl; cin>>cur_Unit;//takes input from the user } /*1 - 100 = 1 101 - 200 = 2 201 - 300 = 3 above 300 - 5*/ void EleBill::printAmt()//function definition { { unit=cur_Unit-pre_Unit; if(unit>0 && unit<=100) { amt=unit*1; } if(unit>100 && unit<=200) { amt=unit*2; } if(unit>200 && unit<=300) { amt=unit*3; } if(unit>300) { amt=unit*5; } cout << "Bill charge: " <<amt <<endl; } int main() { EleBill o; o.get(); o.printAmt(); getch(); return 0; }
When the above code is executed, it produces the following result
Enter previous unit: 4577 Enter current unit: 5012 Bill charge: 2175
In this code, we will discuss how to calculate electricity bills of a person with full detail using class in C++ language
Program 2
#include <iostream> using namespace std; class Calc_Ebill{ int cus_Id; char cus_Name[50]; int units; double bill_Bal; public: void get() { cout << "Please enter detail of customer below: \n" << endl; cout << "Enter customer id: " << endl; cin>>cus_Id; cout << "Enter customer Name: " << endl; cin>>cus_Name; cout << "Enter the number of units consumed: " << endl; cin>>units; } void put() { cout << "\nCustomer details \n" << endl; cout << "\nCustomer id is: " <<cus_Id<< endl; cout << "\nCustomer Name is: " << cus_Name<<endl; cout << "\nNumber of units consumed: " << bill_Bal<<endl; cin>>units; } /*1 - 100 = 1 101 - 200 = 2 201 - 300 = 3 above 300 - 5*/ void calc_Amt() { if(units<=100) bill_Bal=units*1; else if(units<=200) bill_Bal=100*1+(units-100)*2; else if(units<=300) bill_Bal=100*1+100*2+(units-200)*3; else if(units>300) bill_Bal=100*1+100*2+100*3+(units-300)*5; } }; int main() { cout << "Here your output\n\n" << endl; Calc_Ebill b; b.get(); b.calc_Amt(); b.put(); return 0; }
When the above code is executed, it produces the following result
Suggested for you
Data type in C++ language
Similar post
Java code to calculate electricity bill
C code to calculate electricity bill
C++ code to calculate electricity bill
How to find reverse number using method In this article, we will discuss the concept…
C# inverted full pyramid star pattern In this article, we will discuss the concept of…
C# Full Pyramid star pattern program In this article, we will discuss the concept of…
Program to count vowels, consonants, words, characters and space in Java In this article, we…
How to print multiplication table using Array in C++ language In this post, we will…
C Program to multiplication table using Array In this tutorial , we will discuss about…