CS 135: Computer Science I
Spring 2008
Design, code, and test a C++ program that displays a restaurant menu, reads the customer's choices, displays the check (bill), and saves the check (bill) to a file. For this assignment, we will implement a simple menu that implements the two levels of choices shown in Figure 1.
Figure 1 shows that there are three top level choices.
Since restaurants keep changing their menu, we keep second level choices in text files. Assume that dish names are single words (we cannot yet handle multiword names). So:
Once you know what the customer has chosen, you calculate taxes
(
), tip (
), and then write the well formatted bill to
standard output and to a file called Receipt.txt.
Design your program such that it checks for incorrect input. Your program:
For this assignment, create and run at least six test cases and make sure that your program handles these situations. We provide four possible ways for the program to fail below. You can think up and test the rest.
Here is sample interaction with a running version of the program: Test1: Customer chooses correctly:
sushil@xpc:~/samba/classes/135/assignments/as6/code$ ./rmenu Welcome to Virtual Street Cafe --------------------------------------- We have three main categories 1. Appetizer 2. Main Entree 3. Dessert Please enter the number of the choice to indicate your selection. What would you like to have today? 1 Good Choice!! Here are the selections for Appetizer 1 crabcakes $15.99 2 bruschetta $9.95 3 rolls $8.95 Please choose one: 3 You have chosen rolls from Appetizer Your total is 8.95 Your tax is: 0.660062 Your tip is: 1.3425 Your total with tax and tip is 10.9526 Thank you for choosing Virtual Street Cafe. Your Receipt is available at Receipt.txt
Here's what Receipt.txt looks like:
You have chosen rolls from Appetizer
=====================
Price $ 8.95
Tip $ 1.34
Taxes $ 0.66
=====================
Total $ 10.95
Thank you for choosing Virtual Street Cafe
Test2: Customer makes an incorrect top level choice
sushil@xpc:~/samba/classes/135/assignments/as6/code$ ./rmenu Welcome to Virtual Street Cafe --------------------------------------- We have three main categories 1. Appetizer 2. Main Entree 3. Dessert Please enter the number of the choice to indicate your selection. What would you like to have today? 0 Sorry we do not offer that. Invalid selection......GoodBye
Test3: Another correct test case with main entree choice.
sushil@xpc:~/samba/classes/135/assignments/as6/code$ ./rmenu Welcome to Virtual Street Cafe --------------------------------------- We have three main categories 1. Appetizer 2. Main Entree 3. Dessert Please enter the number of the choice to indicate your selection. What would you like to have today? 2 Good Choice!! Here are the selections for Main Entree 1 steak $25.99 2 pasta $10.99 3 chicken $12.95 Please choose one: 1 You have chosen steak from Main Entree Your total is 25.99 Your tax is: 1.91676 Your tip is: 3.8985 Your total with tax and tip is 31.8053 Thank you for choosing Virtual Street Cafe. Your Receipt is available at Receipt.txt
Test4: Incorrect second level choice:
sushil@xpc:~/samba/classes/135/assignments/as6/code$ ./rmenu Welcome to Virtual Street Cafe --------------------------------------- We have three main categories 1. Appetizer 2. Main Entree 3. Dessert Please enter the number of the choice to indicate your selection. What would you like to have today? 3 Good Choice!! Here are the selections for Dessert 1 cheesecake $10.99 2 sundae $5.99 3 brownie $6.99 Please choose one: 5 You have chosen Something unknown from Dessert Sorry we do not offer that. Invalid selection......GoodBye
Test 5: Missing entree.txt information file:
sushil@xpc:~/samba/classes/135/assignments/as6/code$ ./rmenu Welcome to Virtual Street Cafe --------------------------------------- We have three main categories 1. Appetizer 2. Main Entree 3. Dessert Please enter the number of the choice to indicate your selection. What would you like to have today? 2 Good Choice!! Here are the selections for Main Entree Oops: There was an error in opening a file, GoodBye...
Turn in a Folder (Binder) containing:
Ask an instructor or TA if you have questions.
This document was generated using the LaTeX2HTML translator Version 2002-2-1 (1.71)
Copyright © 1993, 1994, 1995, 1996,
Nikos Drakos,
Computer Based Learning Unit, University of Leeds.
Copyright © 1997, 1998, 1999,
Ross Moore,
Mathematics Department, Macquarie University, Sydney.
The command line arguments were:
latex2html -split 1 as6S08
The translation was initiated by Sushil Louis on 2008-03-02