Question
C ++ Assignment Please help (If possible can you please mark the answers individually, thank you) I) a) Create an array to store 10 Point2D
C ++ Assignment
Please help (If possible can you please mark the answers individually, thank you)
I)
a) Create an array to store 10 Point2D points (the Point2D class from below). Set the coordinates from 0,0 to 9,9. Move all the points left 5 units and up 10 units. Print their new location.
Here is code for Point2D class :
class Point2D { public: /* * Default Constructor * Places point at (0, 0) */ Point2D() { x = 0; y = 0; } /* * Constructor * Places point at (xCoord, yCoord) */ Point2D(int xCoord, int yCoord) { x = xCoord; y = yCoord; } int getX() { return x; } int getY() { return y; } void setX(int xCoord) { x = xCoord; } void setY(int yCoord) { y = yCoord; } void moveHorizontally(int distance) { x+=distance; } void moveVertically(int distance) { y+=distance; } void moveToOrigin() { x = y = 0; } /* * Prints the current location of the point * */ void printLocation() { cout<<"Point located at ("< b) 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. c) 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.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started