Q:

Write a C++ Program To Calculate Electricity Bill Of Person using Class

0

 Write a C++ Program To Calculate Electricity Bill Of Person using Class. Here’s a Simple Program To Calculate Electricity Bill Of Person using Class in C++ Programming Language.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Algorithm for Calculating Electricity Bill : :


  • To Calculate Electricity Bill Of Person using Class,first we have to create and call  get( ) function to take input details of the customer.
  • After get( ) , we create and call a new function i.e  calc_bill( ) to calculate the total bill of the customer on the behalf of units consumed by the customer .
  • At last , we call the put( ) function to print or display customer or person electricity bill on the screen.

Here are some tarrifs set per unit consumption of electricity to the customer.

 
 

Unit tarrif  :

  • 100 RS. 1.20 per unit
    200 RS. 2 per unit
    300 RS. 3 per unit

Here below is the Source code in C++ to Calculate Electricity Bill Of Person using Class.This code is succesfully compile and run(on Codeblocks) on the Windows System and produces the output below.


SOURCE CODE : :

/* C++ Program to Calculate Electricity Bill Of Person using Class  */

#include<iostream>
using namespace std;

class e_bill
{
     private:
         int c_no;
         char c_name[20];
         int units;
         double bill;
     public:
        void get()
        {
                 cout<<"Enter Details of Customer Below :: \n" <<endl;
                 cout<<"Enter Customer No. :: ";
                 cin>>c_no;
                 cout<<"\nEnter Customer Name :: ";
                 cin>>c_name;
                 cout<<"\nEnter No. of Units used :: ";
                 cin>>units;
         }

        void put()
         {
                cout<<"\nEntered Details of Customer are :: " <<endl;
                cout<<"\nCustomer No. is : "<<c_no;
                cout<<"\n\nCustomer Name is : "<<c_name;
                cout<<"\n\nNumber of Units Consumed : "<<units;
                cout<<"\n\nBill of Customer : "<<bill;
         }

        void calc_bill()
        {
                if(units<=100)
                       bill=units*1.20;
               else if(units<=300)
                       bill=100*1.20+(units-100)*2;
               else
                       bill=100*1.20+200*2+(units-300)*3;
         }
};

int main()
{
    e_bill b1;
    b1.get();
    b1.calc_bill();
    b1.put();

    cout<<"\n";

    return 0;
}

OUTPUT : :


/* C++ Program to Calculate Electricity Bill Of Person using Class  */

Enter Details of Customer Below ::

Enter Customer No. :: 123

Enter Customer Name :: CodezClub

Enter No. of Units used :: 2000

Entered Details of Customer are ::

Customer No. is : 123

Customer Name is : CodezClub

Number of Units Consumed : 2000

Bill of Customer : 5620

Process returned 0

Above is the source code and output for C++ Program to Calculate Electricity Bill Of Person using Class which is successfully compiled and run on Windows System to produce desired output.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C++ Classes and Objects Solved Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Write a C++ Program to Multiply every member by k ... >>
<< C++ Program To Calculate Simple Interest using cla...