COSC 071: Computer Science I

Project 1
Spring 2007

Written part due in class Thursday, Feb 8
Implementation due Feb 16 @ 5 PM
6 points

The good folks at Wisemiller's need some help producing the grocery list for their world-renown Chicken Madness. After years of producing the sandwiches, they generally know when demand is high (e.g., during homecoming) and low (e.g., during Spring Break). Additionally, the cost of the ingredients for the sandwiches changes throughout the year. For example, during the winter months, produce is more expensive.

Wisemiller's needs a C++ program that will let them enter the number of sandwiches they expect to produce and the price of the ingredients. The program should then calculate how much of each ingredient they'll need to order, the total cost of those ingredients, and their anticipated net sales, assuming that the sandwiches cost $5.95 each.

If you haven't had a Chicken Madness, each sandwich consists of a sub roll, chicken, bacon, onion, green pepper, lettuce, tomato, mayo, and spices (yummy!). Since they buy mayo and spices in bulk, these ingredients will not figure into the calculations. For a single sandwich, the cooks use a roll, one boneless breast of chicken, two slices of bacon, and two slices of cheese. They estimate that they use one onion for three sandwiches, one green pepper for two sandwiches, one head of lettuce for five sandwiches, and one tomato for four sandwiches. Wisemiller's food distributor sells sub rolls in eight-roll packages, chicken in boxes of twelve pieces, bacon in packages of twelve slices, and cheese in packages of forty-eight slices. Rather than buying their produce separately, the food distributor delivers a "produce pack" containing vegetables sufficient for making twenty sandwiches. Note that the price of bacon does not fluctuate and costs $3.99 per package.

(Naturally, you may have to do extensive research for this project. Therefore, any purchases of Chicken Madness should be tax deductable until the deadline. But that's something you can work out with your accountant.)

The written part of the assignment is to write a general algorithm expressed in our algorithmic language:

  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.

The implementation portion of the assignment involves implementing your algorithm as a C++ program. As a minimum requirement, 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, such as for the cost of sandwiches. 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 unknown quantities, such as the cost of chicken and the number of sandwiches to be produced. Known values, such as the cost of bacon, should be represented in the program as constants. After the user enters all the pertinent data, the program should produce a list of ingredients, the cost of those ingredients, gross sales, and net sales.

For example, if Wisemiller's wanted to make 51 sandwiches, the cost of a package of rolls is $0.69, the cost of chicken is $3.50, the cost of cheese is $3.50, and the cost of one produce pack is $1.69, then the program's execution should look like the following:

seva% a.out
Enter the number of sandwiches: 51
Enter the cost of rolls: .69
Enter the cost of chicken: 3.50
Enter the cost of cheese: 3.50
Enter the cost of produce pack: 1.69

Grocery List
7 packages of rolls
5 boxes of chicken
9 packages of bacon
3 packages of cheese
3 produce packs

Total cost: $73.81
Gross sales: $303.45
Net sales: $229.64
seva%

Regardless of whether you choose to code from your algorithm or write your C++ program on paper first, do not enter it all at once, as you might a term paper. We will talk more about stepwise refinement and incremental development in class, but you should always enter or write the program in manageable pieces. Start with an empty main function. Declare an object, use it in an input statement, output 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. On the other hand, if you start by entering your 300-line program all at once and compiling, you will be overwhelmed by the number of compiler errors. Even seasoned programmers don't do this.

Data Set Sandwiches Rolls Chicken Cheese Produce
1 51 $0.79 $6.39 $3.50 $1.69
2 200 $0.79 $6.39 $3.50 $1.69
3 120 $0.59 $6.79 $2.89 $1.89
4 160 $0.71 $6.59 $2.79 $1.89

Instructions for 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>
 * E-mail: <e-mail address>
 * Instructor: Maloof
 * TA: <TA's name>
 * COSC 071, Spring 2007
 *
 * 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.
 *
 * Description: <Describe your program>
 */

When you are ready to submit your program for grading, use the submit program. Both submit.jar and the file containing your program should be in the same directory. This assignment's label is p1. Assuming the file you want to submit is p1.cc, then to submit you enter the command

seva% java -jar submit.jar -a p1 -f p1.cc
Make sure you submit the file containing your program's source, not its executable code; that is, do not submit a.out.

Once you've submitted your project, it is a good idea to keep a copy on seva, which preserves the modification date and time and ensures that you will have a backup copy of your project. If we lose your project or submit 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 submit your project before 5 PM on the due date.

Plan B

The submit program is pretty reliable, but it is software. If it is three minutes before the deadline and the submit program breaks, here's Plan B. You are to mail your program to our grading account. The syntax for this command is
seva% mail -s "<netid>.cc" cosc071@cush < <filename>
Assume that I want to submit my file named p1.cc. Then I would type
seva% mail -s "maloofm.cc" cosc071@cush < p1.cc
This command sends mail with the subject "maloofm.cc" to our grading account (cosc071@cush). The body of the e-mail is the contents of the file p1.cc. Use Plan B only if you have made sure that submit is truly broken. Finally, don't send normal mail to this account because no one will be checking it regularly.