Answer to Question #179213 in C++ for Waleed Abid

Question #179213

Create a class called Distance that has two data member feet as int type and inches as float type. Provide multiple constructors for the Distance class. One constructor should initialize this data to 0, and another should initialize it to fixed values. Also provide copy constructor to initialize Distance object with another object. Also provide get and set method for the class.


1
Expert's answer
2021-04-07T20:03:43-0400
class Distance
{
  int _feet;
  float _inches;


  public:


      int GetFeet()
      {
          return _feet;
      }


      float GetInches()
      {
          return _inches;
      }


      void SetFeet(int feet)
      {
          _feet = feet;
      }


      void SetInches(float inches)
      {
          _inches = inches;
      }


      Distance()
      {
          _feet = 0;
          _inches = 0;
      }


      Distance(int feet, float inches)
      {
          _feet = feet;
          _inches = inches;
      }


      Distance(const Distance &distance)
      {
          _feet = distance._feet;
          _inches = distance._inches;
      }
};

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
APPROVED BY CLIENTS