COSC 071: Computer Science I

Project 1: Woody Woodchuck Grocery List Calculator
Spring 2000

Algorithm (written) due: Feb 7 @ 5 PM (my mailbox)
Implementation (electronic) due: Feb 11 @ 5 PM
5 points

The Woody Woodchuck Explorer Scouts plan a lot of camping trips, and they always eat the same thing. Since you are their counselor for their Computers merit badge, they've asked you to write a program that will help them compile their grocery list and figure the cost to each scout and adult.

Each scout is allotted two hot dogs, 8 ounces of potato chips, and 24 ounces of coke. Each adult is allotted three hot dogs, 16 ounces of potato chips, and they bring their own beverage, if ya' know what I mean.

They can buy a five pound bag of chips for $3.49, and a two liter bottle of coke (or soda or pop) for 2.49.

What varies is the cost of the hot dogs and the buns. They may decide to get tofu dogs, or they may decide to get potato buns, so your program needs to prompt the user for these prices.

Hot dogs come ten to a pack, and buns come eight to a pack, which is still one of the great mysteries of our time. The number of scouts and the number of adults also varies, so you should provide input statements for these quantities also.

Your program should, based on the input, calculate the number of bottles of coke and the number of packages of buns, hot dogs, and chips. It should compute the total cost, with tax. Assume a tax rate of 7.4%. And finally, your program should compute the cost for each scout and adult. If the cost for each scout is more than three dollars, then the portion over three dollars is distributed among the adults.

The written portion of this assignment consists of two parts. First, solve the problem using the first data set below. Second, based on this solution, develop an algorithm, the general solution, using the four basic operations INPUT, CALCULATE, DECISION, and OUTPUT, as in homeworks 1 and 2. If you prefer, you may express your algorithm as a flowchart.

Naturally, the implementation portion of the assignment involves expressing your algorithm as a C++ program. Make sure it works for the three data sets below.

Avoid using literals in your program by declaring constants for values that do not change during program execution, like for the tax rate. Declare all constants and variables at the top of the main function. Use static casting to convert between ints and floats.

Data Set Adults Scouts Cost of Hot Dogs Cost of Buns
1 2 10 3.25 0.89
2 3 15 2.49 1.25
3 5 30 1.89 0.69

A sample run appears below with the user's input in bold:

gusun% a.out

Enter number of adults: 4
Enter number of scouts: 10
Enter cost of buns per package: 1.89
Enter cost of hot dogs per package: 4.25

Needed groceries:
   4 packages of hot dog buns
   4 packages of hot dogs
   2 packages of potato chips
   4 2-liter bottles of coke

Cost of Groceries: $41.50
Tax: $3.07

Total Cost: $44.57

Cost per Adult: $3.64
Cost per Scout: $3.00

Instructions for Electronic Submission: At the top of the file containing your source code (i.e., the file containing the C++ instructions), place the following header comment, with the appropriate modifications:

//
// Project 1
// Name: <your name>
// SID: <last four digits of student ID>
// E-mail: <e-mail address>
// Instructor: Maloof
// TA: <TA's name>
// COSC 071-<section number>
//
// Description: <Describe your program>
//

All programs must run under UNIX and must compile using GNU g++. When you are ready to submit your program for grading, e-mail it to your TA using the last four digits of your student ID and the suffix ``.cc'' as the subject line.

For example, if the last four digits of your student ID is 1234, the name of your source file is proj1.cc, and your TA's e-mail address is ``imagoodta@georgetown.edu'', then you would type at the UNIX prompt:

gusun% mailx -s "1234.cc" imagoodta@georgetown.edu < proj1.cc
You are executing the mailx command. The -s option indicates that the string "1234.cc" is the subject heading. imgagoodta@georgetown.edu is the address to which the mail will be sent. The part ``< proj1.cc'' takes your source file and directs it into the mailx command.

You can also use pine to submit your project. After filling in the To and Subject fields, type the ^R command in the MESSAGE TEXT screen. Pine will ask for a file name, which it will then load as your message text. Type ^X to send the e-mail.

You must submit your project by e-mail before 5:00 P.M. on the due date. Late projects will be subject to a penalty.

If you need to include a message to you TA about your submission, then type the message as a comment in the program.

Once you've submitted your project, it is important to keep an electronic copy on a university machine (e.g., gusun or cssun) that preserves the modification date and time. If we lose your project or the e-mail system breaks, then we will need to look at the modification date and time of your project to ensure that you submitted it before it was due.