Question: Please help zybooks lab. C++ any warnings will result in termination of program For this activity we attempt to make our own container class (like

Please help zybooks lab. C++ any warnings will result in termination of program

For this activity we attempt to make our own container class (like vector) to hold instances of our "point" class. To do this you will need create 2 classes as described below:

CMyPoint - This class will contain a point in an arbitrary 2 dimensional space. You will create instances of this class and store them in the container CMyPointArray. To achieve this you will need to implement the following:

int _X - which is an integer that contains the location of the point in the horizontal direction

int _Y - which is an integer that contains the location of the point in the vertical direction

const int GetX() - which is the "getter function for the "x" coordinate.

const int GetY() - which is the "getter function for the "y" coordinate.

friend ostream& operator << (ostream& os, const CMyPoint& pt) - this function is an overload of the "<<" operator that will allow the class to print itself when used in an io stream (just like all of the other variables in this course). Please see this link for more information

The constructor for this class should take "X" and "Y" parameters with defaults of zero.

All variables are to be declared private and all functions declared public.

CMyPointArray - This class will dynamically (e.g. new and delete) allocate and de-allocate memory so that it is capable of containing an arbitrary number of instances of the CMyPoint object. To achieve this you will need to implement the following:

CMyPoint* pPoints - This variable is a pointer to the memory that contains the CMyPoint objects.

CMyPoint Get(const int iIndex) - This is the "getter" function used to retrieve a particular point that is contained in an instance of the CMyPointArray class. The parameter const int iIndex is used to locate the particular point.

void Set(const int iIndex, const CMyPoint pt) - This is the "setter" function used to store a particular point in an instance of the CMyPointArray class, at the location indicated by iIndex.

The class constructor should take as a parameter the size of the container (e.g. how may CMyPoint objects it will hold) and allocate the appropriate space to hold theses objects.

The class destructor should free any memory the CMyPointArray class owns.

All variables are to be declared private and all functions declared public.

Note: Do not use the STL vector object in any part of your program or you will receive 0 points. Instead go caveman style and use the C++ new and delete functions as described in this chapter.

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!