Q2. Assume that the cell users are two kinds – those with a postpaid option and those
with a prepaid option. Postpaid gives a fixed free talk time and the rest is computed at
the rate of N2.90 per pulse. Prepaid cards have a fixed talk time.
Define a class Cell_user as a base class and derive the hierarchy of classes. Define
member functions and override them wherever necessary to
(i) retrieve the talk time left for each user.
(ii) print the bill in a proper format containing all the information for the postpaid user
using namespace std;
/*
Q2. Assume that the cell users are two kinds – those with a postpaid option and those
with a prepaid option. Postpaid gives a fixed free talk time and the rest is computed at
the rate of N2.90 per pulse. Prepaid cards have a fixed talk time.
Define a class Cell_user as a base class and derive the hierarchy of classes. Define
member functions and override them wherever necessary to
(i) retrieve the talk time left for each user.
(ii) print the bill in a proper format containing all the information for the postpaid user
*/
#define PREPAID 0
#define POSTPAID 1
class Cell_user
{
public:
void PrintBill(int Cust, int PP, float PR, int BTT)
{
float Bill;
if(Cust == PREPAID)
{
cout<<"\n\tPRE-PAID User Bill";
cout<<"\n\tBalance Talk Time: "<<BTT;
}
else
{
Bill = PR*PP;
cout<<"\n\tPOST-PAID User Bill";
cout<<"\n\tBill : N "<<Bill;
}
}
};
class Postpaid:Cell_user
{
public:
float PulseRate = 2.90;
class Cell_user C;
int FreePulses = 100;
int TotalPulses,PaidPulses,BTT;
void GetPulse(void)
{
cout<<"\n\n\tOST-PAID USER:";
cout<<"\n\tEnter Total Pulses consumed: "; cin>>TotalPulses;
PaidPulses = 0;
if(TotalPulses>FreePulses) PaidPulses = TotalPulses - FreePulses;
C.PrintBill(PREPAID,PaidPulses,PulseRate,PaidPulses);
}
};
class Prepaid:Cell_user
{
public:
class Cell_user C;
float PulseRate = 2.90;
int FreePulses = 100;
int TotalPulses,PaidPulses;
void GetPulse(void)
{
cout<<"\n\n\tPRE-PAID USER:";
cout<<"\n\tEnter Total Pulses consumed: ";cin>>TotalPulses;
PaidPulses = 0;
if(TotalPulses>FreePulses) PaidPulses = TotalPulses - FreePulses;
C.PrintBill(PREPAID,PaidPulses,PulseRate,PaidPulses);
}
};
int main()
{
Postpaid PP;
Prepaid PR;
PP.GetPulse();
PR.GetPulse();
}
Comments
Leave a comment