1. Engineering
  2. Computer Science
  3. for the point class implement the overloaded parameter quotquot so...

Question: for the point class implement the overloaded parameter quotquot so...

Question details

For the point class, implement the overloaded parameter "*", so that the operator can be used to scale the x and y values of a point by a fixed number. Usage: point p2 = 2.0*p1; In this example p2's x and y coordinates should be double that of p1. Specify whether you would implement the operator as a member function, a non-member function or a friend function, and why?

A Header File //FILE: point.h // CLASS PROVIDED: point (part of the namespace main_savitch 2A) // CONSTRUCTOR for the point class // point(double initial.x = 0.0, double initial-y = 0.0) // Postcondition: The point has been set to (initial_x, initial y). //MODIFICATION MEMBER FUNCTIONS for the point class: //void shift(double x_amount, double y_amount) // Postcondition: The point has been moved by x amount along the x axis // and by y.amount along the y axis. // void rotate900) / Postcondition: The point has been rotated clockwise 90 degrees around the origin. // CONSTANT MEMBER FUNCTIONS for the point class: // double get_x() const / Postcondition: The value returned is the x coordinate of the point. // double get_y() const / Postcondition: The value returned is the y coordinate of the point. // VALUE SEMANTICS for the point class: /Assignments and the copy constructor may be used with point objects. #1 fndef MAIN-SAVİTCH-POINT-H #define MAIN-SAVITCH-POINT-H namespace main savitch_2A class point public: CONSTRUCTOR point(double initial_x -0.0, double initial y0.0); // MODIFICATION MEMBER FUNCTIONS voïd shift(double x_amount, double y_amount); void rotate90( //CONSTANT MEMBER FUNCTIONS double get xC const return x; 1 double get y) const return y; 1 private: double x; // x coordinate of this point double y; // y coordinate of this point fendi fAn Implementation File / FILE: point.cxx /I CLASS IMPLEMENTED: point (see point.h for documentation) #1 nclude point . h namespace main_savitch_2A point::point(double initial_x, double initial_y) 1 // Constructor sets the point to a given position. x - initial_x; y -initial.y; void point::shift (double x amount, double y_amount) XX amount; yyamount; void point::rotate90C) double new_x; double newy new x y; // For a 90-degree clockwise rotation, the new x is the original y new-y =-х; // and the new y is-1 times the original X. x = new-x; y- new y;

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution