Program to generate telephone bill using the concept of class.
#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;
}
Comments
Leave a comment