Question: C++ problem 1) Create an array to store 10 Point2D points (the Point2D class from A6). Set the coordinates from 0,0 to 9,9. Move all
C++ problem
1) Create an array to store 10 Point2D points (the Point2D class from A6). Set the coordinates from 0,0 to 9,9. Move all the points left 5 units and up 10 units. Print their new location. 2) Make a new class Point3D which inherits from the Point2D class. The class has one more data member for the z coordinate. There are two constructors, a default one and one with 3 coordinates. Add the new member functions getZ, setZ and moveAlongZ. Override moveToOrigin and printLocation to do the right thing for all 3 coordinates. Make a few Point3D objects and exercise their functionality.
Point2D class:
#include
class Point2D{
private: int x, y; public: // default constructor Point2D(){ x = 0; y = 0; } // parameterized constructor Point2D(int xp, int yp){ xp = x; yp = y; }
// setters and getters
int getX(){ return x; }
int getY(){ return y; }
void setX(int xp){ x = xp; }
void setY(int yp){ y = yp; }
void moveHorizontally(int xp){ x = x + xp; }
void moveVertically(int yp){ y = y + yp; }
void moveToOrigin(){ x = 0; y = 0; }
void printLocation(){ cout<<"Point at ("< int main(){ // creating object Point2D p1; p1.printLocation(); p1.setX(3); p1.printLocation(); p1.setY(-4); p1.printLocation(); p1.moveVertically(2); p1.printLocation(); return 0; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
