next_inactive up previous


Assignment 6

CS 135: Computer Science I

Spring 2008

Objectives

  1. Learn and demonstrate use of file I/O in C/C++
  2. Learn and demonstrate use of the switch and if else statements in C/C++
  3. Learn and demonstrate use of relational operators in C/C++
  4. Learn and demonstrate prototyping, defining, and calling value returning functions.

Restaurant Menu and Billing Application (20 points)

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: A tree view of your restaurant menu.
\includegraphics[height=5.0in,width=4.0in]{figs/menuTree.eps}

Figure 1 shows that there are three top level choices.

  1. Appetizer
  2. Entree
  3. Dessert
For each of these top level choices, there are three further choices. So, for example, if the customer chooses Dessert, they will be presented with a choice of
  1. Cake
  2. Fruit
  3. Brownie

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:

Your program will therefore have to read these second level choices (item and price) from the appropriate files and display the items and their prices to the customer.

Once you know what the customer has chosen, you calculate taxes ($7.375\%$), tip ($15\%$), 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:

  1. Should check for invalid choices
  2. Should check for file I/O errors
  3. Should close the file stream after you are done reading or writing

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.

  1. Incorrect selection at the top level
  2. Incorrect selection at the second level
  3. File does not exist
  4. Three correct test cases, one for each top level selection

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...

Handing it in

Turn in a Folder (Binder) containing:

  1. Cover sheet with
    1. Assignment Number
    2. Section Number
    3. Your name
    4. Your email
    5. Your TA's name
  2. Source code (.cpp) file (s) on a CD/USB stick with your name and section number written on your CD/USB stick.
  3. Executables for all parts of the assignment on the CD/USB stick.

  4. Three input files that you make up
  5. Output files for all error-free test cases
  6. Hardcopy of your source code (printout)
  7. Screen captures of your program running

Ask an instructor or TA if you have questions.

About this document ...

Assignment 6

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


next_inactive up previous
Sushil Louis 2008-03-02