Assume you’re implementing class Rectangle. A Rectangle in 2D is described by th
ID: 3754879 • Letter: A
Question
Assume you’re implementing class Rectangle. A Rectangle in 2D is described by the x, y position of its upper lower left corner along with a width and height. Width and height may only be positive real numbers. Given this description, provide an implementation for setWidthand setHeight. In particular, if the new value for width or height violates the positive real number requirement, throw an exception. [10]
class Rectangle {
private:
int xPos;
int yPos;
int height;
int width;
public:
//all other functionality
//provide an implementation of the following two member functions
//and throw exceptions where appropriate.
void setWidth(int newWidth);
void setHeight(int newHeight);
};
Explanation / Answer
class Rectangle { private: int xPos; int yPos; int height; int width; public: //all other functionality //provide an implementation of the following two member functions //and throw exceptions where appropriate. void setWidth(int newWidth); void setHeight(int newHeight); }; void Rectangle::setWidth(int newWidth) { if(newWidthRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.