Write a C++ program that will create a list of axis-aligned rectangles defined i
ID: 3658956 • Letter: W
Question
Write a C++ program that will create a list of axis-aligned rectangles defined in a 2D space,
i.e. the x-y space. An axis-aligned rectangle has two vertical sides (left and right) that
are parallel to the y-axis and two horizontal sides (top and bottom) that are parallel to
the x-axis.
Each rectangle is defined by the(x, y) location of its bottom left corner, its length (along the x-axis),
and its height (along the y-axis). In your program, each rectangle will also have its own unique name. After
the description of each rectangle is input from the user and stored in a list (vector of class
Rectangle), your program will compute each rectangle's area, perimeter, and midpoint. In
addition, you will scale each rectangle by a factor of 2 about its midpoint. Please use/complete the template
Explanation / Answer
//class defintion of Rectangle and Point //the other fxns need more specifics (instructions/ purpose etc) or at least a samplerun #include #include #include using namespace std; class Point { private: double px; double py; public: void setX(const double x); void setY(const double y); double getX() const; double getY() const; }; class Rectangle { private: string name; Point blPoint; double length, height; public: // member functions void setName(const string & inName); void setBottomLeft(const double x, const double y); void setDimensions(const double inLength, const double inHeight); string getName() const; Point getBottomLeft() const; double getLength() const; double getHeight() const; double area() const; double perimeter() const; Point midPoint() const; void scaleBy2(); void display() const; }; // CLASS MEMBER FUNCTION DEFINITIONS GO HERE: ///Point void Point::setX(const double x){ px=x; } void Point::setY(const double y){ py=y; } double Point::getX()const{ return px; } double Point::getY()const{ return py; } ///Rectangle /* string name; Point blPoint; double length, height;*/ void Rectangle::setName(const string & inName){ name=inName; } void Rectangle::setBottomLeft(const double x, const double y){ blPoint.setX(x); blPoint.setY(y); } void Rectangle::setDimensions(const double inLength, const double inHeight){ if(inLenght>0) lenght=inLength; else{ coutRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.