Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- using namespace std;
- const float BALCONY_PRICE = 25.00;
- const float ORCHESTRA_PRICE = 50.00;
- const float BOX_PRICE = 75.00;
- const float PREMIUM_PRICE = 20.00;
- const float PARKING_PRICE_PER_DAY = 10.00;
- const int MAX_DAYS_ALLOWED = 5;
- //---------------------------------------------------------------------------
- // Name: GetYorN
- // Parameters: Questions, string, input, the YN question to ask
- // Returns: char; the character the user entered. Must be 'y' or 'Y' or 'n' or 'N'
- // Purpose: This function returns the user's response to a yes/no question
- //---------------------------------------------------------------------------
- char GetYorN(const string Question)
- {
- char Choice;
- cout << Question << " Enter Y or N: ";
- cin >> Choice;
- Choice = toupper(Choice);
- while (Choice != 'Y' && Choice != 'N')
- {
- cout << "Invalid character. Please enter either (Y) for yes or (N) for no.\n";
- cout << Question << " Enter Y or N: ";
- cin >> Choice;
- Choice = toupper(Choice);
- }
- return (Choice);
- }
- //---------------------------------------------------------------------------
- // Name: ParkingPass
- // Parameters: none
- // Returns: float; the cost of the pass ordered
- // Purpose: This function returns the cost of parking pass that a participant wants
- //---------------------------------------------------------------------------
- float ParkingPass()
- {
- char ParkingPassChoice = '\0';
- int ParkingDays = 0;
- float ParkingPassPrice = 0.0;
- ParkingPassChoice = GetYorN ("Would you like to buy parking passes?");
- if (ParkingPassChoice == 'Y')
- {
- cout << "Parking passes are $10 per day." << endl;
- cout << "How many days of parking would you like to buy (1-"
- << MAX_DAYS_ALLOWED << "): ";
- cin >> ParkingDays;
- while(ParkingDays < 1 || ParkingDays > MAX_DAYS_ALLOWED)
- {
- cout << "Please enter a valid number of days (1-"
- << MAX_DAYS_ALLOWED << ") or enter 0 to cancel your purchase: ";
- cin >> ParkingDays;
- }
- ParkingPassPrice = PARKING_PRICE_PER_DAY * ParkingDays;
- }
- return ParkingPassPrice;
- }
- //---------------------------------------------------------------------------
- // Name: CalculatePrice
- // Parameters: TicketName: string, pass by value, name of ticket type
- // PricePerTicket: float, pass by value, cost of one ticket
- // NumTickets, int, input, number of tickets to purchase.
- // Returns: float - the total cost of the tickets purchased
- // Purpose: This function calculates and returns the cost of the tickets;
- // It also prints out that cost to the user.
- //---------------------------------------------------------------------------
- float CalculatePrice(const string TicketName, const float PricePerTicket, const float NumTickets)
- {
- float Amount;
- Amount = NumTickets * PricePerTicket;
- cout << "\n--------------------------------------------------------------------------\n";
- cout << "You have chosen to order " << noshowpoint << setprecision(0) << NumTickets
- << " " << TicketName << " tickets.\n";
- cout << fixed << showpoint << setprecision(2);
- cout << "Each ticket costs $" << PricePerTicket << ".\n";
- cout << "The price for these tickets is $" << Amount << endl;
- cout << "--------------------------------------------------------------------------\n\n";
- return Amount;
- }
- //---------------------------------------------------------------------------
- // Name: AddPremium
- // Parameters: Price, float, input/output, current cost of the tickets
- // It gets updated if the user selects the premium upgrade
- // NumTickets, const int, input, the number of tickets.
- // Returns: none
- // Purpose: This function adds the cost of the premium upgrade, if the patron
- // chooses to purchase it
- //---------------------------------------------------------------------------
- void AddPremium(float &Price, const int NumTickets)
- {
- char Choice;
- cout << "\n----------------------------------------------------------------------------------------------\n";
- cout << "You have chosen to order Box seat tickets.\n";
- cout << "You can add a premium package that includes a souvenier and free refreshments.\n"
- << "This costs $" << PREMIUM_PRICE<< " per ticket.\n";
- cout << "----------------------------------------------------------------------------------------------\n\n";
- Choice = GetYorN("Would you like to add the premium package?");
- if (Choice == 'Y')
- {
- Price = Price + NumTickets * PREMIUM_PRICE;
- cout << "Your Box seats with the premium upgrade cost $"
- << fixed << showpoint << setprecision(2) << Price
- << " for " << noshowpoint << setprecision (0) << NumTickets << " tickets.\n";
- }
- }
- //---------------------------------------------------------------------------
- // Name: MainMenu
- // Parameters: none
- // Returns: none
- // Purpose: This function prints the main menu describing various tickets
- // offered by the Walton Arts Center
- //---------------------------------------------------------------------------
- void MainMenu()
- {
- char MoreInfo;
- cout << "The Walton Arts Center offers its patrons an assortment\n"
- << "of tickets to fit different budgets.\n"
- << "There are three kinds of seats that the Arts Center offers:\n"
- << "Balcony, Orchestra, and Box seats.\n\n";
- MoreInfo = GetYorN("Would you like more information about each ticket type?");
- if(MoreInfo == 'Y')
- {
- cout << "The Balcony tickets are the cheapest, because the tickets"
- << " are located the furthest from stage.\n";
- cout << "The Orchestra tickets are more expensive, because the tickets allow "
- << "participants to sit closer to the stage.\n";
- cout << "The Box seat tickets are the most expensive, "
- << "because the seats are very comfortable and private.\n"
- << "Box seat purchasers can also add other options (souvenirs and refreshments)"
- << " to their purchase.\n\n";
- }
- }
- //---------------------------------------------------------------------------
- // Name: TicketType
- // Parameters: none
- // Returns: char; the selection of ticket to be purchased
- // Purpose: This function asks the user which ticket they would like to buy
- //---------------------------------------------------------------------------
- char GetTicketType()
- {
- char TicketType;
- cout << "\nWhich ticket would you like to purchase next?\n";
- cout << "Type B for Balcony, O for Orchestra, or X for Box: ";
- cin >> TicketType;
- TicketType = toupper(TicketType); //convert to uppercase
- //User I/O error-checking
- while(TicketType != 'B' && TicketType != 'O' && TicketType != 'X')
- {
- cout << TicketType << " is invalid input.\n";
- cout << "Type B for Balcony, O for Orchestra, or X for Box: ";
- cin >> TicketType;
- TicketType = toupper(TicketType);
- }
- return TicketType;
- }
- //---------------------------------------------------------------------------
- // Name: GetNumTickets
- // Parameters: NumTickets, integer, reference, passes back the number of tickets requested
- // Returns: none
- // Purpose: This function asks the user how many tickets would like to buy
- //---------------------------------------------------------------------------
- void GetNumTickets (int &NumTickets)
- {
- cout << "Enter the number of tickets you would like to buy: ";
- cin >> NumTickets;
- while(NumTickets < 0) //User I/O error-checking
- {
- cout << "Please enter a non-negative number of tickets: ";
- cin >> NumTickets;
- }
- }
- //---------------------------------------------------------------------------
- // This is the main program that you need to write
- //---------------------------------------------------------------------------
- int main ()
- {
- // Variable Declarations
- char Choice = '\0'; // what the user enters
- int NumTickets = 0; // how many tickets they want to buy
- float Price = 0.0; // the price of one set of tickets
- float Total = 0.0; // the total price of all tickets
- // Print your name and UAID
- // Loop until the user is done
- // Print the main menu describing the tickets offered
- // Ask the user type what ticket they want to purchase next
- // Find out how many tickets they want
- // Find out the price of the tickets
- // If the user selects Box seats, ask if they want the premium package
- // Add the ticket price to a running total
- // Ask if they want to continue (Y or N)
- // When the loop is done
- // Sell the user parking pass
- // Print out the total amount of all the tickets and parking passes
- // that the participant has purchased to 2 decimal places, with a $
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement