[MSOE Homepage]

Dr. Taylor's MSOE Homepage

Courses

Unix is a Four
Letter Word

My Photo Album

My Personal Homepage

CS-182 Main page

CS-182 -- Lab 3 - Gas Mileage

Winter Quarter 1998-1999



Electrical Engineering and Computer Science Department
Dr. Christopher C. Taylor

S-331, 277-7339
t a y l o r@m s o e.e d u (remove spaces)
www.msoe.edu/~taylor/

Purpose

In this lab, you will write a C++ program that reads input from an input file, computes some statistics, and writes the results to an output file. In doing this lab assignment you should learn how to use selection statements effectively and read from and write to files. In addition, the assignment is designed to give you more experience with programming design and other basic operations in C++.

Assignment

In the summer of 1992 I purchased my first used car. I began with a full tank of gas and 40056.0 miles on the car. The file mileage.txt contains my records for gas purchases. The first few lines of the file are included below:

Date	 Odomtr 	Gallon	Price
 6/22	 40056.0	 0.000	 0.00
 7/ 8	 40459.2	10.003	10.69
 7/ 8    40814.4	 7.995	 9.75
 7/ 9	 41140.9	 7.274	 7.99

As suggested by the column headings, the first column indicates the date the purchase was made. The second column indicates the odometer reading at the time the car was filled. The third column indicates the number of gallons of gas purchased; and the forth column indicates the price paid for the gas.

Write a program that will read the data file, calculate a number of statistics, and display them on the screen. Your output should include the following statistics:

  • Total number of miles between car purchase and last gas purchase
  • Total amount of money spent on gas
  • Average miles per gas purchase
  • Average gas mileage

In addition, you should include any additional statistics required to answer the questions listed below.

  • In which season have I driven the most/least?
  • In which season did I get the best/worst gas mileage?
  • In which season is the price of gas highest/lowest?

Assume the following: Winter = {Dec, Jan, Feb}, Spring = {Mar, Apr, May}, Summer = {Jun, Jul, Aug}, Fall = {Sep, Oct, Nov}.

Programming consideration: It is always good in program design to consider potential modifications that may be required a some later date. Be sure to keep this in mind when designing your program.

Lab report

The lab report should be self-contained. That is, it should be possible for someone to understand what you did and why without seeing anything other than your report. Your report should include:

  • Purpose
  • Problem Statement
  • Procedure (include the steps in the Programmers Algorithm, reasons for your design decisions, etc.)
  • Documented source code (you may wish to include this at the end of your report)
  • Discussion (example program output, answers to questions, problems you encountered, etc.)
  • Conclusions (what you learned, suggestions of how the lab could have been better, things you would have done differently, etc.)

As with any report you submit, correct spelling and grammar are required. In addition, your report should be submitted electronically following the Electronic submission guidelines. (You may wish to consult the sample report before submitting your report.) Be sure to keep copies of all your files, in case something gets lost. It may be wise to keep a diskette backup as well.

The lab report is due at 4:00pm, Monday, Jan. 11, 1999, though you are encouraged to submit it sooner if you can. If you have any questions, consult the instructor.


This page was created by Dr. Christopher C. Taylor, copyright 1998.