CISC1600: Computer Science I Final Lab

Fall 2022

Write a program for a vending machine that sells the following four types of drinks: 1) coke ($2.5), 2) orange juice ($2.6), 3) root bear ($3.20), 4) water ($1.8).

Your program should work as follows:

  1. Display the company name
  2. Read the menu, first prompt the user to enter how many different drinks, and then read in a list of drink names, and then a list of prices Save these in two arrays
  3. Repeat the following until the user enters "Shutdown"
    1. Prompt the user to enter "Start or Shutdown"
    2. Read user command
    3. If the user enters "Shutdown", terminate the program by saying "Good Bye! Shutting down...".
    4. If the user enters "Start", take the user order, charge the user and give the change:
      1. first display the menu with all avaialble drinks and their prices
      2. prompt the user to select the drink, or enter -1 to abort
      3. If -1 is entered, abort this order, go back to ask the user to either "Start or Shutdown"
      4. Otherwise, display the drink selected and the amount due, and prompt user to enter coins by calling function TakeCoins (provided) if The function returns true, display "Giving changes..." and then "Enjoy Your drink."; if the function returns false (i.e., the user cancels the order), display "Order cancelled...".

Choosing variable type Throughout your program, you should store the prices, the amount due, and the balance in terms of cents (to avoid rounding errors when working with double or float).

Writing functions You are required to define several functions in this program:

  1. A function that reads the menu from the user
    	void ReadMenu (string drinksName[], int drinkPrice[], int & size)
    	
  2. A function that displays the menu.
    	void DisplayMenu (string drinksName[], int drinkPrice[], int size)
    	
  3. A function that simulates taking coins from user.
    	/* Keep prompting user to enter a coin until the total amount entered is no less
    	than the totalDueInCents, or until the user cancels 
    	In the former case, the function returns true, and set totalEntered to the 
    	 total value of coins entered; 
    	In the latter case, the function return false */
    	bool TakeCoins (int totalDueInCents, int & totalEntered)
    	{
    	}
    	

Example output

$a.out
YouthDrink Corp. Vending Machine
Loading menus....
Enter number of drinks:4
Enter 4 drink names:coke orange_juice root_bear water
Enter their prices: 250 260 320 180
Starting the machine.... 

Enter a command: Start (a new order) or Shutdown (the machine):Start
We offer the following drinks:
***********************
1. coke ($2.50)
2. orange_juice ($2.60)
3. root_bear ($3.20)
4. water ($1.80)
***********************
Enter the number for the drinks, or enter -1 to quit: 1
You ordered: coke
Total due $2.50. 
Enter coins (D for dollar, Q for quarter, M for dime, N for nickel, C to quit): D
$1.00 entered. 
Enter coins (D for dollar, Q for quarter, M for dime, N for nickel, C to quit): D
$2.00 entered. 
Enter coins (D for dollar, Q for quarter, M for dime, N for nickel, C to quit): D
$3.00 entered. 
Giving change: $0.50
Enjoy your drink. 

Enter a command: Start (a new order) or Shutdown (the machine):Start
We offer the following drinks:
***********************
1. coke ($2.50)
2. orange juice ($2.60)
3. root bear ($3.20)
4. water ($1.80)
***********************
Enter the number for the drinks, or enter -1 to quit: -1
Order cancelled.

Enter a command: Start (a new order) or Shutdown (the machine):Shutdown
Vending machine shutting down! 

How to submit Please submit your program (named finallab.cpp) to the following site by Dec 14, Wed, midngiht:

Autograder submission site.

Please email the instructor if you encounter any problems with the testcases.