Answer to Question #250692 in C++ for Shruthi

Question #250692
Declare the class E-Bill consisting of data members cust_no, name, st_reading, end_reading, tot_usage and amount to find total energy usage and amount per unit of electric energy. The parameterized constructor are used to initialize object of class E-Bill, then find the total energy usage and amount per unit of electric energy and display the information of E-Bill electric energy. Finally free the resources of data objects using destructor member function. (Note: Amount per unit is Rs. 5.50)
1
Expert's answer
2021-10-13T07:30:51-0400
#include<iostream>
#include<string.h>
using namespace std;
class E_bill { 
  public: 
    int cust_no;
	string name;
	int st_reading;
	int end_reading;
	int tot_usage;
	int amount;  
    E_bill(int x, string y, int s,int e, int z,int a) { // Constructor with parameters
      cust_no = x;
      name = y;
      st_reading = s;
      end_reading = e;
      tot_usage = z;
      amount = a;
    }
    ~E_bill(){//destructor
	}
};


int main() {
E_bill cust1(1,"John",1,5,1500,1000);
E_bill cust2(2,"Grace",3,5,1000,1000);
cout<<"Number\t"<<"Name\t"<<"Start\t"<<"End\t"<<"usage\t"<<"Amount\t"<<endl;
  cout << cust1.cust_no << "\t" << cust1.name<< "\t" << cust1.st_reading<<"\t"<<cust1.end_reading<<"\t"<<cust1.tot_usage<<"\t"<<cust1.amount << "\n";
  cout << cust2.cust_no << "\t" << cust2.name << "\t" <<  cust2.st_reading<<"\t"<<cust2.end_reading<<"\t"<<cust2.tot_usage<<"\t"<<cust2.amount << "\n";
  int v=cust1.amount+cust2.amount;
  int r=cust1.amount*5.50+cust2.amount*5.50;
  cout<<"Total energy usage is: "<<v;
  cout<<"\nAmount per unit of electric energy: "<<r;
  return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS