121k views
3 votes
The cost to become a member of a fitness center is as follows: the membership fee per month is $50.00 the personal training session fee is $30.00 the senior citizens ( > 60) discount is 30% if the membership is bought and paid for 12 or more months, the discount is 15%; if more than five personal training sessions are bought and paid for, the discount on each session is 20%.

Develop a C++ program that determines the cost of a new membership. The program must contain a function that displays the general information about the fitness center and its charges, a function to get all the necessary information to determine the membership cost, and a function to determine the membership cost. Also must be a menu driven program. Given the user 2 options as follows: Calculate membership costs. Quit program. If the user enters 'a' as the option, then display general information, get their details and calculate costs. Then display the menu again. If the user enters 'b', quit the program with an appropriate message. This must loop continuously until the user enters 'b' to quit. (Do not use any global variables.)
Must use the given function prototypes: void information(); void getInfo(bool &senior, int &months, int &personal); double calcCost(bool senior, int months, int personal);

1 Answer

2 votes

Answer:

// Program is written in C++

// Comments are used for explanatory purpose

// See attachment below for output

#include <string>

#include <iomanip>

#include <iostream>

using namespace std;

void setPrices(double&, double&);

double calcCost(double, int, double, int, bool, bool, bool);

void getInfo(bool&, bool&, bool&, int&, int&);

void information();

int main()

{

//Variable Declarations

int duration, PSessions;//Duration and Personal Training Session

double regular, PSessionCost, memberCost;

//Regular Charge, Cost of One Personal Training Session and Membership Cost

bool SCitizen, Sessions, payment;

cout << fixed << showpoint << setprecision(2);

information();

cout << endl;

setPrices(regular, PSessionCost);

getInfo(SCitizen, Sessions, payment, duration, PSessions);

// cal getInfo

memberCost = calcCost(regular, duration, PSessionCost, PSessions, SCitizen, Sessions, payment);

cout << "$" << memberCost;

system("pause");

return 0;

}

void information()

{

cout << "Welcome to Stay Healty and Fit center." << endl<< "This program determines the cost of a new membership." << endl;

cout << "There's a discount of 30% for senior citizen" << endl;

cout << "Procurement for twelve months memebership attracts a discount of 15%." << endl;

cout << "Procurement of 6 or more personal training session attracts a discount 20% on each session" << endl;

}

void setPrices(double& RegularPrice, double& TrainingCost)

{

cout << "Cost of regular Membership per month: " << endl;

cin >> RegularPrice;

cout << "Cost of one personal traning session: " << endl;

cin >> TrainingCost;

}

void getInfo(bool& senCitizen, bool& bSixOrMoreSess, bool& paidTwMnth, int& nOfMonths, int& nOfPersonalTrSess)

{

//Senior Verification

char selectCl;

cout << "Are you a Senior Citizen? Please enter 'Y' or 'N': ";

cin >> selectCl;

if (selectCl == 'y' || selectCl == 'Y')

{

senCitizen = true;

}

else

senCitizen = false;

cout << endl;

//Number of personal training session.

cout << "Enter the number of personal training sessions bought: ";

cin >> nOfPersonalTrSess;

if (nOfPersonalTrSess > 5)

{

bSixOrMoreSess = true;

}

else

bSixOrMoreSess = false;

cout << endl;

//Number of months

cout << "Enter the number of months you are paying for: ";

cin >> nOfMonths;

if (nOfMonths >= 12)

{

paidTwMnth = true;

}

else

paidTwMnth = false;

}

double calcCost(double regMemPricePerMth, int nOfMonths,

double TrainingCost, int nOfPersonalTrSess,

bool senCitizen, bool bSixOrMoreSess, bool paidTwMnth)

{

double TotalCost, finalSessionCost;

//Session Discount

if (bSixOrMoreSess)

{

TrainingCost = (TrainingCost * 0.8);

}

else

{

TrainingCost = TrainingCost;

}

//Month Discount

if (paidTwMnth)

{

regMemPricePerMth = regMemPricePerMth * 0.85;

}

else

{

regMemPricePerMth = regMemPricePerMth;

}

TotalCost = regMemPricePerMth * nOfMonths;

finalSessionCost = TrainingCost * nOfPersonalTrSess;

// Check if Senior Citizen Discount Applies

if (senCitizen) {

return (TotalCost * 0.7) + finalSessionCost;

}

else {

return TotalCost + finalSessionCost;

}

}

The cost to become a member of a fitness center is as follows: the membership fee-example-1
User Tnschmidt
by
5.3k points