CISC105 Summer 2007, Project 1

Due Sunday, July 22

Pizza Parlor

Barry and his cousin Lem have decided to open a pizza parlor with their winnings from last month's lottery drawing. They've hired you to help out with some of their computer systems. They're not exactly computer savvy, so if some of their requests sound a little strange, just go along with it. They'll be paying you well until that lottery money runs out.

The project you've been assigned to has four parts. The first involves doing a few helpful calculations, since maths make Lem's head hurt something fierce, and Barry's generally busy perfecting the pizza sauce. The second involves keeping track of the inventory in the shop, so that they never run out of anchovies for their Supreme Surprise! Pizza (tm), and the third part of the project involves printing nicely formatted receipts for the customers, since receipts in crayon just look unprofessional. The last part of the project involves putting everything together in a nice menu-based system.

NOTE: Depending on how much work this is shaping up to be, part 3 may or may not be included in this project. I will decide whether or not to include it, so you don't need to express to me your preference. I will let you know if the status changes, but currently, part 3 is: NOT INCLUDED. That means you don't have to do part 3. Just parts 1 and 2, and then the menu (part 4).

Approach

The first three parts to this project are independent, and should be treated as such. You should have a different file for each part (project1.1.c, project1.2.c, etc). The final part (project1.4.c) should contain all of the previous files, plus the code for the menu.

Remember how we approach problems in class. Given some specific task, before you enter a line of code, figure out how you're going to accomplish it. Start with high-level english, and refine your algorithm until you feel you know what most of the code should be already. Then, start adding code, testing after every few lines to make sure that there are no mistakes. It may seem like it takes longer to test every few lines, but believe me, the project will go more quickly if you do so. Spending a few extra seconds testing after every change may take some time, but this amount of time pales in comparison with the amount you'll spend trying to find that one error in the 50 lines of code you just wrote.

A good approach to programming projects like this, borrowed from T. Harvey:

Part 1 -- Calculations (project1.1.c)

There are two tasks in this section.

  1. Write code to calculate the cost per square foot of a pizza. The user should input the diameter of the pizza and the price of the pizza, the code should then output a nice message with the price per square foot of the pizza. Divide this into two parts: the user input/output should be in a function, and the actual calculations should be in another function. Remember, the "calculation" function should not print anything out. Also, notice that the parameter for the calculation function and the user input are not precisely the same--you'll have to do some slight conversions.
    1. Calculation function: takes double radius (in inches) and the double cost as parameters, and returns the double price per square foot. Use the formula:
      areapizza = pi * radius2
      Write this function first.
    2. Input/Output function: takes no parameters and has type void. This function asks the user for the needed information (diameter and cost), then uses the calculation function to get the price per square foot. The function should then print it out, with a nice message.
  2. Write code to calculate the menu cost of a slice of pizza. Barry and Lem have started selling by the slice, with a slight markup. The formula they use is this:
    priceslice = ( pricepizza / slices_per_pizza ) * (1 + markup_percentage)
    So, for example, for a $10 pizza with 10 slices, if Barry and Lem applied a 20% markup,
    priceslice = ( 10 / 10 ) * (1 + .2) = 1 * 1.2 = $1.20 per slice
    Divide this problem up just like the first one, with a user I/O function and a calculation function.
  3. One last part--add a menu that allows you to select which calculation you want to perform. Make sure that if the user enters an invalid number that the program gives him/her a chance to try again.
Once you have finished this section, make sure it is saved as project1.1.c. For the next section, start a new file--project1.2.c.

Part 2--Inventory (project1.2.c)

In this part, you will employ parallel arrays to keep track of an inventory system. You are tracking three things for each item: an itemID, the cost, and the supply on hand.

Sample Inventory
itemIDcostsupply Array Index
1$3.2550 [0]
2$10.990 [1]
15$0.9915 [2]
9$.25999 [3]
11$5.45100 [4]
100 $9.9944 [5]
8$5.0030 [6]
7$4.4930 [7]

So you will have 3 arrays, itemID[], cost[] and supply[]. A single item is represented by the contents of these three arrays at a single index. For example, the item with itemID 2 has a cost of $10.99, a supply of 0, and this information can be found at index 1 of each array. Keep in mind you won't have an "array index" array or anything like that--that column is just there for illustration.

Assume the following about the inventory:

    Detailed steps for part 2:


  1. Declare 3 arrays in main(), as specified above. The first will hold ID numbers, the second will hold prices, the third supply. Remember: All of the information for an item will be in the same index position of every array. itemID[0] contains 1, price[0] contains $3.25, and supply[0] contains 50.

    Initialize each array to the example values shown above. Note that the arrays will not be full--it has 50 slots, but you will only be using 8 of them. You will need to keep track of the number of items that are currently stored in the inventory, so that you can use loops to interact with the arrays. Create a variable numItems that stores the number of items that are currently in the inventory.

    Test that your arrays hold the correct values by looping through them, printing out each value. Once you are satisfied that everything is working fine, move your testing code into a function that will print the values.

    void printArrayContents( ... )
    This function should take as parameters the array and the number of valid items in the array. It should then walk through the array, printing the values to the screen. Since we have two different types of arrays (int and double), however, we will need two functions for this printing.
    void printArrayContentsInt( int ... )
    void printArrayContentsDouble( double ... )
  2. Next, you will write a series of functions that allow you to access information in the inventory. First is a function that you will use in most of the other functions that you write. It sounds kind of backwards at first, so read carefully. Write a function:

    int getIndexFromID( ... )
    That takes as parameters the itemID[] array, the number of valid items in the array (numItems), and finally an integer idNumber to search for. The function should look through the array, find the idNumber within the itemID array, and then return the index of the idNumber. If the idNumber is not found in the array, the function should return a defined sentinel value (-1, perhaps), which lets the caller know that the item could not be found. Remember: you should not be looking through all 50 elements of the array. Only the first 8 are initialized in the beginning--the rest are garbage. This is why you have the numItems passed in as a parameter. Test this function thoroughly before moving on, it is very important.

    Once you have getIndexFromID written, you will use this function to write a few more. Write two functions:

    double getCostFromID( ... )
    int getSupplyFromID( ... )
    These functions will have to take four parameters each. Can you think of what information these functions need? They will be calling the getIndexFromID function in order to get the index needed for accessing their respective arrays (cost and supply), so remember that any information needed for calling the getIndexFromID function must also be passed into the getCost and getSupply functions.

    These functions should not print anything. They should return their result so that it may be used elsewhere.

  3. You've accumulated a few functions now, so it's a good time to organize things a bit. Add a menu to main, which allows the user to call any of the functions that you have written thus far. Before calling, the program should ask the user for any input necessary (the id number to search for, for example).

    You should use a do-while loop and a switch statement for your menu. To get the user input specific to functions, you may either include the I/O in your case clauses of the switch statement, or you may write a new function that does the input/output for each menu option. It's up to you.

    Start by adding one option to the menu, and then test it out. See how you think is best to organize it, decide on a method, then add the rest of the options, testing between each.

    The menu should continue to present the user with options until the user enters a value of -1 to quit.

    Lastly, add a single new function (and then add it to the menu):

    void printInventoryTable( ... )
    This function should print a nice table of the current inventory. It should be nicely aligned and the numbers should have appropriate precision.

  4. This section deals with functions that update the inventory. There are four parts: adding an item to the inventory, deleting an item from the inventory, the pizza parlor selling an item, and the pizza parlor resupplying an item into inventory.

    These functions will be described in less detail than the preceding ones. They will take more thought, so be sure to think very carefully before you start coding. Add these functions to your menu (or better yet, make a submenu with this set of functions) as you finish them. Lastly, be sure that you use the functions you wrote for part2.2 to access information. You should not be rewriting any of that code in new functions. Review the functions that you have on hand, and think of how you can use them to solve these problems.

    1. Adding an item to the inventory. The user should be asked for input. Input/output and the actual adding should occur in different functions. A new item is added, so remember to update the count/sentinel and make sure that all arrays are updated. See addStudent from grades.c for inspiration.
    2. Deleting an item from the inventory. Read this one carefully--you may want to do it last in this section. The user should specify an ID# to be deleted, and this item should be removed from all arrays. What needs to happen to the arrays when that item is removed? There can't be a slot in the array that you just skip, so some of the other items may need to shift.
    3. Selling an item. The user should specify which item he/she wants, and then the amount. The program should report back the cost to the user the final cost of the products sold. Keep in mind that Barry and Lem can't sell more than they have on hand, so you will need to do some error checking and give the user another chance if they enter an invalid amount. And once these items are sold, well, Barry and Lem have less of that item than they once did.
    4. Resupplying an item. Barry and Lem need more cheese (or item #21, whichever). The user should specify which item, and how much of it. Supply will need to be updated.

Part 3--Printing Receipts to a file

Currently NOT Included in this assignment.

Part 4--Adding a menu to control everything

To finish the project, add a main menu that includes options for all of the previous features you have added. Since you likely have menus already written for the other parts of the project, this menu can be simple--it need only give the user the ability to call the other menu functions. The main idea is that it should allow the user to access all of the features in a quick and easy fashion. The menu should be straightforward and easy to understand and read.

Once the menu is in place, add a loop that will continue to allow the user to choose options until they ask to quit. Input that is not valid (only numbers that do not correspond to menu options, don't worry about the user entering characters) should be dealt with gracefully.

That's it

You will recieve instructions for scripting and submitting your project at least a day before the project is due. The instructions will lead you through a series of tests to perform, so that submissions are complete as well as somewhat easier to grade.




Thanks to T. Harvey for inspiration for a good portion of this project.