Question: C++ programming 1.2 Class PointXY The class PointXY will be used below in questions. class PointXY { public: PointXY() { x = 0; y =

C++ programming

1.2 Class PointXY The class PointXY will be used below in questions. class PointXY { public: PointXY() { x = 0; y = 0; } void set(double a, double b) { x = a; y = b; } double getx() const { return x; } double gety() const { return y; } private: double x, y; };

This question uses the class PointXY defined in Sec. 1.2. Declare a class Polygon as follows. The data in class Polygon is an integer num and a pointer PointXY *pxy, both private. class Polygon { public: Polygon(int n); // write code // copy constructor // write code // assignment operator // write code // destructor // write code (return type) get_point(int n) const; // write code void set_point(const PointXY &p, int n); // write code int get_num() const { return num; } // nothing to do, code is given to you private: int num; PointXY *pxy; }; Write a non-default constructor with an input int n. 1. If n > 0, set num=n and dynamically allocate pxy to an array of length num. 2. Else if n ? 0, set num = 0 and pxy = NULL. Write a copy constructor, assignment operator and destructor to perform appropriate copies and management of dynamic memory. Write a method get point(int n). 1. Return the address of pxy[n] if the value of n is valid. 2. Else return NULL. 3. The method is const. 4. Write the function value to have the correct type. Write a method set point(const PointXY &p, int n). 1. Set pxy[n] = p if the value of n is valid. 2. Else do nothing.

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!