CSE/ENGR 142 Homework 3

Detailed Instructions

Due: web submission by Friday, July 16th at 5:00 p.m. sharp, paper receipt submission by 10:00 p.m.


The pizza program you wrote last week was a huge hit. Your showed it to your friends, and they were so impressed that they want to use it when they order pizza. However they want it to be a bit more flexible; some of them want to order more than one pizza, some want to order more toppings, and some want it to handle drink orders. Oddly enough, all of your friends are given $30 from their parents for pizza, so they also want you to change the amount you can spend from $20 to $30. You just learned about loops and functions, so you confidently tell your friends that you can handle all of their requests. Your task for this assignment is to do just that.


Overview

In this homework, you'll be using more complex functions and loops. You'll have plenty of help along the way, including a sample executable you can run to see how the finished product should work. Read all of the information on this page before starting. Pay particular attention to the specifications below, and, when you think you're done, be sure to double-check them before you submit your code.

Program Specifications

This program is an extension of your original pizza program. This means that you can re-use some of the code from the original program. However the structure of this program is quite different from the first, so you might want to start from our skeleton instead of your program, then cut and paste any code you will re-use. The new program will handle the following things above and beyond the original:

These will be done through the use of loops. Which type of loop you use is up to you, although it will be good practice to try out both for and while loops. Additionally, your program will use multiple functions. You will write functions for:

We've written the skeletons for functions to handle choosing the pizza size (getPizzaSize), ordering the toppings (getToppings), and checking the order's price (checkPrice). Pay attention to the declarations of these functions and their comments -- getPizzaSize and getToppings are both used to add money to the total price of the order, but they do so in different manners (getPizzaSize returns the price of the pizza size alone, while getToppings returns the total cost of the order plus the toppings price). You'll also get a chance to flex your function muscles by writing a function from scratch for ordering drinks.

You'll notice that these functions do a lot of the work that we had done in main() last time. Using these functions, we can simplify main() quite a bit. Instead of having a long string of code that does many different calculations, main() will simply consist of a few function calls. This makes main() a lot easier to read, and each part of the program easier to debug. Using lots of functions is very good style, and they'll be heavily utilized in this course.

Implementation Requirements

For the most part, you are free to implement your program as you wish.  However, there are several specific requirements that must be met.

Pizza Size Topping Prices Drink Prices
Small $13.00 Extra Cheese $0.75 Soda $1.00
Medium $14.50 Pepperoni $1.50 Italian Soda $2.00
Large $16.00 Olives $1.50 Milkshake $3.00
Anchovies $2.00

Now you see why #defines are useful -- if you #defined each of the numbers above, then all you have to do is change each variable once. If you didn't use #defines, then you're going to have to hunt through your program for every instance of every variable and change it there. What a pain!

You are free to use additional functions if appropriate.  If you find that you are writing the same code over and over, that might suggest creating a function and calling it as needed.  But you are only required to implement the four functions described above.

Sample Executable

Download and run the sample PC executable hw3.exe and run it several times with different inputs until you get the general idea of how it works. One technique for running it is to double-click on it from Windows Explorer.

Getting Started

It would be possible to type in your program from scratch. In that case, you would unfortunately have to go through some additional steps to create a project and a workspace.  To make it easier, just modify hw3.c, the source file provided in the self-extracting archive (get the version 6 archive if you are using MSVC 6.0, or the version 5 archive if using MSVC 5.x).  Just as in the last homework, download the archive to a floppy disk. Once you have extracted the files, run MSVC from the Start menu and open the file hw3.dsw using the File menu's Open Workspace... option. Use the MSVC editor to modify hw3.c. Be sure to re-save hw3.c on your floppy, because you will need it later.   You can also get the file hw3.c by itself but in this case you will have to build a project and a workspace to compile it in.

You will find that the best way to proceed is not to type in the entire program at once and then try to compile. A better way would be to break the problem up into smaller parts, getting each part to build and work properly before moving on to the next.

IMPORTANT NOTE: This work must be entirely your own. If you are in doubt about what is and is not acceptable, please re-read the relevant section from the syllabus .
 

Submitting Your Work

Just as in the previous homeworks, you will be submitting your C file via the web and submitting your receipt on paper.

After you're finished testing your program and rereading the instructions, go to the turn-in page to submit your C file. Fill out the form (click on the links labeled "help" if you don't understand something). At the bottom of the form, you will need to specify the name of your file, which is probably named something like A:\hw3.c, but you can use the Browse button to find it if you like. Click the turn in button at the bottom when you're done. Your program will be checked to be sure that it compiles. If all is well, you'll get a receipt back showing what we received. Print out and hand in this receipt at the CSE 142 Homework Turn-In Box. You won't get credit for the assignment if you don't turn in this receipt.

You may turn in the program as many times as you wish.  Only the last version is graded, and only the receipt from this last version should be handed in.


Back to main Homework 3 page...