Advertisement
okelikai

Untitled

Feb 27th, 2018
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 8.96 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. using namespace std;
  4.  
  5. const float BALCONY_PRICE = 25.00;
  6. const float ORCHESTRA_PRICE = 50.00;
  7. const float BOX_PRICE = 75.00;
  8. const float PREMIUM_PRICE = 20.00;
  9. const float PARKING_PRICE_PER_DAY = 10.00;
  10. const int MAX_DAYS_ALLOWED = 5;
  11.  
  12. //---------------------------------------------------------------------------
  13. // Name: GetYorN
  14. // Parameters: Questions, string, input, the YN question to ask
  15. // Returns: char; the character the user entered.  Must be 'y' or 'Y' or 'n' or 'N'
  16. // Purpose: This function returns the user's response to a yes/no question
  17. //---------------------------------------------------------------------------
  18. char GetYorN(const string Question)
  19. {
  20. char Choice;
  21.  
  22.      cout << Question << "  Enter Y or N: ";
  23.      cin >> Choice;
  24.      Choice = toupper(Choice);
  25.  
  26.      while (Choice != 'Y' && Choice != 'N')
  27.      {
  28.         cout << "Invalid character. Please enter either (Y) for yes or (N) for no.\n";
  29.         cout << Question << "  Enter Y or N: ";
  30.         cin >> Choice;
  31.         Choice = toupper(Choice);
  32.      }
  33.  
  34.      return (Choice);
  35. }
  36.  
  37. //---------------------------------------------------------------------------
  38. // Name: ParkingPass
  39. // Parameters: none
  40. // Returns: float; the cost of the pass ordered
  41. // Purpose: This function returns the cost of parking pass that a participant wants
  42. //---------------------------------------------------------------------------
  43. float ParkingPass()
  44. {
  45. char ParkingPassChoice = '\0';
  46. int ParkingDays = 0;
  47. float ParkingPassPrice = 0.0;
  48.  
  49.      ParkingPassChoice = GetYorN ("Would you like to buy parking passes?");
  50.  
  51.      if (ParkingPassChoice == 'Y')
  52.      {      
  53.         cout << "Parking passes are $10 per day." << endl;
  54.         cout << "How many days of parking would you like to buy (1-"
  55.              << MAX_DAYS_ALLOWED << "): ";
  56.         cin >> ParkingDays;
  57.  
  58.         while(ParkingDays < 1 || ParkingDays > MAX_DAYS_ALLOWED)
  59.         {
  60.             cout << "Please enter a valid number of days (1-"
  61.                  << MAX_DAYS_ALLOWED << ") or enter 0 to cancel your purchase: ";
  62.             cin >> ParkingDays;
  63.         }
  64.         ParkingPassPrice = PARKING_PRICE_PER_DAY * ParkingDays;
  65.      }
  66.  
  67.     return ParkingPassPrice;
  68. }
  69.  
  70. //---------------------------------------------------------------------------
  71. // Name: CalculatePrice
  72. // Parameters:  TicketName:  string, pass by value, name of ticket type
  73. //              PricePerTicket: float, pass by value, cost of one ticket
  74. //              NumTickets, int, input, number of tickets to purchase.
  75. // Returns: float - the total cost of the tickets purchased
  76. // Purpose: This function calculates and returns the cost of the tickets;
  77. //          It also prints out that cost to the user.
  78. //---------------------------------------------------------------------------
  79. float CalculatePrice(const string TicketName, const float PricePerTicket, const float NumTickets)
  80. {
  81. float Amount;
  82.  
  83.     Amount = NumTickets * PricePerTicket;
  84.  
  85.     cout << "\n--------------------------------------------------------------------------\n";
  86.     cout << "You have chosen to order " << noshowpoint << setprecision(0) << NumTickets
  87.          << " "  << TicketName << " tickets.\n";
  88.     cout << fixed << showpoint << setprecision(2);
  89.     cout << "Each ticket costs $" << PricePerTicket << ".\n";
  90.     cout << "The price for these tickets is $" << Amount << endl;
  91.     cout << "--------------------------------------------------------------------------\n\n";
  92.     return Amount;
  93. }
  94.  
  95. //---------------------------------------------------------------------------
  96. // Name: AddPremium
  97. // Parameters: Price, float, input/output, current cost of the tickets
  98. //             It gets updated if the user selects the premium upgrade
  99. //             NumTickets, const int, input, the number of tickets.
  100. // Returns: none
  101. // Purpose: This function adds the cost of the premium upgrade, if the patron
  102. //          chooses to purchase it
  103. //---------------------------------------------------------------------------
  104. void AddPremium(float &Price, const int NumTickets)
  105. {
  106. char Choice;
  107.  
  108.     cout << "\n----------------------------------------------------------------------------------------------\n";
  109.     cout << "You have chosen to order Box seat tickets.\n";
  110.     cout << "You can add a premium package that includes a souvenier and free refreshments.\n"
  111.          << "This costs $" << PREMIUM_PRICE<< " per ticket.\n";
  112.     cout << "----------------------------------------------------------------------------------------------\n\n";
  113.  
  114.     Choice = GetYorN("Would you like to add the premium package?");
  115.    
  116.     if (Choice == 'Y')
  117.     {
  118.         Price = Price + NumTickets * PREMIUM_PRICE;
  119.         cout << "Your Box seats with the premium upgrade cost $"
  120.              << fixed << showpoint << setprecision(2) << Price
  121.              << " for " << noshowpoint << setprecision (0) << NumTickets << " tickets.\n";
  122.     }  
  123. }
  124.  
  125. //---------------------------------------------------------------------------
  126. // Name: MainMenu
  127. // Parameters: none
  128. // Returns: none
  129. // Purpose: This function prints the main menu describing various tickets
  130. //          offered by the Walton Arts Center
  131. //---------------------------------------------------------------------------
  132. void MainMenu()
  133. {
  134.     char MoreInfo;
  135.  
  136.     cout << "The Walton Arts Center offers its patrons an assortment\n"
  137.          << "of tickets to fit different budgets.\n"
  138.          << "There are three kinds of seats that the Arts Center offers:\n"
  139.          << "Balcony, Orchestra, and Box seats.\n\n";
  140.  
  141.     MoreInfo = GetYorN("Would you like more information about each ticket type?");
  142.  
  143.     if(MoreInfo == 'Y')
  144.     {
  145.         cout << "The Balcony tickets are the cheapest, because the tickets"
  146.              << " are located the furthest from stage.\n";
  147.              
  148.         cout << "The Orchestra tickets are more expensive, because the tickets allow "
  149.              << "participants to sit closer to the stage.\n";
  150.  
  151.         cout << "The Box seat tickets are the most expensive, "
  152.              << "because the seats are very comfortable and private.\n"
  153.              << "Box seat purchasers can also add other options (souvenirs and refreshments)"
  154.              << " to their purchase.\n\n";
  155.    }
  156. }
  157.  
  158. //---------------------------------------------------------------------------
  159. // Name: TicketType
  160. // Parameters: none
  161. // Returns: char; the selection of ticket to be purchased
  162. // Purpose: This function asks the user which ticket they would like to buy
  163. //---------------------------------------------------------------------------
  164. char GetTicketType()
  165. {
  166.     char TicketType;
  167.  
  168.     cout << "\nWhich ticket would you like to purchase next?\n";
  169.     cout << "Type B for Balcony, O for Orchestra, or X for Box: ";
  170.     cin >> TicketType;
  171.     TicketType = toupper(TicketType);   //convert to uppercase
  172.  
  173.     //User I/O error-checking
  174.     while(TicketType != 'B' && TicketType != 'O' && TicketType != 'X')
  175.     {
  176.         cout << TicketType << " is invalid input.\n";
  177.         cout << "Type B for Balcony, O for Orchestra, or X for Box: ";
  178.         cin >> TicketType;
  179.         TicketType = toupper(TicketType);
  180.     }
  181.  
  182.     return TicketType;
  183. }
  184.  
  185. //---------------------------------------------------------------------------
  186. // Name: GetNumTickets
  187. // Parameters: NumTickets, integer, reference, passes back the number of tickets requested
  188. // Returns: none
  189. // Purpose: This function asks the user how many tickets would like to buy
  190. //---------------------------------------------------------------------------
  191. void GetNumTickets (int &NumTickets)
  192. {
  193.    cout << "Enter the number of tickets you would like to buy: ";
  194.    cin >> NumTickets;
  195.    while(NumTickets < 0) //User I/O error-checking
  196.    {
  197.        cout << "Please enter a non-negative number of tickets: ";
  198.        cin >> NumTickets;
  199.    }
  200. }
  201.  
  202.  
  203. //---------------------------------------------------------------------------
  204. //  This is the main program that you need to write
  205. //---------------------------------------------------------------------------
  206. int main ()
  207. {
  208. // Variable Declarations
  209. char Choice = '\0';   // what the user enters
  210. int NumTickets = 0;   // how many tickets they want to buy
  211. float Price = 0.0;    // the price of one set of tickets
  212. float Total = 0.0;    // the total price of all tickets
  213.  
  214.  
  215.    // Print your name and UAID
  216.  
  217.    // Loop until the user is done
  218.        // Print the main menu describing the tickets offered
  219.        
  220.        // Ask the user type what ticket they want to purchase next
  221.  
  222.        // Find out how many tickets they want
  223.  
  224.        // Find out the price of the tickets
  225.        // If the user selects Box seats, ask if they want the premium package
  226.        
  227.        // Add the ticket price to a running total
  228.  
  229.        // Ask if they want to continue (Y or N)
  230.  
  231.    // When the loop is done
  232.    // Sell the user parking pass
  233.  
  234.    // Print out the total amount of all the tickets and parking passes
  235.    // that the participant has purchased to 2 decimal places, with a $
  236.    
  237.    return 0;
  238. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement