Respuesta :
Answer:
/ Header files section
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
// Function prototypes
void printGeneralInfo();
void readData(double& costPerMonth, double& costPerTraining,
bool& seniorCitizen, int& numOfSessions, int& number0fMonths);
double calcMembershipCost(double costPerMonth, double costPerTraining,
bool seniorCitizen, int numOfSessions, int numOfMonths);
//Program begins with a main function
int main()
{
//Declare variables
double costPerMonth;
double costPerTraining;
bool seniorCitizen;
int numOfSessions;
int numOfMonths;
double costMemberShip;
char choice;
//Read input from the user
cout << "\n*Welcome to Fitness Center*" << endl;
do
{
printGeneralInfo();
readData(costPerMonth,
costPerTraining,
seniorCitizen, numOfSessions,
numOfMonths);
costMemberShip = calcMembershipCost(costPerMonth, costPerTraining,
seniorCitizen, numOfSessions, numOfMonths);
cout << "\nCost of the new membership: $"
<< setprecision(2) << fixed
<< costMemberShip << endl;
cout << "\nEnter 'Y' for another membership: ";
cin >> choice;
} while (choice == 'Y' || choice == 'y');
return 0;
}
//Method definition of printGeneralInfo: It displays the general
//information about the fitness center and its charges
void printGeneralInfo()
{
cout << "\nThe discounts at this Fitness Center are:"
<< endl;
cout << "(a) 30% discount for the senior citizens."
<< endl;
cout << "(b) 15% discount if the membership is bought"
<< endl;
cout << " and paid for 12 or more months" << endl;
cout << "(c) 20% discount on each session if more than"
<< endl;
cout << " five personal training sessions are bought and paid for."
<< endl;
}
//Method definition of readData
void readData(double& costPerMonth,
double& costPerTraining,
bool& seniorCitizen, int& numOfSessions,
int& numOfMonths)
{
cout << "\nEnter the cost per month of a regular membership: $";
cin >> costPerMonth;
cout << "Enter the cost per a personal training session: $";
cin >> costPerTraining;
cout << "Enter 'Y' if you are senior citizen: ";
char ch;
cin >> ch;
if (ch == 'Y' || ch == 'y')
seniorCitizen = true;
else
seniorCitizen = false;
cout << "Enter the number of personal training sessions bought : ";
cin >> numOfSessions;
cout << "Enter the number of months paid for: ";
cin >> numOfMonths;
}
//Method definition of calcMembershipCost
double calcMembershipCost(double costPerMonth,
double costPerTraining,
bool seniorCitizen, int numOfSessions,
int numOfMonths)
{
double costMemberShip = costPerMonth * numOfMonths;
if (seniorCitizen)
{
costMemberShip = costMemberShip -
(costPerMonth * 0.30 * numOfMonths);
}
if (numOfMonths >= 12)
{
costMemberShip = costMemberShip -
(costPerMonth * 0.15 * numOfMonths);
}
costMemberShip = costMemberShip + (costPerTraining * numOfSessions);
if (numOfSessions > 5)
{
costMemberShip = costMemberShip - (costPerTraining * 0.20 * numOfSessions);
}
return costMemberShip;
}
Explanation: