Answer to Question #149259 in C++ for Vaibhav Mahajan

Question #149259
2. Class Distance consists of length in feet and inches. Class Distance contains

1. one default constructor

IF. one parameterized constructor III. Function getdata () to take the value of feet and inches.

IV. Function show () to display.

V. Overload += operator in the Distance class.

Overload < operator to compare two distances.
1
Expert's answer
2020-12-06T17:54:25-0500
#include <iostream>


using namespace std;


class Distance{
    private:
        int feet;
        int inches;
    public:
        Distance(){}
        Distance(int ft, int in): feet(ft), inches(in){}
        void show(){
            cout << feet << " feet and " << inches << " inches" << "\n";
        }
        Distance operator+=(const Distance& d){
            this->feet = feet+d.feet;
            this->inches  = inches+d.inches;
            return *this;
        }
        void getdata(int ft, int in){
            feet = ft;
            inches = in;
        }
        bool operator<(const Distance& d){
            if(feet < d.feet) {
                return true;
            }
            if(feet == d.feet && inches < d.inches) {
                return true;
            }


            return false;
      }


};

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog