CS 157 Spring 2003                     Assignment 3 – Some Basic Calculations                                     100 points

 

Assigned: 01/29/2003

Due: 02/05/2003 (at the start of class – as will be the normal case)

 

Pre-Lab (Do Before Lab):  Bring an empty (or nearly empty) disk. Plan out sequence of statements needed for program.

 

Main Assignment:

 

We are writing a program to help a driver keep track of their car expenses, focusing on gas costs.  Your program will interact with the user, asking for the number of gallons of gas purchased, the price per gallon paid for the gas, the odometer reading when the tank was full, and the odometer reading when refilling the tank.  For your variable types, choose the type that fits the possible values. Your program calculate the miles per gallon, and the cost per mile driven, and will print a report showing all basic information including the calculated information; see the example below. To keep your job simple for this early in the class, we will assume that the order-entry typists are infallible.

Put your name, e-mail address, and date in comments near the top (e.g.  /* Your Name */).  You will need the Keyboard file (still obtainable from my WWW page  - or from last week). 

Compile the program and remove any errors. Ensure that the program runs correctly. It should run on any inputs (that shouldn’t be much of a problem with this straightforward a program).

               To avoid needless long waits, I recommend doing this on the c: drive, then upon completion, copying it to the a: drive, testing it there, creating an extra backup for yourself, then deleting it from the c: drive.

 

 

Sample Interaction:

 

What is the odometer at the start of the trip?

79504

What is the odometer at the end of the trip?

79759

How many gallons of gas were purchased?

10.5

What price (per gallon) was paid for the gas?

1.369

Results:

      Start Reading:        79504

      End Reading:          79759

      Miles Traveled:         255

      Price:                    1.369

      Gallons:                 10.5

      Total Amount Paid:       14.37

      Miles Per Gallon:        24.3

      Cost Per Mile:            0.06

 

Hand in: