Asgn 3 for CS246 DRAFT 25 Jan 2010
BACKGROUND. A new coffee shop called Fred Morton’s Coffee has opened. Fred has hired you to write a C++ program that allows people to order cups of coffee of various sizes and with varying amounts of cream and sugar. Each cup size has a particular price. Each “add-in” (such as cream and sugar) costs extra. So, each shot of cream in a coffee also costs extra as does each spoonful of sugar.
Fred wants to be able to quickly change the amounts he charges. He also wants to easily change the names and ranges of the sizes. He’s thinking if he changes a name from, say, Large, to say, Giganto, he can charge more for the same coffee. He’s also thinking of changing the name of Cream to Creme or to O-Lait and maybe experimenting with new add-ins such as Vanilla or Licorice or HyperJolt.
Fred himself has programmed a pair of “config” files, named
coffee-config.h
coffee-config.cpp
that determine things such as the ranges of cup sizes, their names and costs, the range and cost of add-ins etc. (These two files will be given to you and you are not to change them.) Your program should use his config files so when he changes his mind about ranges, names, etc, he generally only needs to change his files (and re-compile) without looking at your part of the program.
Here is an example session. A customer is interacting with the C++ program to order a cup of coffee.
Fred
Morton's Coffee: Can I help who's next?
Do
you want coffee? ( a=Yes b=No ) a
You've come to the right place.
What
size of cup? ( a=Small b=Medium c=Large d=XLarge ) b
Medium
Add
what to it? ( a=Cream b=Sugar c=Nothing ) b
Sugar
Add
what to it? ( a=Cream b=Sugar c=Nothing ) b
Sugar
Add
what to it? ( a=Cream b=Sugar c=Nothing ) a
Cream
Add
what to it? ( a=Cream b=Sugar c=Nothing ) c
Nothing
You
have ordered Medium coffee with 1 Cream 2 Sugar
Please
pay $1.27
Thank
you for visiting our coffee shop.
In this example, the customer has ordered a Medium cup of coffee with double sugar and single cream. The single letters, namely a, b and c were typed by the customer, and the rest was output by the program. Add-in’s such a cream and sugar can be ordered by the customer in any order and any amount. The current prices of the sizes of cups and the add-in’s are given in Fred’s config files.
If at any point, the customer types an expected input, say character x, the program prints the following and halts.
Sorry,
bad choice 'x'. Bye.
For example if for the first question (Do you want coffee?)
the customer types letter b (or
anything but a), he/she gets such a
message and the program halts Or, if
he/she requests a size by typing an inappropriate letter such as q, again such a message is output and
the program halts.
PART 3a. Write a C++ program that does no input, but uses Fred’s 2 config files to print out the following:
Fred
Morton's formidable coffee shop.
Great
sizes, 4 of them:
Small ($1.00) Medium ($1.05) Large ($1.10)
XLarge ($1.20)
Great
add-ins, 2 of them:
Cream ($0.10) Sugar ($0.06)
Terms such as “Cream” and “Medium" and the number of sizes and add-ins should be determined by Fred’s config files, and your program should automatically adjust to changes in the config files. Your main program should be in file
coffee-ad.cpp
and your executable should be called coffee-ad
Don’t forget to use
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision (2);
You should be able to compile your coffee-ad program using
g++ -c
coffee-config.cpp
g++ coffee-config.o
coffee-ad.cpp –o coffee-ad
PART 3b. Write a C++ program that handles customers as described in the above Background section.
FILES. Your C++ source code for Part 3b is to be made up the following files and no other files.
coffee-check.cpp coffee-check.h These two files contain a single function
(and no data). They are used by the main
program (coffee-shop.cpp) to check to see if a given customer input (a character) is within a given range (such
as ‘a’ to ‘c’). If not, the function
prints a mesage (“Sorry ...”) and aborts the program. The function does no writing, except for
abort messages.
coffee-config.cpp coffee-config.h These two files contain configuration
information (ranges of input from the customer as well as names of menu items (“Small”,
“Large”, “Cream” etc). These files have
no functions and they do no I/O. These
two files are given to you.
coffee-order.cpp coffee-order.h These
files are essentially an “object” which contains (encapsulates) the information
recorded about a coffee order (size and add-ins). This information is not visible to other
files. These files do no reading, and
write only to report an order or to report the cost of an order for coffee
(with add-ins).
coffee-shop.cpp This is the main program. It does most of the interaction with the
customer (except for printing abort messages and except for reporting orders
and cost to the customer).
Your executable code should be in a file called coffee-shop
INCLUDE FILES. For part 3b, your source program should have exactly these “include” directives (plus includes for system files such as iostream).:
coffee-check.cpp:#include
"coffee-check.h"
coffee-config.cpp:#include
"coffee-config.h"
coffee-order.cpp:#include
"coffee-order.h"
coffee-order.cpp:#include
"coffee-config.h"
coffee-shop.cpp:#include
"coffee-config.h"
coffee-shop.cpp:#include
"coffee-check.h"
coffee-shop.cpp:#include
"coffee-order.h"
In each of your header .h files, use #ifdef to allow for the possibility of multiple includes of the file.
MAKE FILE. You will be given a
“makefile” file to build your program.
You should not change it. Write
your program so it can be built by this make file. Under Linux, use gmake and not make. (‘make’
will not work with the makefile.)
CONFIGURATION CHANGES. Your programs (for both parts 3a and 3b) should continue to work when the two config files are updated (in reasonable ways).
WORKING SOLUTION. You will be given a working (compiled) solution. You should write tests to convince yourself that your program for 3b and the given solution produce exactly the same results, character by character.