Fall 2014

Lab06
Distance

Due: Tuesday November 12, 2013 11:59 PM

Lab06 - Distance

Requirements

Distance class created10 pts
Distance class can store values as Miles or Kilometers10 pts
Addition can be performed correctly20 pts
Subtraction can be performed correctly20 pts
Multiplication can be performed correctly20 pts
Division can be performed correctly20 pts
Total100 pts

Resources

Objective

To practice working with classes and operators

Instructions

Create a class called Distance whose objects can store a distance measured in either miles or kilometers. Set up your Distance class so its objects can be added, subtracted, multiplied, or divided by other distance objects.

When the two distance objects that are being worked with are not in the same units a conversion will have to take place. To convert miles to kilometers multiple the value by 1.60934 and to convert kilometers to miles multiple the value by 0.621371

Your distance class is correct when it can run the attached code and produce the following output:

Adding:
1.621371 Miles
4 Miles
4
m
6 Kilometers
10.43736 Kilometers
------------------------------
Subtracting:
0.378629 Miles
0 Miles
0
m
0 Kilometers
-2.43736 Kilometers
------------------------------
Multiplying:
0.621371 Miles
4 Miles
4
m
9 Kilometers
25.74944 Kilometers
------------------------------
Dividing:
1.6093444978925633 Miles
1 Miles
1
m
1 Kilometers
0.6213727366498067 Kilometers