Code:
#include <iostream>
#include <iomanip>
#include "apstring.h"
using namespace std;
void ExplainProgram();
int getInteger(const apstring &prompt);
double getDouble(const apstring &prompt);
void DisplayAdults(int adults);
void DisplayChild(int children);
void DisplayAmeal(double adultMeal);
void DisplayCmeal(double childMeal);
void DisplayDmeal(double dessertMeal);
void DisplayRoom(double roomCost);
void DisplayTrate(double tiptaxRate);
void DisplayCadults(double adultCost);
void DisplayChild(double childCost);
void DisplayDessert(double dessertCost);
void DisplayFood(double foodCost);
void DisplayTiptax(double tiptaxCost);
void DisplayRoom(double roomCost);
void DisplayDeposit(double depositCost);
void DisplayCost(double foodCost, double tiptaxCost, double roomCost, double depositCost);
double CalculateAdultCost(int adults, double adultMeal);
double CalculateChildCost(int children, double childMeal);
double CalculateDessertCost(int adults, int children, double dessertMeal);
double CalculateFoodCost(double adultCost, double childCost, double desserCost);
double CalculateTiptaxCost(double foodCost, double tiptaxRate);
double CalculateTotalCost(double foodCost, double tiptaxCost, double roomCost, double depositCost);
int main()
{
int adults; // number of adult meals
int children; // number of children meals
double adultMeal; // cost per adult meal
double childMeal; // cost per child meal
double dessertMeal; // cost per dessert meal
double roomCost; // cost of the room fee
double tiptaxRate; // tip and tax rate
double adultCost; // cost of all adult meals bought
double childCost; // cost of all child meals bought
double dessertCost; // cost of all the desserts bought
double foodCost; // sot of all food meals bought
double tiptaxCost; // cost of all the tax and tips
double totalCost; // cost of all meals bought
ExplainProgram(); // Explain the program to the user
adults = getInteger("Number of adults: ");
children = getInteger("Number of children: ");
adultMeal = getDouble("Enter cost per adult without dessert: ");
childMeal = getDouble("Enter cost per child without dessert: ");
dessertMeal = getDouble("Enter cost per dessert: ");
roomCost = getDouble("Enter room fee: ");
tiptaxRate = getDouble("Enter tip and tax rate: ");
adultCost = CalculateAdultCost(adults); // Calculate total adult meal cost
childCost = CalculateChildCost(children); // Calculate total child meal cost
dessertCost = CalculateDessertCost(adults,children,dessertMeal); // Calculate total dessert cost
foodCost = CalculateFoodCost(adultCost,childCost,dessertCost); // Calculate total food cost
tiptaxCost = CalculateTiptaxCost(tiptaxRate,tiptaxCost); // Calculate total tips and tax cost
totalCost = CalculateTotalCost(foodCost,tiptaxCost,roomCost,depositCost); // Calculate total the total balance due
DisplayAdults(adults); // Display number of adults
DisplayChild(children); // Display number of children
DisplayAmeal(adultMeal); // Display cost per adult meal
DisplayCmeal(childMeal); // Display cost per child meal
DisplayDmeal(dessertMeal); // Display cost per dessert meal
DisplayRoom(roomCost); // Display the room fee
DisplayTrate(tiptaxRate); // Display tip and tax rate
DisplayCadults(adultCost); // Display the total adult cost
DisplayChild(childCost); // Display the total child cost
DisplayDessert(dessertCost); // Display the total dessert cost
DisplayFood(foodCost); // Display the total food cost
DisplayTiptax(tiptaxCost); // Display the total tip and tax cost
DisplayRoom(roomCost); // Display the room fee
DisplayDeposit(depositCost); // Display the deposit amount
DisplayCost(foodCost,tiptaxCost,roomCost,depositCost); // Display the balance due
system("PAUSE");
return 0;
}
int getInteger(const apstring &prompt)
{
int number;
cout << prompt;
cin >> number;
return number;
}
double getDouble(const apstring &prompt)
{
double number;
cout << prompt;
cin >> number;
return number;
}
// Function: CalculateTotalCost
// Input: 2 parameters of type double which represent the cost of the adult and child
// meals
// Output: the total cost is returned as a double value
// Task: to calculate the total cost of the meals purchased
double CalculateTotalCost(double foodCost, double tiptaxCost, double roomCost, double depositCost)
{
double cost; // total balance due
cost = foodCost + tiptaxCost + roomCost - depositCost;
return cost;
}
// Function: CalculateFoodCost
// Input: 3 parameters of type double which represent the cost of the adult, child
// and dessert meals
// Output: the food cost is returned as a double value
// Task: to calculate the total cost of the food meals purchased
double CalculateFoodCost(double adultCost, double childCost, double dessertCost)
{
double cost; // total cost for all meals purchased
cost = adultCost + childCost + dessertCost;
return cost;
}
// Function: ExplainProgram
// Input: Nothing
// Output: Nothing is returned but an explanation is placed on the output screen
// Task: Display an explanation of the program on the screen to inform
// the user of the program's purpose
void ExplainProgram()
{
cout << "This program will determine the cost of an adult and childs\n"
<< "meal, dessert cost, room cost, tip and tax cost and total cost.\n"
<< "User will enter the number of adult and children and the program will\n"
<< "determine the cost of the meals, dessert, room, tip, tax and total.\n\n";
}
// Function: DisplayCost
// Input: 8 parameters of type double representing the adult cost, child cost, dessert cost,
// food cost, tip/tax cost, room cost, deposit cost and total cost are received
// Output: Nothing is returned but an invoice of costs is displayed on
// the output screen
// Task: Display cost information on the screen for the user
void DisplayCost(int adults, int children, double adultMeal, double childMeal, double adultCost,
double childCost, double dessertCost, double foodCost, double tiptaxRate, double tiptaxCost, double roomCost,
double depositCost, double totalCost)
{
cout << endl;
cout << "Causewell Catering and Convention Service" << endl;
cout << "Final Bill" << endl;
cout << endl;
cout << setiosflags(ios::fixed) << setprecision(2);
cout << "Number of adults: " << adults << endl;
cout << "Number of children: " << children << endl;
cout << "Cost per adult without dessert: " << setw(6) << adultMeal << endl;
cout << "Cost per child without dessert: " << setw(6) << childMeal << endl;
cout << "Room fee: " << setw(6) << roomCost << endl;
cout << "Tip and tax rate: " << setw(6) << tiptaxRate << endl;
cout << endl;
cout << "Total Cost for adult meals: $" << setw(6) << adultCost << endl;
cout << "Total cost for child meals: $" << setw(6) << childCost << endl;
cout << "Total cost for dessert: $" << setw(6) << dessertCost << endl;
cout << "Total food cost: $" << setw(6) << foodCost << endl;
cout << "Plus tip and tax: $" << setw(6) << tiptaxCost << endl;
cout << "Plus room fee: $" << setw(6) << roomCost << endl;
cout << "Less deposit: $" << setw(6) << depositCost << endl;
cout << endl;
cout << "Balance due: $" << setw(6) << totalCost << endl;
}
// Function: CalculateAdultCost
// Input: Receives 1 parameter which represents the number of adult meals
// and it accesses 1 global constant (adultMeal) which represents the
// cost of one adult meal
// Output: return a double which represents the cost for all adult meals
// purchased
// Task: Calculate the cost of all of the adult tickets being purchased
double CalculateAdultCost(int adults, double adultMeal)
{
double cost; // cost of adult meals purchased
cost = adults * adultMeal;
return cost;
}
// Function: CalculateChildCost
// Input: Receives 1 parameter which represents the number of child meals
// and it accesses 1 global constant (childMeal) which represents the
// cost of one child meal
// Output: return a double which represents the cost for all child meals
// purchased
// Task: Calculate the cost of all of the child meals being purchased
double CalculateChildCost(int children, double childMeal)
{
double cost; // cost of child meals purchased
cost = children * childMeal;
return cost;
}
// Function: CalculateDessertCost
// Input: Receives 1 parameter which represents the number of child meals
// and it accesses 1 global constant (dessertMeal) which represents the
// cost of one dessert meal
// Output: return a double which represents the cost for all dessert meals
// purchased
// Task: Calculate the cost of all of the dessert meals being purchased
double CalculateDesertCost(double dessertMeal, int adults, int children)
{
double cost; // cost of dessert meals purchased
cost = dessertMeal * (adults + children);
return cost;
}
// Function: CalculateTiptaxCost
// Input: Receives 1 parameter which represents the number of child meals
// and it accesses 1 global constant (tiptaxRate) which represents the
// rate of tips and tax
// Output: return a double which represents the amount of total tips and
// tax
// Task: Calculate the total cost of tips and tax
double CalculateTiptaxCost(double tiptaxRate, double foodCost)
{
double cost; // tip and tax rate
cost = tiptaxRate * foodCost;
return cost;
}