Answer to Question #298488 in C++ for Wasim Akram

Question #298488

Program to generate telephone bill using the concept of class.

1
Expert's answer
2022-02-16T10:21:19-0500


#include <iostream>
#include <string>
using namespace std;


class Bill{
private:
	int bno;
	string name;
	int call;
	double amt;
public:
	Bill() {
		bno = 0;
		name = "";
		call = 0;
		amt = 0.0;
	}


	Bill(int bno, string name, int call) {
		this->bno = bno;
		this->name = name;
		this->call = call;
	}


	void calculate() {
		double charge;
		if (call <= 100)
			charge = call * 0.6;
		else if (call <= 200)
			charge = 60 + ((call - 100) * 0.8);
		else if (call <= 300)
			charge = 60 + 80 + ((call - 200) * 1.2);
		else
			charge = 60 + 80 + 120 + ((call - 300) * 1.5);


		amt = charge + 125;
	}


	void display() {
		cout<<"Bill No: "<< bno<<"\n";
		cout<<"Name: " << name<<"\n";
		cout<<"Calls: " << call<<"\n";
		cout<<"Amount Payable: " << amt<<"\n";
	}
};






int main() {
	int bno;
	string name;
	int call;
	cout<<"Enter Name: ";
	getline(cin,name);
	cout<<"Enter Bill Number: ";
	cin>>bno;
	cout<<"Enter Calls: ";
	cin>>call;


	Bill objBill(bno, name, call);
	objBill.calculate();
	objBill.display();


	system("pause");
	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