COSC 071-02: Computer Science I

Project 1: Hoya Kids Refreshments Calculator
Spring 2001

Specific solution and algorithm (written) due: Feb 12 in class
C++ Implementation (electronic) due: Feb 16 @ 4 PM
5 points

The good folks over at Hoya Kids need a program to help them better plan refreshment purchasing, and they've asked you---oh yes, you---to write a program to calculate how much cookies and Kool-aid to buy at Wisemiller's. Unfortunately, the little tykes will have to wait a few years before they can experience Chicken Madness.

Each morning, after determining how many adults and children will be present for refreshments, the staff assemble a grocery list, estimate the total cost of the groceries, and walk down to Wisemiller's to buy the treats. Each child gets two cookies and 8 oz. of Kool-aid. Adults, both staff and visiting parents, get three cookies and 16 oz. of Kool-aid. Each person also gets one-third of a banana.

One gallon of Kool-aid costs $2.25. Naturally, they buy bananas by the pound, the price of which fluctuates on the global marketplace, but you probably covered that in your econ class. Bananas weigh, on average, one-fourth of a pound. In terms of cookies, the staff buy either Oreos or peanut-butter wafers, depending on which choice will minimize the number of leftover cookies. Oreos come 48 cookies to a box and cost $4.25. Peanut butter wafers come 36 to a box and cost $3.60.

Your program should take as input the number of children and adults partaking in refreshments. The user will also provide the current price of bananas. Based on these inputs, your program should calculate the number of bananas, the number of gallons of Kool-aid, and the kind and number of packages of cookies. It should compute the cost of the groceries, the tax, and then the total cost. The tax rate for snack items in DC is 10.0%. All of this information should be printed to the screen, as shown below in the sample run.

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. Store quantities using the appropriate data type, and if needed, convert between ints and floats using either static casting or some other type conversion method.

Data Set Children Adults Cost of Bananas (lb)
1 30 5 1.99
2 44 4 2.49
3 60 10 1.89

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

gusun% a.out

Hoya Kids Refreshment Calculator

Enter the number of children: 30   
Enter the number of adults: 5
Enter the cost of bananas per pound: 1.99

Hoya Kids Shopping List

   12 bananas
    3 gallons of Kool-aid
    2 pkgs of Oreos

Cost of groceries: $21.22
              Tax: $ 2.12
       Total cost: $23.34

gusun%

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

Although you may use any C++ compiler to develop your program, it 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 4: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.