Question: Four integers are read from input, where the first two integers are the miles and feet of distance1 and the second two integers are the

Four integers are read from input, where the first two integers are the miles and feet of distance1 and the second two integers are the miles and feet of distance2. Complete the function to overload the + operator.

Ex: If the input is 13 1415 2 642, then the output is:

13 miles, 1415 feet 2 miles, 642 feet Sum: 15 miles, 2057 feet

Note: The sum of two distances is:

the sum of the number of miles

the sum of the number of feet

#include using namespace std;

class Distance { public: Distance(int miles = 0, int feet = 0); void Print() const; Distance operator+(Distance rhs); private: int mi; int ft; };

Distance::Distance(int miles, int feet) { mi = miles; ft = feet; }

// No need to accommodate for overflow or negative values Distance Distance::operator+(Distance rhs) {

/* Your code goes here */

}

void Distance::Print() const { cout << mi << " miles, " << ft << " feet"; }

int main() { int miles1; int feet1; int miles2; int feet2; cin >> miles1; cin >> feet1; cin >> miles2; cin >> feet2; Distance distance1(miles1, feet1); Distance distance2(miles2, feet2); Distance sum = distance1 + distance2; distance1.Print(); cout << endl; distance2.Print(); cout << endl; cout << "Sum: "; sum.Print(); cout << endl; return 0; }

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!