Assignment 2

due at midnight on   +40

The objective of this assignment is to encourage you to write programs with conditional statements and expressions. Create a file called a2.cpp in your cs102 folder – that’s the filename I will look for when I am grading.

Write a program to do distance conversions, according to quantities and units provided by the user. It should be able to convert between meters, kilometers, miles, and yards. Below are a couple of transcripts of different runs of my program:

First we’ll test entering kilometers. The program produces that quantity in meters, miles, and yards.

Enter a distance: 86.3
Select unit for that distance:
  1. meters
  2. kilometers
  3. miles
  4. yards
Your choice: 2
86.3 kilometers is:
  86300 meters.
  53.6245 miles.
  94378.8 yards.

In this next run, we chose miles and get the result in meters, kilometers, and yards.

Enter a distance: 32
Select unit for that distance:
  1. meters
  2. kilometers
  3. miles
  4. yards
Your choice: 3
32 miles is:
  51499 meters.
  51.499 kilometers.
  56320 yards.

Look for the correct conversion factors between these units using Google. You can also simply ask Google to check your work for you, by typing in “32 miles in km” (for example) as your search query.

To submit your program, select Tools » Sync with git from the editor’s menu. If the transcript says SUCCESS then your file has been saved successfully on the server.