Write a program that helps a person decide on whether to buy a hybrid car.


thumb You should ask the user for input. Your program's inputs should be

  • The cost of a new car
  • The estimated miles driven per year
  • The estimated price of a gallon of gas
  • The efficiency of the new car in miles per gallon
  • The estimated resale value after 5 years

Your program's output should be

  • the total cost of fuel for 5 years
  • the total cost of owning the car for 5 years (fuel + depreciation in car value)

You can then run your program with the cost, gas mileage, and resale value for a normal car and a hybrid car and determine which is less expensive.

Think before programming

Before you can write code, you will need to decide on how to solve this problem by hand. Write pseudo code that shows what you would do by hand. Then convert this pseudo-code into a program.

Getting Help

If you get stuck:

  • Write small parts of your program and then test them. For example, knowing the miles per gallon and the gas price, you can estimate the cost of gas over 5 years. Make sure this part of your program is correct before you include resale value.
  • Talk to your friends about problems you may have, and describe your approach to them. Your ideas often become clearer as you explain them to someone else.
  • You can ask the TA to listen your ideas, but don't let them solve the problem for you.

Pass-off procedure

Compute the total cost of owning the car for 5 years. (For simplicity, we will not take the cost of financing into account.) Obtain realistic prices for a new and used hybrid and a comparable car from the Web. Run your program twice, using today's gas price and 15,000 miles per year.

When you have your program working, you will need to show it to a TA. The TA will evaluate your code based on the following criteria and his/her own input values:

  1. Did you print any answer without crashing? (7 points)
  2. Did you calculate the fuel costs correctly? (7 points)
  3. Did you calculate the total costs correctly? (6 points)

Extra credit

Assume that

  • a new normal car costs $15,000 and gets 25 mpg
  • you resell any car after 5 years for 75% its original value
  • you drive 10,000 miles in a year
  • gas costs $2.50

What gas mileage would a new hybrid ($32,000) need to have in order for total costs for 5 years to be equal to the total costs for a normal car? Test different values in your program to find the correct answer. (1 point)

Electronic Submission

WHEN YOU PASS OFF, you will need to submit your code. To do this follow the instructions below:

  1. On your computer, navigate to the directory containing your Visual C++ project (clue: look at the top bar in Visual C++).
  2. Find the .cpp files for the classes you have written.
  3. Attach these files to an email and send them to


If you have trouble, ask a neighbor or a TA.

You can save the files to the desktop and then attach them to an email.

An example pass-off form is shown below for this lab. You will find printed pass-off forms in 1119 TMCB.


LDAP: couldn't connect to LDAP server
cs-142/buying-a-hybrid-car.txt · Last modified: 2015/01/07 08:54 by ryancha
Back to top
CC Attribution-Share Alike 4.0 International
chimeric.de = chi`s home Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0