CSE 142 Homework 1

Due Sunday, July 2nd, 10:00 PM
Paper turn in Monday, July 3rd, 5:00 PM


Seeing the success of so many gaming companies, you've decided to jump on the game bandwagon, and have started your own game company, HAPPYhappyGAMEgames. HHGG sells both an HX PowerCast 65 Game Console as well as numerous games, including Ultra Chess Fighter, and Nim - The Power Returns.

Overview

As the newly hired head software engineer at HHGG, you will be implementing different programs to help the company succeed. Your first assignment is to use what you've learned about variables, types, assignments, expressions and conditionals to manage HHGG's inventory. Read the entire assignment carefully and thoroughly. Pay close attention to the specifications below, as that details what your program must do.

Quick Overview

Specifications

This is a simple program to manage the Console and Game Inventory of HHGG. HHGG's main products are Consoles and Games. However, to save on shipping costs, HHGG also sells Packages and Gamepaks. Packages contain 1 console and 2 games. Gamepaks contain 5 games. The costs of the items are:

Console$99.99
Game $29.99
Package$114.99
Gamepak$119.99

HHGG has an initial inventory of 40 consoles and 100 games.

Your program should take the following as input:

Once you've read in the order, you must calculate the shipping costs and remaining inventory. As HHGG prides itself on great customer service, you will offer your clients the best deal possible.

Your program should calculate the following:

Your program must detect two types of errors.

  1. If more consoles or games were ordered than the number currently in stock, you should output a message saying that the order cannot be fufilled.
  2. If more packages were ordered than can be formed from the games and consoles ordered, your program should output a messages saying that too many packages were ordered

Otherwise, if no errors occured your program should output the following:

See the following page for sample executions.

Suggestions and Hints

Part of the grade for every assignment will be based on proper progamming style which will be discussed further before the assignment is due. However, two things that you will certainly use are comments and constants.

In C, comments are started with /* and closed with */ and can be placed anywhere in the program. Everything between these symbols is not considered part of the program and is ignored by the compiler. You will notice the use of comments in the starter code provided, as well as in the hw0 source. Here's an example:

double total_cost; /* the total cost of all items */

Constants are created at the very top of the program, after any #include lines. A constant is created by: #define CONSTANT value. For example, a program might start like :

#include <stdio.h>
#define PI 3.1415

You should use both constants and comments to make your program more readable and more modular (meaning -- easier to modify).

Lastly, you should consider using the % operator (modulus) to make certain calculations easier.

Sample Executable

Download and run the sample PC executable hw1.exe. Run it several times with different inputs until you get the general idea of what you're going to be writing. One technique for running it is to double-click on it from Windows Explorer.

See some sample runs of the program.

To make sure you understand the calculations, work some simple cases by hand (or with a pocket calculator or spreadsheet) and see if they match the sample program.

If you play with the sample executable very long, you'll notice that it doesn't handle errors very well. For example, inputting a negative number for the number of packages doesn't make much sense. Don't worry about these problems for now. Later in the course, you'll see how you could detect and handle these errors, but for this assignment you should just assume that the user will supply only valid and sensible input.

Getting Started

Altough you could write the program entirely from scratch based on the above Specification, we've provided a workspace and starter code to help you on your way. Download the self-extracting archive. (MSVC 5.0 here) If you are not using Windows, or this doesn't work for you, you can download the starter code by itself.

Once you've added some code to your program, you may find that it doesn't compile right away. Each of these compilation or "syntax" errors has to be solved. Notice that if you click on the error message, you will be placed in the editing window at a point near where the error was detected (often the actual error is a little earlier). Each time you make a change to the program, don't forget to recompile it before executing again.

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

Use the turnin page.

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.

When your work is saved, you should hand it in. This will always be done on the web in this course, so you should be sure that you know how it works. Go to the turnin page. Fill out the form (click on the words "help" if you don't understand something). At the bottom of the form, you will need to specify the name of your file. Use the Browse button. 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. Read carefully through the receipt in case there are error messages or other important information. If everything looks good, print out and turn in this receipt. You will hand in this receipt in class on the date given above.