CS110 Introduction to Computer Science

Spring 2000

Programming Project #2

Due in class on Tuesday, February 15, 2000.

Write a C++ program to solve Exercise 2.16 (page 131) from Deitel & Deitel, which is restated here:

Drivers are concerned with the mileage obtained by their automobiles. One driver has kept track of several tankfuls of gasoline by recording miles driven and gallons used for each tankful. The program should calculate and display the miles per gallon obtained for each tankful. After processing all input information, the program should calculate and print the combined miles per gallon obtained for all tankfuls. Your program should have the interface shown below:

Enter the gallons used (-1 to end): 12.8
Enter the miles driven: 287
The miles/gallon for this tank was 22.42

Enter the gallons used (-1 to end): 10.3
Enter the miles driven: 200
The miles/gallon for this tank was 19.42

Enter the gallons used (-1 to end): 5
Enter the miles driven: 120
The miles/gallon for this tank was: 24.00

Enter the gallons used(-1 to end): -1

The overall average miles/gallon was 21.60

Extra Credit: In some countries, efficiency of automobiles is measured by listing the amount of gasoline required for going 100 miles (or kilometers). Enhance your program to print out, using the final average, the number of gallons required to go 100 miles. Do the same for the number of litres required to go 100 kilometers. (1 US Gallon = 3.89 Litres, 1 mile = 1.6 kilometers).

What to Hand in:

Hand in the following:

  1. A printout of your C++ program file.
  2. A printout of your project window (select the project window and choose Print from File menu to get this).
  3. At least two sample runs on different inputs. For one set, use the sample provided in the book.

Additionally, write a short paragraph/essay on your experiences in working on this assignment. Please staple all the pages together.


Each C++ program should have the following:

// Program Name: <The name of your C++ program file>
// Programmer: <Your name here>
// Address: <your e-mail and Campus Address here>
// Assignment Number: <put project number here, e.g. Project#1, Part A>
// Purpose: <A short problem description>


Back to CS110 Page