The type Point is a fairly simple data type, but under another name (the templat
ID: 3654622 • Letter: T
Question
The type Point is a fairly simple data type, but under another name (the template class pair) this data type is defined and used in the C++ Standard Template Library, although you need not know anything about the Standard Template Library to do this exercise. Write a definition of a class named Point that might be used to store and manipulate the location of a point in the plane. You will need to declare and implement the following member functions: a.) A member function set that sets the private data after an object of this class is created. b.) A member function to move the point by an amount along the vertical and horizontal directions specified by the first and second arguments. c.) A member functions to rotate the point by 90 degrees clockwise around the origin. d.) Two const inspector functions to retrieve the current coordinates of the point. Document these functions with appropriate comments. Embed your class in a test program that requests data for several points from the user, creates the points, then exercises the member functions.Explanation / Answer
#include #include using namespace std; class Point { public: Point(double initial_x = 0, double initial_y = 0); void shift(double x_amount, double y_amount); void rotate90(); int rotation_needed(Point p); void rotation_upper_right(Point &p); double get_x() const {return x;} double get_y() const {return y;} friend istream& operator >>(istream &ins, Point &target); private: double x; double y; }; //NON-MEMBER FUNCTIONS double distance(const Point &p1, const Point &p2); Point mid_point(const Point &p1, const Point &p2); bool operator ==(const Point &p1, const Point &p2); bool operator !=(const Point &p1, const Point &p2); Point operator +(const Point &p1, const Point &p2); ostream& operatorRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.