### COSC 071: Computer Science I

Project 1
Spring 2002

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

J. P. Henry, a notorious moonshiner, needs a computer program to help him plan production and compute the price of his moonshine. J. P. wants to enter how many quarts of moonshine he wants to produce and the cost of certain goods, and have the computer tell him how much of the ingredients is required and the selling price of his product.

J. P. has a 50 gallon still and distills twice with a 20% reduction in mash for each distillation. He wants to make 100% profit on each batch. J. P.'s moonshine recipe, which has been passed down through the generations, is as follows:

For 5 gallons of mash:

• 2 bushels of apples, the cost of which varies,
• Three 5 lb. bags of sugar (\$1.50 per bag),
• 5 pkgs. of yeast (\$1.25).
Now, J. P. is a little superstitious, so he always makes full recipes because that's what his daddy did and his daddy's daddy did. Each quart Mason jar costs J. P. \$2.75. Occasionally, J. P. has to give the local Sheriff protection money, and this amount varies. Finally, the program should alert J. P. if he tries to produce more mash than his still can hold.

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 five statements from HW2:

1. input
2. output
3. calculate
4. if condition, then statement
5. if condition, then statement; otherwise, statement
If you need to group multiple statements together, say in an if statement, use
begin
statement
...
statement
end
If you prefer, you may express your algorithm as a flowchart.

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

Avoid using literals in your program by declaring constants for values that do not change during program execution, like for the size of the still. 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 doubles using static_cast.

The program should prompt the user for unknowns, such as the cost of apples. Known values, such as the cost of sugar, should be represented in the program as constants. After the user enters all the pertinent data, the program should produce a list of ingredients and a suggested cost of each quart.

For example, if J. P. wanted to make 51 quarts of moonshine, apples cost \$3.25 a bushel, and he paid the local Sheriff \$100, then the program run should look like the following:

```gusun% a.out

Enter desired number of quarts: 51
Enter cost of apples per bushel: 3.25
Enter sheriff payoff: 100

Needed ingredients:
20 gallons of water,
8 bushels of apples,
12 bags of sugar,
20 packages of yeast.

Yield: 51 quarts
Suggested Quart Price: \$11.34
```
On the other hand, if J. P. tried to make 1000 quarts of moonshine, then the program should produce:
```gusun% a.out

Enter desired number of quarts: 1000

Gallons of mash exceed volume of still.
```

Run your program using the following four data sets:

 Data Set Desired Quarts Cost of Apples Sheriff Payoff 1 51 \$3.25 \$100 2 72 \$5.25 \$500 3 130 \$4.25 \$200 4 250 \$2.25 \$50

Hint: Once you've expressed your solution as a C++ program, don't just sit down and type it all in like a history paper. I'll talk more about stepwise refinement and incremental development in class, but enter the program in pieces. Start with an empty main function. Declare an object, use it in an input statement, print its value, then compile and run the program. If everything works as expected, declare another object, use it in an input statement, print its value, then compile and run the program. Continue in this fashion until you've entered your program. You should always have a program that compiles and executes. It may not do everything, but it will always compile and execute.

This approach minimizes errors and helps manage the complexity of software development. If you start each step with a working program and you add a few lines of code, if you make a mistake, then it mostly likely involves the last few lines you typed. If you start by entering your 300-line program and hit compile, you'll be overwhelmed by the number of compiler errors. Even seasoned programmers don't do this.

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
// Instructor: Maloof
// TA: <TA's name>
// COSC 071
//
// In accordance with the class policies and Georgetown's Honor Code,
// I certify that, with the exceptions of the lecture notes and those
// items noted below, I have neither given nor received any assistance
// on this project.
//
//
```

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, if necessary, use ws-FTP to transfer your source and data file from your PC to gusun. Use SSH to logon to gusun, and use pine to e-mail it to your TA. Use your netid and the suffix ``.cc'' as the subject.

```gusun% pine
```

When the menu appears, select the item for composing e-mail. Assume that your netid is ab123, the name of your source file is proj1.cpp, and your TA's e-mail address is ``imagoodtamaloof@cs''.

Type your TA's e-mail address in the To field, and type your netid with the .cc suffix in the Subject field (no spaces before or after). Move the cursor down into the MESSAGE TEXT screen, and type the ^R command. Pine will ask for a file name (e.g., proj1.cpp), which it will then load as your message text. At this point, your screen should look something like the following:

Finally, type ^X to send the e-mail to your TA.

IMPORTANT: Do not send your source code as an attachment. Do not use a mail client other than pine.

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.

The TAs who will be grading your projects this semester are listed on the main page. You must e-mail your project before 5 PM on the due date.