Question: So far I have this code but I'm not sure if it's right or how to finish it. #include distance.h #include #include #include using namespace

 So far I have this code but I'm not sure ifSo far I have this code but I'm not sure if it's right or how to finish it.

#include "distance.h"

#include

#include

#include

using namespace std;

Distance::Distance()

{

feet = 0;

miles = 0;

yards = 0;

inches = 0;

}

Distance::Distance(int inch)

{

}

Distance::Distance(int m, int y, int f, double i)

{

if(m

{

feet = 0;

miles = 0;

yards = 0;

}

else if (i

{

inches = 0;

}

if(i >= 12)

{

inches = 0;

feet++;

}

if(f >= 3)

{

feet = 0;

yards++;

}

if(y >= 1760)

{

yards = 0;

miles++;

}

}

Your task will be to create a class called Distance, in the files distance.h and distance.cpp, which will involve a variety of operator overloads. A Distance object will store a quantity of distance in terms of miles, yards, feet, and inches. You will overload some basic operators for use with these objects including arithmetic, comparison, and insertion/extraction operators. These operators must work even for large distances (e.g. thousands of miles) and should not overflow the capacity of the storage variables (int) unless the number of miles is very close to the upper limit of int storage. Program Details and Requirements The Distance class must allow for storage of a non-negative quantity of distance in terms of miles, yards, feet, and inches using integer precision. All values should be non-negative. The data should always be maintained in a simplified form. For example, if you have 14 inches, this should be expressed as 1 foot and 2 inches. You should create appropriate member data in your class, all of which must be private. Remember that there are 12 inches in a foot, 3 feet in a yard, and 1760 yards in a mile. The only limit on the number of miles is that imposed by int storage (e.g. ~2 billion for 32 bit int) Public Interface 1. Constructors The class should have a default constructor (no parameters) which should initialize the object so that it represents the distance 0. The class should have a constructor with a single integer parameter which represents a quantity of inches. This should be translated into the appropriate notation for a Distance object. Note: this will be a conversion constructor that allows automatic type conversions from int to Distance. If the parameter is negative, default the Distance object to represent 0. The class should have a constructor that takes 4 parameters representing the miles, yards, feet, and inches to use for initializing the object. If any of the provided values are negative, default the Distance object to represent 0. If any of the provided values are too high (e.g. 13 inches), simplify the object to the appropriate representation. Examples: Distance t; Distance s (1234); // creates an object of 0 miles, 0 yards, 0 feet, 0 inches // creates an object of 0 miles, 34 yards, 0 feet, 10 inches

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!