$29.99
In this project you will model a vending machine.
Enjoy!
Coke
Pepsi
7 Up
Status panel
Coin slot
Select button
Delivery chute
Product display
Figure 1. Vending machine
Principals of Operation You can imagine the external interface of the vending machine including a product display area allowing customers to see the available products, a status panel that displays messages when users take actions (e.g. to tell the user she must insert more money if not enough money has been inserted for a purchase), a coin slot for inserting money, a set of buttons for selecting a product to purchase, and a delivery chute from which customers may retrieve a purchased product.
Internally the vending machine contains a set of product racks. Each product rack holds a set of products all of the same type.
Two types of individuals may use a vending machine, a customer and a service professional. The customer can insert coins into the vending machine, press buttons to
CSE-40477 – C/C++ III, Intermediate Programming with Objects – Project #1
Page 2 of 5
purchase products (sodas), and retrieve products from the vending machine’s delivery chute one at a time. The service professional can add products to the vending machine, request the number of products of a certain type currently in the machine, request the current total balance of coins, and empty the till of all of the coins.
The following UML class diagram shows the classes and operations that will be used to model the vending machine.
+insertCoin() +pressButton() +retrieveProduct() +addProduct() +getProductCount() +countTill() +getNumCoinsInCoinBox()
-numCoins -unspentMoneyCents VendingMachine
+getDenomination() +getValueCents() -denomination Coin
+insertProduct() +retrieveProduct()
DeliveryChute
+getBrand() +setBrand() +getName() +setName() +getSize() +setSize()
-brand -name -size Product
+press() +getProductPriceCents()
ProductButton
+isCompatibleProduct() +isEmpty() +isFull() +addProduct() +deliverProduct() +getNumProductsInRack() +getProductPriceCents()
-allowedProductName -productCount -productPriceCents ProductRack
+displayMessage() -messages StatusPanel 1 1
1
1
0..*1
0..*1
0..*
1
1
0..1
1
1
0..*
1
1
1
1
1
1
1
Figure 2. UML class diagram for vending machine.
Requirements The following requirements must be met by the vending machine implementation (more details are provided in the provided source code).
CSE-40477 – C/C++ III, Intermediate Programming with Objects – Project #1
Page 3 of 5
Any operation that fails (such as inserting an invalid coin into the machine) should cause an appropriate message to be displayed on the status panel. Each product rack is associated with a specific type of product. If an attempt is made to add a product of a type with no matching product rack then the attempt should fail. Each product rack is limited to holding a maximum number of products. An attempt to add a product to an already full product rack should fail. The vending machine accepts the following types of coins: dollars, half-dollars, quarters, dimes, nickels, and pennies. Any other type of coin (e.g. wooden nickel) inserted into the machine should be rejected. An attempt to purchase a product when the product rack containing that product is empty should fail. The delivery chute may only contain a single product at a time. If an attempt is made to purchase a product when another product is already in the delivery chute then the purchase should fail. Pushing a button on the vending machine entails passing the button index to a member function. If no button exists at that index in the vending machine the operation should fail. Attempting to purchase a product when insufficient coins have been inserted into the vending machine should fail.
Project Files
Files you must implement These files contain the class member function definitions for the classes required by the vending machine. You must complete the implementations of the member functions in these files: Coin.cpp DeliveryChute.cpp Product.cpp ProductButton.cpp ProductRack.cpp VendingMachine.cpp
Files you must not change The following files have already been implemented and must not be changed. I will use my own original versions of these files when grading. These files must not be modified: Vending Machine Header Files o Coin.h o DeliveryChute.h o Product.h o ProductButton.h o ProductRack.h o StatusPanel.h o VendingMachine.h
CSE-40477 – C/C++ III, Intermediate Programming with Objects – Project #1
Page 4 of 5
Status Panel Implementation File - This implementation has been provided for you because we have not yet covered ostreams o StatusPanel.cpp – Test Framework – Generic test framework for running unit tests (will be reused for project #2) o TestFramework.cpp o TestFramework.h Unit Tests – These tests test the logic of the functions you will be implementing o main.cpp o UnitTest.cpp o UnitTest.h
Work required You will need to provide an implementation for each of the member functions in the “Files you must implement” section.
Grading You will be graded based on how your solution performs against the unit tests and how few memory leaks your program has.
You can earn a number of points on this project equal to the total number of unit tests present in UnitTest.cpp. You will lose 1 point for each unit test your program fails. You will lose 1 point for each unique memory leak your program exhibits. If your program fails to compile you will receive 0 points.
Recommended approach The best way to get started with the project is as follows: Look at the UML diagram to get an understanding of the various classes and how they relate to and depend on each other You should see that the following dependencies: o Coin depends on no other classes o Product depends on no other classes o DeliveryChute depends on Product and StatusPanel o ProductRack depends on DeliveryChute, Product, and StatusPanel o ProductButton depends on ProductRack o VendingMachine depends on pretty much everything else Start by coding the class that depends on the least other classes (either Coin or Product will do). Take the following steps: o Comment out all tests in UnitTest.cpp that are not related to the class you chose (e.g. if you chose to start with Coin then comment out all non-Coin tests). o Implement the class you chose until you can get all of the tests related to that class to pass. o Once you have all tests for this class passing you’re done with this class Next, move on to a class that depends on no other classes or only depends on classes you’ve already finished. Uncomment the tests for this class and follow the
CSE-40477 – C/C++ III, Intermediate Programming with Objects – Project #1
Page 5 of 5
process you did for the first class. Repeat this process until all tests pass for all classes. Lastly, make sure you don’t have any memory leaks. You can do this with a memory leak detection tool such as Valgrind for g++ or the built-in memory leak detection features in Visual Studio (see the comments I placed in main.cpp for a link explaining how to do this).
Turning in the project Submit a single zip file containing only the files listed under the “Files you must implement” section. I will not use any other files you send; I will be using my original versions of all other files. Note: You may submit your project early if you would like. I will let you know what grade your project would receive. You may then make corrections and resubmit. You may repeat this as many times as desired up until the due date.