Answer to Question #286075 in C++ for Khaleefah

Question #286075

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


1
Expert's answer
2022-01-09T10:44:02-0500
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();
}

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