Question
class Distance { private: double meters; double centimeters; public: Distance (double m=1, double c=1) { meters = m; centimeters = c; } }; int main()
class Distance
{
private:
double meters;
double centimeters;
public:
Distance (double m=1, double c=1) {
meters = m;
centimeters = c; }
};
int main()
{
Distance d1(4,5), d2(2,3), d3;
}
- write setMeters and setCentimeters and let them havecascading capability.
They must be set to positive values.
-Overloadthe + operator to add two Distances and return the double sum of
all data members of both objects in centimeters.
( double sum = d1 + d2; //d1 and d2 are objects of class Distance)
-Overloadthe post-increment operator d2++; to increment by 1 the meter data member.
-Overload<< to print out a Distance using the following format:
Distance Information [2 Meters, 55.6 centimeters]
-Dynamically create an array of objects of class Distance in main and set their members
to values entered by the user.
You must do something before exiting the code
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