To gain coding XP, complete this coding challenge by adding constructors to the Point class you completed for the previous challenge.Point should have three constructors:One that takes no arguments and does nothing (the default constructor).One that takes the x- and y-coordinates for the point to create as arguments. The x- and y-coordinates of a point should be non-negative. If the arguments provided are negative values, use 0 instead as the construction value.A copy constructor
Thanks for the question.
Here is the completed code for this problem. Comments are included, go through it, learn how things work, and let me know if you have any doubts or if you need anything to change.
Thanks!
===========================================================================
class Point{
private:
int x; int y; // member
variables
public:
// default constructor
Point();
// paremeterized constructor
Point(int x, int y);
// copy constructor
Point(const Point& p);
};
// default constructor
Point::Point() : x(0) , y(0) {}
// paremeterized constructor
Point::Point(int x, int y){
this->x = x<0?0:x;
this->y = y<0?0:y;
}
// copy constructor
Point::Point(const Point& p){
this->x = p.x;
this->y = p.y;
}
==================================================================
Get Answers For Free
Most questions answered within 1 hours.