Calculations

Program to Electricity bill calculation using OOP in C++

Program to Electricity bill calculation using OOP in C++

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

 

Program to Electricity bill calculation

Electricity bill calculation using OOP

Example

This program has the following explanations of calculating electricity bill

  • Declare total unit consumed by the customer using the variable unit.
  • if the unit consumed less or equal to 100 units, calculates the total amount of usage =unit*1
  • if unit consumed between 100 to 200 units, calculates the total amount of usage =(100*1)+(unit-100)*2)
  • if  unit consumed between 200 to 300 units ,calculates total amount of usage =(100*1)+(100*2)+(unit-200)*3
  • if unit consumed above 300 units ,calculates total mount of usage =(100*1)+(100*2)+(100*3)+(unit-300)*5
  • No additional charge

Electricity bill calculation using class

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

 

Electricity bill calculation of a person

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

Output

 

Suggested for you

Operator in C++ language

If statements in C++ language

Data type  in C++  language

Variable in C++ language

 

Similar post

Java code to calculate electricity bill

C code to calculate electricity bill

C++  code to calculate electricity bill

Python code to calculate electricity bill

C++  code to calculate electricity bill using function

Calculate electricity bill using OOP in Java
Java exercise to Divide two numbers
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

C# inverted full pyramid star pattern

C# inverted full pyramid star pattern In this article, we will discuss the concept of…

3 weeks ago

C# Full Pyramid star pattern program

C# Full Pyramid star pattern program In this article, we will discuss the concept of…

1 month ago

Program to count vowels,consonants,words, characters and space in Java

Program to count vowels, consonants, words, characters and space in Java In this article, we…

1 month ago

How to print multiplication table using Array in C++ language

How to print multiplication table using Array in C++ language In this post, we will…

1 month ago

C Program to multiplication table using Array

C Program to multiplication table using Array In this tutorial , we will discuss about…

2 months ago

Java program to check odd or even using recursion

Java program to check odd or even using recursion In this tutorial, we discuss a…

2 months ago