Question: C++ (please help) This is Point 2D class code class Point2D { private: double x; double y; public: Point2D() { x = 0; y =

C++

(please help)

This is Point 2D class code

class Point2D { private: double x; double y; public: Point2D() { x = 0; y = 0; } Point2D(double xVal, double yVal) { x = xVal; y = yVal; } double getX() { return x; } double getY() { return y; } void setX(double xVal) { x = xVal; } void setY(double yVal) { y = yVal; } void moveHorizontally(double xVal) { x += xVal; } void moveVertically(double yVal) { y += yVal; } void moveToOrigin() { x = 0; y = 0; } void printLocation() { cout << "Point at (" << x << ", " << y << ")" << endl; } }; int main() { Point2D p1; p1.setX(3); p1.setY(2); p1.printLocation(); p1.moveHorizontally(5); p1.printLocation(); p1.moveVertically(5); p1.printLocation();

return 0; }

4) Make a Point2D* pointer variable and point it to a newly created Point2D object. Make a Point3D* pointer variable and point it to a newly created Point3D object. Use the pointer variables to move the points and print their locations. 5) Point a Point2D pointer to a Point3D object. Does this work? Why or why not? Use the Point2D pointer to print the location of the Point3D object. What does it print? Is that what you expected for the location of a 3D point? 6) Modify the member functions so that exercise 5 behaves as expected for a Point3D

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!