Design a class TBills to include customer_id, customer_name, phone number, calls and usagecost and also include the following member functions
-getCustomerData()- To input customer data(customer_id, customer_name, phone number,calls)
-usage_cost() - to calculate the monthly telephone bills and calculate the usage cost of telephone bill as per the following rule:
• Minimum Rs. 200 for upto 100 calls.
• Plus Rs. 0.60 per call for next 50 calls.
• Plus Rs. 0.50 per call for next 50 calls.
• Plus Rs. 0.40 per call for any call beyond 200 calls.
-monthlyTelephoneBills() - to display monthly telephone bills of customer
#include <iostream>
#include <string>
using namespace std;
class TBills{
private:
//include customer_id, customer_name, phone, number calls
int customer_id;
string customer_name;
string phone;
int calls;
public:
// and usagecost and also include the following member functions
//getCustomerData()- To input customer data(customer_id, customer_name, phone number,calls)
void getCustomerData(){
cout<<"Enter the customer id: ";
cin>>customer_id;
cout<<"Enter the customer name: ";
getline(cin,customer_name);
getline(cin,customer_name);
cout<<"Enter the customer phone: ";
getline(cin,phone);
cout<<"Enter the number of calls: ";
cin>>calls;
}
//-usage_cost() - to calculate the monthly telephone bills and
// calculate the usage cost of telephone bill as per the following rule:
// - Minimum Rs. 200 for upto 100 calls. 200
// - Plus Rs. 0.60 per call for next 50 calls. 30
// - Plus Rs. 0.50 per call for next 50 calls. 25
// - Plus Rs. 0.40 per call for any call beyond 200 calls. 184
double usage_cost(){
double monthlyTelephoneBills=200;
int nCalls=calls;
if(nCalls>100){
nCalls-=100;
if((nCalls-50)>=0){
monthlyTelephoneBills+=50*0.60;
nCalls-=50;
}else{
monthlyTelephoneBills+=nCalls*0.60;
nCalls=0;
}
if((nCalls-50)>=0){
monthlyTelephoneBills+=50*0.50;
nCalls-=50;
}else{
monthlyTelephoneBills+=nCalls*0.50;
nCalls=0;
}
}else{
nCalls=0;
}
if(nCalls>0){
monthlyTelephoneBills+=nCalls*0.40;
}
return monthlyTelephoneBills;
}
//-monthlyTelephoneBills() - to display monthly telephone bills of customer
void monthlyTelephoneBills(){
cout<<"\nThe customer id: "<<customer_id<<"\n";
cout<<"The customer name: "<<customer_name<<"\n";
cout<<"The customer phone: "<<phone<<"\n";
cout<<"The number of calls: "<<calls<<"\n\n";
cout<<"The monthly telephone bills of customer is "<<usage_cost()<<"\n\n";
}
};
//The start point of the program
int main (){
TBills Tbills;
Tbills.getCustomerData();
Tbills.monthlyTelephoneBills();
//delay
system("pause");
return 0;
}
Comments
Leave a comment