Answered step by step
Verified Expert Solution
Question
1 Approved Answer
#include Distance.h #include #include Distance::Distance ( ) { feet = 0 ; inches = 0 . 0 ; } Distance::Distance ( unsigned ft ,
#include "Distance.h
#include
#include
Distance::Distance
feet ;
inches ;
Distance::Distanceunsigned ft double in : feetft inchesin
init;
Distance::Distancedouble in : feet inchesin
init;
unsigned Distance::getFeet const
return feet;
double Distance::getInches const
return inches;
double Distance::distanceInInches const
return feet inches;
double Distance::distanceInFeet const
return feet inches ;
double Distance::distanceInMeters const
return distanceInInches;
const Distance Distance::operatorconst Distance &rhs const
double totalInches distanceInInches rhsdistanceInInches;
return DistancetotalInches;
const Distance Distance::operatorconst Distance &rhs const
double diffInches distanceInInches rhsdistanceInInches;
ifdiffInches
diffInches diffInches; Ensure that Distance is always positive
return DistancediffInches;
ostream& operatorostream &out, const Distance &rhs
out rhsgetFeet rhsgetInches;
return out;
void Distance::init
if inches
feet staticcastinches;
inches fmodinches;
#include
using namespace std;
class Distance
public:
Constructs a default Distance of feet and inches
Distance;
Constructs a distance of ft feet and in inches,
unless in in which case the values of feet and inches
are adjusted accordingly. A Distance will always be positive.
Just convert negative inches to positive. Don't subtract from feet.
Distanceunsigned ft double in;
Constructs a distance of ft and in inches,
unless in in which case the values of feet and inches
are adjusted accordingly. A Distance will always be positive.
Just convert negative inches to positive. Don't subtract from feet.
Distancedouble in;
Returns just the feet portion of the Distance
unsigned getFeet const;
Returns just the inches portion of the Distance
double getInches const;
Returns the entire distance as the equivalent amount of inches.
eg feet inches would be returned as inches
double distanceInInches const;
Returns the entire distance as the equivalent amount of feet.
eg feet inches would be returned as feet
double distanceInFeet const;
Returns the entire distance as the equivalent amount of meters.
inch equals meters.
eg feet inches would be returned as meters
double distanceInMeters const;
Returns the sum of Distances.
Distance operatorconst Distance &rhs const;
Returns the difference between Distances.
Distance operatorconst Distance &rhs const;
Outputs to the stream out the Distance in the format:
feet' inches'ie
friend ostream & operatorostream &out, const Distance &rhs;
private:
Used by the parameterized constructors to convert any negative values to positive and
inches to the appropriate number of feet and inches.
void init;
unsigned feet;
double inches;
;
#include
using namespace std;
#include "Distance.h
int main
Distance d;
cout d: d endl;
Distance d Distance;
Distance d Distance;
cout d: d endl;
cout d: d endl;
test init helper function
Distance d Distance;
Distance d Distance;
cout d: d endl;
cout d: d endl;
test add inches
cout d d: d d endl;
test add inches
cout d d: d d endl;
test sub ft
cout d d: d d endl;
test sub ft negative conversion
cout d d: d d endl;
test sub positive ft & inch
cout d d: d d endl;
test sub negative ft & inch
cout d d: d d endl;
test sub negative ft positive inch
cout d d: d d endl;
test sub positive ft negative inch
cout d d: d d endl;
return ;
mistake:Distance.cpp::: error: no declaration matches const Distance Distance::operatorconst Distance& const
const Distance Distance::operatorconst Distance &rhs const
~~~~~~~
In file included from Distance.cpp::
Distance.h::: note: candidate is: Distance Distance::operatorconst Distance& const
Distance operator
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started