Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For the point class, implement the overloaded parameter '+=', so that for two point objects p1 and p2, p1+= p2, produces the effect of adding

For the point class, implement the overloaded parameter '+=', so that for two point objects p1 and p2, p1+= p2, produces the effect of adding p2's x and y member variables to the corresponding member variables of p1, and store the resulting values back into p1. Usage: p1+=p2. Specify whether you would implement the operator as a member function, a non-member function or a friend function, and why?

image text in transcribedimage text in transcribed

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-SAVTCH-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 vod 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 f An 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; 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-SAVTCH-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 vod 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 f An 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

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

Progress Monitoring Data Tracking Organizer

Authors: Teacher'S Aid Publications

1st Edition

B0B7QCNRJ1

More Books

Students also viewed these Databases questions

Question

How does the Rights Theory compare with the Fairness Theory?

Answered: 1 week ago

Question

1. Describe the power of nonverbal communication

Answered: 1 week ago