The class Distance is defined below: class Distance //English Distance class { private: int feet; float inches; public: //constructor (no args) Distance()...

50.1K

Verified Solution

Question

Programming

The class Distance is defined below:

class Distance //English Distance class
{
private:
int feet;
float inches;
public: //constructor (no args)
Distance() : feet(0), inches(0.0)
{ } //constructor (two args)
Distance(int ft, float in) : feet(ft), inches(in)
{ }
};

Overloading the following operators:
a. + to add two Distance objects using member function.
b. - to subtract two Distance objects using friend function
c. << and >>
Use the following main function to test your class Distance.

int main()
{
Distance dist1, dist3, dist4; //define distances
cin>>dist1;
Distance dist2(11, 6.25); //define, initialize dist2
dist3 = dist1 + dist2; //single '+' operator
dist4 = dist1 - dist2; //friend '-' operators
//display all lengths
cout << \"dist1 = \";
cout<< dist1 << endl;
cout << \"dist2 = \";
cout<< dist2 << endl;
cout << \"dist3 = \";
cout<< dist3 << endl;
cout << \"dist4 = \";
cout<< dist4 << endl;
return 0;
}

PLEASE DO THIS WITH C++

Also, using declaration of array and using [] notationfor accessing element of array

Answer & Explanation Solved by verified expert
3.8 Ratings (606 Votes)
include include include using namespace stdclass Distance English Distance classprivateint feetfloat inchespublic constructor no    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students