CSC 161 Program #1

"Vending Machine"
Assigned: Weds Apr 2, 2003 Design due: Mon Apr 7, 2003
Grade: 80 points Due: Mon Apr 14, 2003

Concepts

This program reviews many of the concepts we covered in CSC 160, including:

  • Basic I/O and formatted output
  • Basic data types: int, float, bool, string
  • Classes, objects and object-oriented programming
  • Arrays
  • Searching an array
  • Multiple-file programs and Visual C++

Description

The "Vending Machine" program is a modification of the "Drink Machine Simulator" on page 582 of our text.

Your program should have 4 steps:

  1. Fill your vending machine with items
  2. Ask the user to select an item
  3. Get the user's payment for the item and then dispense the item
  4. Ask the user if he/she wants another item (return to step 2)

Example Session

Here's a possible example session (user input in bold):

** Vending Machine **
 
Slot  Item                  Price   Quantity
A1    Super ball            $0.35   4
A2    Grape Nehi            $0.25   2
B1    Fake tattoo           $0.50   2
B2    Tiny American flags   $1.00   5
 
Select an vending slot> A1
 
You have selected Super Ball
You owe $0.35
Enter a [N]ickel, [D]ime, [Q]uarter, or [R]eturn coins> Q
Quarter accepted
You owe $0.10
Enter a [N]ickel, [D]ime, [Q]uarter, or [R]eturn coins> Q
Quarter accepted
Super Ball dispensed
You change is: 1 dime, 1 nickel
 
Do you want another item> no

Implementation

Your implementation must use classes in an object-oriented approach. As a hint, I used the following classes in my solution:

  • VendingMachine - contains an array of vending slots that can be filled and dispensed.
  • VendingSlot - each slot in a VendingMachine has its own name and contains the name of the item in the slot, its price and how many there are in the slot.
  • CoinChanger - accepts coins (nickels, dimes, quarters) until a given amount is reached. It can also calculate the change if the user overpays.

 


Grading

Your program will be graded on three areas: design, quality, and function. Their description and weighting in your grade is given below.

1. Program Design (25%)

It is essential to design your program before pounding it out in front of Visual C++. The design for this program requires:

  • A header each class that you design with member variables and functions defined and commented.
  • A pseudo-code description of main().

You should include all the class interface files in your main() and be able to compile, but not build (or link) because your class member functions are not yet written.

2. Program quality (25%)

I'm working on a more comprehensive style guide, but here's what I will be looking for:

  • File comments - at the top of the file, list the file name (for printing purposes), your name, the date, "CSC 161", and what the file contains
  • Class comments - describe the purpose of the class
  • Function comments - describe the purpose of each function, it's parameters and return value if any
  • Variable comments - describe the purpose of each variable
  • Block comments - describe large or complex blocks of code in your functions
  • Well-chosen names - descriptive names for classes, functions, variables, etc.
  • Proper indentation - consistent indentation, just use the built-in facilities in Visual C++, and you'll be golden.
  • Readability - nice spacing of major sections and functions, clear flow and design

3. Program function (50%)

If your program doesn't compile or link, your grade for this section will automatically be cut in half and then I'll start from there. Please leave a README file in your prog01 folder with notes you want me to read.

I will use your vending machine, of course... and, of course, it should work.

I will be sure to try some error cases as well:

  • Specifying a bad item or vending slot
  • Trying to get an item after they've all been vended (I guess)

Good luck.

Notes

I filled my vending machine with the following items:

Slot Item Cost Quantity
A1 Super ball .35 4
A2 Grape Nehi .25 2
B1 Fake tattoo .50 2
B2 Tiny American flags 1.00 5

You can fill your vending machine with any items you like. Please keep the quantities on some items low, so that I can test your program for 0 items in a slot.