Design a Soda Machine class that can keep track of the type of sodas and number of sodas in stock. Use the following UML class diagram to design the class Soda Machine.
SodaMachine
-brand [NUMPRODUCTS] : string
- inStock [NUMPRODUCTS] : int
-price: double
+SodaMachine();
+getBrand (int) : string
+setBrand (int, string): void
+getInStock (int) : int
+decrementStock (int): void
+getPrice(): double
+setInStock (int, int): void
+totalCans () : int
Your assignment is to write a complete C++ program which will produce the sample run shown.
Soda Machine(): The default constructor in class Soda Machine sets up the two arrays: an array of string that has the names of soda's type and an array of integer that keeps track of the number of soda's in stock. For example brand[0] ="Coke" and inStock[0] = 10, brand[1]="Orange", inStock[1]=8 and etc. Also set the price to 0.65 which is the price for each soda.
Hint: You can declare a constant variable const static int NUMPRODUCTS = 6 for the size of the two arrays.
In your Assignment7.cpp you will first display a menu to access the soda machine. Below are suggestions for functions to implement in the function main but you could add or not use all of the functions listed below:
void displayMenuChoice (char &, SodaMachine); //display the menu and get use input A-D
void errorChkChar (char &); //validate user input user character should be A-D
bool evaluateChoice (char, SodaMachine &); //evaluate if the choice is in valid rage, 1 through 6
void displaySodas (SodaMachine);
void getSoda (Soda Machine &); //buy the soda and update the inventory (the particular brand is reduced by 1)
void restock (Soda Machine &); //set a particular brand to 20 cans
int totalCans (SodaMachine); // return total number of cans left
Below are the menus and the starting number of cans for each product.
Soda Machine Main Menu
A. Get Soda - $.65
C. Restock Soda
D. Leave This Machine
The following is an explanation of each menu choice:
Get Soda (option A): This menu choice will displays the type of sodas in stock. It lists out the 6 different sodas available and how many are in stock. This is the starting cans for each product.
----------------------
Soda Type Stock
----------------------
1. Coke 10
2. Orange 8
3. Dew 6
4. Ice Tea 4
5. Water 2
6. Iced Coffee 0
Restock Soda (option B): The user will type in the name of the soda to be restocked. If the user does not type in the exact name of the old soda, an error message will display, because the program will not be able to match the names. If there is a soda name match, the user can restock the soda with 20 cans.
Leave this menu (option C): Leaves the menu and quit the program.
If the user choose to quit the program, the program states the total number of sodas.
If the user enters any letter other than A, B, or C the program prints wrong choice, prints the total number of drinks and exist the program.
All user input must be error checked. If it is out of range, an appropriate error message must be generated and the user must be prompted again. String input is case insensitive but not characters. (See the Sample Runs below.)
Soda Machine Main Menu
A. Get Soda - $0.65
B. Restock Soda
C. Leave This Machine
Enter your menu choice (A – C): a----------------------
Soda Type Stock
----------------------
1. Coke 10
2. Orange 8
3. Dew 6
4. Ice Tea 4
5. Water 2
6. Iced Coffee 0
Enter your choice: 1
Soda Machine Main Menu
A. Get Soda - $0.65
B. Restock Soda
C. Leave This Machine
Enter your menu choice (A – C): a----------------------
Soda Type Stock
----------------------
1. Coke 9
2. Orange 8
3. Dew 6
4. Ice Tea 4
5. Water 2
6. Iced Coffee 0
Enter your choice: 5
Soda Machine Main Menu
A. Get Soda - $0.65
B. Restock Soda
C. Leave This Machine
Enter your menu choice (A – C): a----------------------
Soda Type Stock
----------------------
1. Coke 9
2. Orange 8
3. Dew 6
4. Ice Tea 4
5. Water 1
6. Iced Coffee 0
Enter your choice: 5
Soda Machine Main Menu
A. Get Soda - $0.65
B. Restock Soda
C. Leave This Machine
Enter your menu choice (A – C): A----------------------
Soda Type Stock
----------------------
1. Coke 9
2. Orange 8
3. Dew 6
4. Ice Tea 4
5. Water 1
6. Iced Coffee 0
Enter your choice: 5
No water left. Make another selection.
Enter your choice: 1
Soda Machine Main Menu
A. Get Soda - $0.65
B. Restock Soda
C. Leave This Machine
Enter your menu choice (A – C): A----------------------
Soda Type Stock
----------------------
1. Coke 8
2. Orange 8
3. Dew 6
4. Ice Tea 4
5. Water 1
6. Iced Coffee 0
Enter your choice: 5
Soda Machine Main Menu
A. Get Soda - $0.65
B. Restock Soda
C. Leave This Machine
Enter your menu choice (A – C): B
Enter your beverage name: Water
Water is restocked with 20 cans.
Soda Machine Main Menu
A. Get Soda - $0.65
B. Restock Soda
C. Leave This Machine
Enter your menu choice (A – C): a----------------------
Soda Type Stock
----------------------
1. Coke 8
2. Orange 8
3. Dew 6
4. Ice Tea 4
5. Water 20
6. Iced Coffee 0
Enter your choice: 6
No Ice Coffee left. Make another selection.
Enter your choice: 2
Soda Machine Main Menu
A. Get Soda - $0.65
B. Restock Soda
C. Leave This Machine
Enter your menu choice (A – C): b
Enter the beverage name: Pepsi
Pepsi is not on the list. Make a different selection.
Enter the beverage name: Ice Tea
Ice Tea is restocked with 20 cans.
Soda Machine Main Menu
A. Get Soda - $0.65
B. Restock Soda
C. Leave This Machine
Enter your menu choice (A – C): a----------------------
Soda Type Stock
----------------------
1. Coke 8
2. Orange 8
3. Dew 6
4. Ice Tea 20
5. Water 20
6. Iced Coffee 0
Enter your choice: 2
Soda Machine Main Menu
A. Get Soda - $0.65
B. Restock Soda
C. Leave This Machine
Enter your menu choice (A – C): c
Total number of drinks: 59