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).
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:
There are two tasks in this section.
areapizza = pi * radius2Write this function first.
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 sliceDivide this problem up just like the first one, with a user I/O function and a calculation function.
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.
itemID | cost | supply | Array Index | |
---|---|---|---|---|
1 | $3.25 | 50 | [0] | |
2 | $10.99 | 0 | [1] | |
15 | $0.99 | 15 | [2] | |
9 | $.25 | 999 | [3] | |
11 | $5.45 | 100 | [4] | |
100 | $9.99 | 44 | [5] | |
8 | $5.00 | 30 | [6] | |
7 | $4.49 | 30 | [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:
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 ... )
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.
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.
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.
Currently NOT Included in this assignment.
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.
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.