Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Help with the following practice question in C++ Now consider the Point class template Let's explore what constraints are associated with each of its member

Help with the following practice question in C++

Now consider the Point class template

Let's explore what constraints are associated with each of its member functions. For each of the member functions listed below, what are the constraints on any template parameters associated with it? List the constraints separately (e.g., with a bulleted list); be as specific as possible about which constraints to include, but no single constraint requires you to write more than a few words.

  1. The constructor that takes three CoordinateType arguments.
  2. The copy constructor that initializes a Point of one type from a Point of a potentially different type.
  3. The assignment operator that assigns a Point of one type from a Point of a potentially different type.
  4. The x, y, and z member functions. (Note: Both overloads of all three of these will have the same constraints. Do you see why?)
  5. The distanceFrom member function.

 #ifndef POINT_HPP #define POINT_HPP #include template class Point { public: Point( const CoordinateType& x, const CoordinateType& y, const CoordinateType& z); template Point(const Point& other); template Point& operator=(const Point& other); CoordinateType& x() noexcept; const CoordinateType& x() const noexcept; CoordinateType& y() noexcept; const CoordinateType& y() const noexcept; CoordinateType& z() noexcept; const CoordinateType& z() const noexcept; double distanceFrom(const Point& p) const; private:  CoordinateType x_; CoordinateType y_; CoordinateType z_; }; template Point::Point( const CoordinateType& x, const CoordinateType& y, const CoordinateType& z) : x_{x}, y_{y}, z_{z} { } template template Point::Point(const Point& other) : x_{other.x()}, y_{other.y()}, z_{other.z()} { } template template Point& Point::operator=(const Point& other) { x_ = other.x(); y_ = other.y(); z_ = other.z(); return *this; } template CoordinateType& Point::x() noexcept { return x_; } template const CoordinateType& Point::x() const noexcept { return x_; } template CoordinateType& Point::y() noexcept { return y_; } template const CoordinateType& Point::y() const noexcept { return y_; } template CoordinateType& Point::z() noexcept { return z_; } template const CoordinateType& Point::z() const noexcept { return z_; } template double Point::distanceFrom(const Point& other) const { return std::sqrt( (x_ - other.x_) * (x_ - other.x_) + (y_ - other.y_) * (y_ - other.y_) + (z_ - other.z_) * (z_ - other.z_)); } #endif // POINT_HPP 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions