Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a C++ program that will create a list of axis-aligned rectangles defined i

ID: 3659071 • 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 NOTE: Please fill in the main function and all other functions with the right code. It will help me a lot when studying classes!! Thank you. #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; }; // FUNCTION PROTOTYPES GO HERE: int main() { // Define your local variables, e.g. a vector of class Rectangle // Display welcome banner /* Prompt user for first rectangle or 'stop' */ // WHILE user input is invalid // Display "Try again! " // IF user input is not 'stop' // Extract rectangle name from user input // Prompt for bottom left point // Prompt for length and height // Add rectangle to the rectangle list /* Prompt user for next rectangle or 'stop' */ // WHILE user input not 'stop' // Display "Thank you! " // WHILE user input is invalid // Display "Try again! " // IF user input is not 'stop' // Extract rectangle name from user input // Prompt for bottom left point // Prompt for length and height // Add rectangle to the rectangle list // IF the rectangle list is not empty // Display all rectangles in the rectangle list // ELSE // Display that no rectangles are in the list return 0; } // FUNCTION DEFINITIONS GO HERE: // CLASS MEMBER FUNCTION DEFINITINOS GO HERE: 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); } void Rectangle::setName(const string & inName) { // replace with your code } void Rectangle::setBottomLeft(const double x, const double y) { // replace with your code } void Rectangle::setDimensions(const double inLength, const double inHeight) { // replace with your code } string Rectangle::getName() const { // replace with your code } Point Rectangle::getBottomLeft() const { // replace with your code } double Rectangle::getLength() const { // replace with your code } double Rectangle::getHeight() const { // replace with your code } double Rectangle::area() const { // replace with your code } double Rectangle::perimeter() const { // replace with your code } Point Rectangle::midPoint() const { // replace with your code } void Rectangle::scaleBy2() { // replace with your code } void Rectangle::display() const { // replace with your code

Explanation / Answer

#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; }; // FUNCTION PROTOTYPES GO HERE: int main() { // Define your local variables, e.g. a vector of class Rectangle // Display welcome banner /* Prompt user for first rectangle or 'stop' */ // WHILE user input is invalid // Display "Try again! " // IF user input is not 'stop' // Extract rectangle name from user input // Prompt for bottom left point // Prompt for length and height // Add rectangle to the rectangle list /* Prompt user for next rectangle or 'stop' */ // WHILE user input not 'stop' // Display "Thank you! " // WHILE user input is invalid // Display "Try again! " // IF user input is not 'stop' // Extract rectangle name from user input // Prompt for bottom left point // Prompt for length and height // Add rectangle to the rectangle list // IF the rectangle list is not empty // Display all rectangles in the rectangle list // ELSE // Display that no rectangles are in the list return 0; } // FUNCTION DEFINITIONS GO HERE: // CLASS MEMBER FUNCTION DEFINITINOS GO HERE: 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{ cout
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote