The first three people to complete this program will be entered into the annual contest for Top Coder! The grand prize is the chance to become one of TopCoders independent programmer. This is a special opportunity to get paid for programing projects that you create. Below is the program to be written. It appears simple but details are a priority.

Vending Machine

Write a complete C++ program which will produce the sample runs shown at the end.

You will first ask the user to choose a school (ASU or UA) or to quit the program. If a school is chosen, display a menu to access that school's vending machine. Below is the menu and the starting amounts in each machine.

[school] Vending Machine Main Menu
-----------------------------
A. Get Soda - $ .65
B. Change Brand
C. Restock Soda
D. Leave This Machine
-----------------------------

[school] Vending Machine
------------------------
Type Stock
------------------------
Coke 10
Orange 8
Dew 6
Ice Tea 4
Evian 2
space available 0


The following is an explanation of each menu choice:

Get Soda
This menu choice displays the vending machine. It lists out the 6 different sodas available and how many are in stock.
See the list above for starting types and amounts.

Change Brand
This allows the user to swap out one soda for a different brand of soda. The user will be prompted for the new soda's name and the name of the old soda to be replaced. The new soda will begin with five (5) cans of soda. 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. The user may not remove the Coke. This will be one of your assumptions.

Restock Soda
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
Leaves the menu and again asks for a school or quit the program.


If the user choose to quit the progarm, the program states Whose machine has more Coke left and how many Cokes each school has. (See the Sample Runs below.)

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 sensitive while character input is case insensitive. (See the Sample Runs below.)

You may wish to use the following two system calls. Each is a simple statement.

system("CLS");
This command will clear the screen.

system("PAUSE");
This command will pause the screen. Great for displaying reports. This command causes the onscreen message of "Press any key to continue . . ." in the following sample output. Once the user presses any key, you want the main menu to display again.

Unified Modeling Language (UML)
The UML is an open method used to specify, visualize, construct and document an object-oriented program.
The diagram shown here is very simplified example of one. I recommend you read the notes on the homepage under
Handouts > Class/Struct > A Very Quick Overview

You may think of this as the pseudocode of your class. The first part is the name of the class, the second part is a list of attributes, and the third part is a list of behaviors. Public behaviors amd attributes are preceded by a + (plus) and private behaviors and attributes are preceded buy a – (minus).

An example of the pseudocode for this assignment is in the diagram shown here.

VendingMachine
-brand[6];
-inStock[6];
-price
+getBrand
+setBrand
+getInStock
+setInStock
+decrementStock
+getprice


The major purposes of this assignment are to demonstrate:
# good design, particularly pseudocode
-- Just because your program produces the correct output does not mean that the program is correct.
# the ability to use UML diagrams as part of the design
# the appropriate use of classes.
# good programming practices, including pre- and post-conditions

Hints:
An array can be made up of any data type.
A user defined class is a data type.
setInStock() sets the number of cans for a particular item
decrementStock() will reduce, by one, the number of cans for a particular item

Assumption(s): ?

Helpful Code: If you decide to use this code, you must change the identifiers. Items that require reference to a class are listed as ???.
Put the DO loop in main().

do{
which_school_will_be_chosen(institution);
 
if(institution== "ASU")
??? = ???
else if(institution== "UA")
??? = ???
else if(institution== "Q" || institution== "q")
break;
 
display_the_Menu_and_get_input(pick_of_user, institution, ???);
flag = evaluate_user_input(pick_of_user, institution, ???);
 
// transfers collected data to appropriate school machine
if( institution== "ASU")
??? = ??? 
else 
??? = ???
}while(flag)
 
 
void display_the_Menu_and_get_input(char & pick_of_user, string institution, ???)
{
system("cls"); // clear the screen
 
// display the main menu
cout << endl;
cout << " " << institution << " Vending Machine Main Menu" << endl;
cout << " -----------------------------" << endl;
cout << setw(15) << "A. " << "Get Soda - $ " << vm.getPrice() << endl;
cout << setw(15) << "B. " << "Change Brand" << endl;
cout << setw(15) << "C. " << "Restock Soda" << endl;
cout << setw(15) << "D. " << "Leave this menu" << endl;
cout << " -----------------------------" << endl;
 
cout << "Enter your menu choice (A - D): ";
cin >> pick_of_user ;
 
choice = toupper(pick_of_user);
errorChkChar(pick_of_user);
 
cin.ignore(100, '\n');
}
 
void errorChkChar(char & userCharacter)
{
while(userCharacter < 'A' || userCharacter > 'D' )
// doesn't work (userCharacter != 'A' || userCharacter != 'F' )
{
cout << "Invalid entry. Use only A-D. Try again. ";
cin >> userCharacter;
userCharacter = toupper(userCharacter);
}
}
 
bool evaluate_user_input(pick_of_user, institution, & ???)
{
switch(choice)
{
case 'A':
show_soda_list(institution, ???);
get_soda_to_drink(???);
return true; break;
case 'B':
show_soda_list(???)
change_a_brand_of _soda(???);
return true; break;
case 'C':
show_soda_list(institution, ???);
user_enters_a_new_brand_of_soda(???);
return true; break;
case 'C':
puts_20_sodas_to_restock(???);
return true; break;
case 'D':
return false;
// no default because choice is validated before being passed
}
}
 
 
void get_soda_to_drink(???)
{
int user_soda_selection // menu choice
bool flag = false; // OK to go on, no errors
 
do{
cout << "Enter your choice: ";
cin >> user_soda_selection ;
while(user_soda_selection < 1 || user_soda_selection > 6)
{
cout << "Please enter only 1 - 6.";
cout << " Reenter your choice: ";
cin >> user_soda_selection ;
}
 
bool flag = false; // OK to go on, no errors
 
// checks to see whether there are sodas left
if(???(user_soda_selection - 1) < 1)
{ 
cout << "\nNo " << ???(user_soda_selection - 1) 
<< " left. Make another selection.\n";
flag = true; // an error, repeat choice
}
}while(flag);
 
// decreases amount of specific soda by 1
???(user_soda_selection );
}

Program requirements and/or constraints:
# Create your plan BEFORE you begin to write the code.
# Follow the Style Guide. All requirements stated there must be met.
# You must use a class in an appropriate manner. - No class, no points.
# All requirements of functions apply to methods.
# Include: structure chart for the client, pseudocode, pre- and post-conditions, etc.
# "ASU" and "UA" are case sensitive inputs.
# Validate all user input
# Use comments freely throughout the program.
# Make sure your pseudocode is typed.
# Do not use material beyond the current topic.
# Do your own work.

Be sure to hand-in in the appropriate envelope:
# The typed plan for your program (pseudocode)
Turn in a UML diagram as the pseudocode for the class.
# A structure chart (may be hand drawn)
# Hardcopy of your source code
# The top of your submission file must begin with the following:

/*===========================================

( 3 blank lines - This is where the graders will put your grade. )

===========================================*/

Submit your source code using the Submission/Retrieval feature on the homepage.

*Normally the source code would be in three separate files, the specification, the implementation, and the client. Our submission program permits a single file entry. Thus, combine the three files in one, preceed each section with a comment (specification, implementation, client). Also comment out any code that would be redundant for a single file submission. Your submission is expected to compile withour errors.


Sample runs: User input is represented by [ ].

Whose machine, ASU or UA? Type Q to quit. [ASU]

// new screen
ASU Vending Machine Main Menu
-----------------------------
A. Get Soda - $ .65
B. Change Brand
C. Restock Soda
D. Leave This Machine
-----------------------------
Enter your menu choice (A - D): [a]

ASU Vending Machine
----------------------------
Soda Type Stock
----------------------------
1. Coke 10
2. Orange 8
3. Dew 6
4. Ice Tea 4
5. Evian 2
6. space available 0
Enter your choice: [1]

Whose machine, ASU or UA? Type Q to quit. [ASU]

// new screen
ASU Vending Machine Main Menu
-----------------------------
menu appears
-----------------------------
Enter your menu choice (A - D):

ASU Vending Machine
----------------------------
Soda Type Stock
----------------------------
1. Coke 9
2. Orange 8
3. Dew 6
4. Ice Tea 4
5. Evian 2
6. space available 0
Enter the beverage to change: [Evian]
Enter the new brand: [Jolt]
Jolt replaces Evian and is stocked with 5 cans.
Press any key to continue . . . // This is NOT a return to the source code.

Whose machine, ASU or UA? Type Q to quit. [UA]

// new screen
UA Vending Machine Main Menu
-----------------------------
menu appears
-----------------------------
Enter your menu choice (A - D): [A]

UA Vending Machine
----------------------------
Soda Type Stock
----------------------------
1. Coke 10
2. Orange 8
3. Dew 6
4. Ice Tea 4
5. Evian 2 // Note that in the UA machine #5 is 'Evian'
6. space available 0
Enter your choice: [2]

Whose machine, ASU or UA? Type Q to quit. [UA]

// new screen
UA Vending Machine Main Menu
-----------------------------
menu appears
-----------------------------
Enter your menu choice (A - D): [d]

Whose machine, ASU or UA? Type Q to quit. [UA]

// new screen
UA Vending Machine Main Menu
-----------------------------
menu appears
-----------------------------
Enter your menu choice (A - D): [c]
Enter the beverage name: [Evian]
Evian is restocked with 20 cans.
Press any key to continue . . .

Whose machine, ASU or UA? Type Q to quit. UA

// new screen
UA Vending Machine Main Menu
-----------------------------
menu appears
-----------------------------
Enter your menu choice (A - D): [D]

Whose machine, ASU or UA? Type Q to quit. Q

UofA has more Coke left. ASU - 9 to UA - 10
ASU has 37 cans of soda and UofA has 47 cans of soda
Press any key to continue

Whose machine, ASU or UA? Type Q to quit. [asu]
Invalid entry. Case counts. Try again.
Whose machine, ASU or UA? Type Q to quit. [ASU]

// new screen
ASU Vending Machine Main Menu
-----------------------------
menu appears
-----------------------------
Enter your menu choice (A - D): [k]
Invalid entry. Use only A-F. Try again. [M]
Invalid entry. Use only A-F. Try again. [a]

ASU Vending Machine
----------------------------
Soda Type Stock
----------------------------
1. Coke 10
2. Orange 8
3. Dew 6
4. Ice Tea 4
5. Evian 2
6. space available 0
Enter your choice: [9]
Please enter only 1 - 6. Reenter your choice: [6]

No space available left. Make another selection.
Enter your choice: [4]

Whose machine, ASU or UA? Type Q to quit. [UA]

// new screen
UA Vending Machine Main Menu
-----------------------------
menu appears
-----------------------------
Enter your menu choice (A - D):

UA Vending Machine
----------------------------
Soda Type Stock
----------------------------
1. Coke 10
2. Orange 8
3. Dew 6
4. Ice Tea 4
5. Evian 2
6. space available 0
Enter the beverage to change: [WildCat]
The brand you entered is not on the list.
Press any key to continue . . .

Whose machine, ASU or UA? Type Q to quit. [AU]
Invalid entry. Case counts. Try again.
Whose machine, ASU or UA? Type Q to quit. [UA]

// new screen
UA Vending Machine Main Menu
-----------------------------
menu appears
-----------------------------
Enter your menu choice (A - D):[C]
Enter the beverage name: [Pepsi]
Pepsi is not on the list. Make a different selection.
Enter the beverage name: [Dew]
Dew is restocked with 20 cans.

Whose machine, ASU or UA? Type Q to quit. [UA]

// new screen
UA Vending Machine Main Menu
-----------------------------
menu appears
-----------------
Enter your menu choice (A - D): [a]

UA Vending Machine
----------------------------
Soda Type Stock
----------------------------
1. Coke 10
2. Orange 8
3. Dew 6
4. Ice Tea 4
5. Evian 2
6. Wild Cat 5
Enter your choice: [4]

Whose machine, ASU or UA? Type Q to quit. [K]
Invalid entry. Case counts. Try again.
Whose machine, ASU or UA? Type Q to quit. [q]

ASU and UofA have the same amount of Coke, 10
ASU has 29 cans of soda and UofA has 43 cans of soda
Press any key to continue

Recommended Answers

All 7 Replies

Member Avatar for iamthwee

What's the top prize again? How do I enter :rolleyes:

What's the top prize again? How do I enter :rolleyes:

I think it is 29 cans of soda. Shall we share?

> The first three people to complete this program will be entered into the annual contest for Top Coder!
Seems the best thing to do is to goto the site and verify this.

No wait, this is just another "ruse" to get someone else to do your homework isn't it?

The first three people to complete this program will be entered into the annual contest for Top Coder! The grand prize is the chance to become one of TopCoders independent programmer. This is a special opportunity to get paid for programing projects that you create. Below is the program to be written. It appears simple but details are a priority.

Vending Machine

That's just sad. If this is an attempt to trick others into doing your homework, it's not a very good one. Keep in mind that several of us have seen every trick in the book. As "contest" tricks go, this one is pretty lame. I can't give you a good grade for your attempt, so I'll simply match the grade you would get for the program if you wrote it yourself.

Your Grade: D-

<offtopic>When I was in school, I was hanging out in the Computer Science Student Lounge when a professor walked in to get a soda out of the vending machine. Then, he exclaimed he had this great idea to give the first year students a project with vending machines and we all got into a discussion with him about it. Thread just brought back memories. Carry on your way.</offtopic>

<offtopic>When I was in school, I was hanging out in the Computer Science Student Lounge when a professor walked in to get a soda out of the vending machine. Then, he exclaimed he had this great idea to give the first year students a project with vending machines and we all got into a discussion with him about it. Thread just brought back memories. Carry on your way.</offtopic>

I'm sure "vending machine" programs are part of the defacto standard set of assignments for School/College/Uni computing students :) One of our 1st year A-level mini projects was very similar in Turbo Pascal

I never had a vending machine problem, but I've had airport simulations and matrix classes :-)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.