Help with using a Class functionality within another functionality
Each functionality of the class should do only one thing. So I am trying to get the stuff from the functionality get_monthly_total inside the functionality of show_info. However, I have been unsuccessful at all of my attempts. I just don't know the syntax to accomplish this. Can someone please provide a suggestion? Thanks.
Code:
# include <iostream>
# include <string>
# include <cstdlib>
using namespace std ;
class Standard_Plan
{
public :
void input_hours_online () ;
void show_info () ;
double get_monthly_total () ;
private :
double the_hours_online ;
} ;
class Premium_Plan
{
public :
void input_hours_online () ;
void show_info () ;
double get_monthly_total () ;
private :
double the_hours_online ;
} ;
int main ()
{
cout << "This will Calculate your Monthly Bill." <<endl ;
// This will determine whether user is in Standard Plan or Premium Plan.
char response ;
cout << "Are you Subscribed to the Standard or Premium Plan? Enter s or
p: " ;
cin >> response ;
if (response == 's')
{
Standard_Plan aStandardPlan ;
aStandardPlan . input_hours_online () ;
aStandardPlan . show_info () ;
}
else
{
Premium_Plan aPremiumPlan ;
aPremiumPlan . input_hours_online () ;
aPremiumPlan . show_info () ;
}
system("PAUSE") ;
return 0 ;
}
void Standard_Plan :: input_hours_online ()
{
cout << "Enter Number of Hours Used: " ;
cin >> the_hours_online ;
cout << "You are Subscribed to the Standard Plan" ;
}
void Premium_Plan :: input_hours_online ()
{
cout << "Enter Number of Hours Used: " ;
cin >> the_hours_online ;
}
void Standard_Plan :: show_info ()
{
cout << get_monthly_total () ;
}
void Premium_Plan :: show_info ()
{
cout << get_monthly_total () ;
}
double get_monthly_total ()
{
double base_charge ;
double additional_charge ;
double premium_discount ;
char response ;
int the_hours_online ;
if (response == 's')
{
// This will calculate charges for Standard Plan
if (the_hours_online <= 20)
{
base_charge = 20.00 ;
cout << "Fixed Monthly Charge is: $" << base_charge << endl ;
cout << "Total Monthly Bill is: $" << base_charge << endl ;
}
if (the_hours_online > 20)
{
base_charge = 20.00 ;
additional_charge = (the_hours_online - 20) * 00.50 ;
cout << "Fixed Monthly Charge is: $" << base_charge << endl ;
cout << "Additional Charges: $" << additional_charge << endl ;
cout << "Total Monthly Bill is: $" << base_charge + additional_charge << endl ;
}
}
else
{
// This will calculate charges for Premium Plan
if (the_hours_online <= 30)
{
base_charge = 25.00 ;
additional_charge = 0.00 ;
premium_discount = (base_charge + additional_charge) * .10 ;
cout << "Fixed Monthly Charge is: $" << base_charge << endl ;
cout << "10% Discount off Bill: $" << premium_discount << endl ;
cout << "Total Monthly Bill is: $" << base_charge - premium_discount << endl ;
}
if (the_hours_online > 30)
{
base_charge = 25.00 ;
additional_charge = (the_hours_online - 30) * 00.50 ;
premium_discount = (base_charge + additional_charge) * .10 ;
cout << "Fixed Monthly Charge is: $" << base_charge << endl ;
cout << "Additional Charges: $" << additional_charge << endl ;
cout << "10% Discount off Bill: $" << premium_discount << endl ;
cout << "Total Monthly Bill is: $" << (base_charge + additional_charge) - premium_discount << endl ;
}
}
}