Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ Please answer all questions. 1) Create an array to store 10 Point2D points (

ID: 3841578 • Letter: C

Question

C++

Please answer all questions.

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.

3) Add a new data member, string color to your Point2D class and a new getter and setter function for color. Create a Point2D object and set its color. Then create a Point3D color and try to set its color. Is the setColor behavior available for a Point3D class? Why or why not?

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.

Explanation / Answer

Question 1

The program is given below:

#include <iostream>
using namespace std;
struct PointStruct             // structure for the point
{
    int X;
    int Y;
};
typedef PointStruct* pointsArray;

int main(void)                      // main method
    {
       int p = 0;
      
       //create array to hold 10 points
        pointsArray arr = new PointStruct[10];         
        for(int i = 0; i < 10; i++)
        {
            arr[i].X = p;         
            arr[i].Y = p;
           p++;
        }
        cout<<"The co-ordinates are: "<<endl;
        for(int i = 0; i < 10; i++)
        {
          
           cout<<"("<<arr[i].X<<", "<<arr[i].Y<<")"<<endl;  
        }
        return 0;                    
    }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote