Question: C++ 1) Create a Point2D class. It should have the fields x and y, a default constructor that puts the point at the origin and
C++ 1) Create a Point2D class. It should have the fields x and y, a default constructor that puts the point at the origin and a constructor with arguments which puts the point at the given coordinate. It should have getters and setters for x and y, and four more member functions:
moveHorizontally which takes a number (positive or negative) and moves the point along the x axis by that many units moveVertically which takes a number (positive or negative) and moves the point along the y axis by that many units moveToOrigin which moves the point to 0,0 printLocation which prints the current location (e.g. Point at (2, 3) )
Create a few point instances and exercise their behaviors. Set their coordinates, move them along the x/y axis, print their location. 2) Explain briefly and clearly how classes are different from structs and how they can be more powerful. 3) Write a function named moveTo that takes two Point2D points and moves the first to the position of the second. The function returns nothing. Call your function from the main and verify by calling printLocation on the first point that it has indeed moved. 4) Create an array to store 10 Point2D points. Set the coordinates from 0,0 to 9,9. Move all the points left 5 units and up 10 units. Print their new location. 5) Overload operator + so that two Point2D objects can be added together. The result of adding p1(x1, y1) with p2(x2, y2) should be a point at (x1+x2, y1+y2). Create two points p1, p2 at different locations and printLocation of the result p1+p2.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
