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

My Program description is this.... Write a program that will create a list of ax

ID: 3533315 • Letter: M

Question

My Program description is this....

Write a program that will create a list of axis-aligned rectangles dened 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.(See www:wikipedia:org for a formal dention). Each rectangle is dened by the

(x, y) location of its bottom left corner, its length (along the x-axis), and its height (along

1the 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.

In the code template you will nd two class denitions. The class Point has two data

members to represent an (x, y) location. This will be used to represent the bottom left

corner of a rectangle and its midpoint. The class attributes and member functions for the

class Point are already completed for you. You do not need to make any changes to

this class.

The class Rectangle has four data members: name, class Point object, length, and height.

The class Point object stores the bottom left corner location of a class Rectangle object. The

member functions are also dened for you, but you will have to write the correct code for

each one. I have indicated these places with // replace with your code. Do not add

or remove any data members or member functions of the class Rectangle.

1. All functions should be written AFTER the main procedure.

2. All function prototypes should be written for each function and placed BEFORE the

main procedure.

3. Each function should have a comment explaining what it does.

4. Each function parameter should have a comment explaining the parameter.

5. You will write the following functions and implement the main function using the

algorithm above. The function descriptions specify the exact input parameters and

return types for the functions. You must follow the specications outlined here to

solve your homework. Though, you should carefully decide whether input parameters

are passed by value or by reference.

6. Write a function which displays the welcome banner. The function has no input pa-

rameters and has a return type of void. Use this in step (i) of the algorithm.

7. Write a function that prompts and reads from the user the name of the rectangle or the

word stop and validates this user input. The user will enter the name for a rectangle

by typing the keyword rec followed by a single space and then the name, e.g., when the

user enters rec john (this is valid input), the name of the rectangle will be assigned

to john. Note that just typing john is invalid input. If the user types stop then

this indicates that the user does not want to enter any more rectangles. This is valid

input. The user is not allowed to input a name for a rectangle that is already used for

a previously entered rectangle. This is invalid input. Any other input is also invalid.

This function has a return type of bool and returns true only if the user input entered

was valid.

The function has ve input parameters. A string that holds the prompt that asks for

the name of the rectangle. A string that holds an error message to display if the user

types invalid input. A string that holds an error message to display if the user types

a name that is already being used. A string that will pass back the user input, i.e.

3whatever the user entered. Lastly, a vector of rectangles, i.e. a list, containing all

rectangles entered so far. Use this function in steps (ii) and (xi).

8. Write a function that prompts and reads the x and y coordinates of the bottom left

corner of a rectangle. The function has return type of void. It has three input param-

eters. A string that holds the prompt that asks for user input. A double for passing

back the entered x coordinate. A double for passing back the entered y coordinate.

This function is used in steps (vi) and (xv).

9. Write a function that prompts and reads the length and height of a rectangle. The

function has return type of void. It has three input parameters. A string that holds

the prompt that asks for user input. A double for passing back the length. A double

for passing back the height. This function should continue prompting the user until

positive values are ented for both values. Use this function in steps (vii) and (xvi).

10. Write a function that adds a rectangle to the back of a vector of rectangles. First, the

function will set the values (name, location, length, and height) of the rectangle into

a class Rectangle object. Second, it will add this object to the back of the vector of

rectangles. The function has a return type of void. It has six input parameters. A

string holding the name of the rectangle. A double holding the x coordinate of the

bottom left corner. A double holding the y coordinate of the bottom left corner. A

double holding the length. A double holding the height. Lastly, a vector of rectangles

containing all rectangles entered so far. Use this function in steps (viii) and (xvii).

11. Write a function that displays all the rectangles in the vector of rectangles. This

function has a return type of void. It has a single input parameter which is a vector

of rectangles containing all rectangles entered so far. Use this function in step (xix).

12. Implement the set and get member functions of the class Rectangle (see examples

found in the lecture notes and textbook reading).

13. Implement the member function area() of the class Rectangle that computes the area

of the rectangle object. Use the appropriate class attributes of the class Rectangle.

14. Implement the member function perimeter() of the class Rectangle that computes

the perimeter of the rectangle object. Use the appropriate class attributes of the class

Rectangle.

15. Implement the member function midPoint() of the class Rectangle that computes

and returns the midpoint of the rectangle object (returned as a class Point object).

The midpoint is the (x, y) point located at the center of a rectangle.

16. Implement the member function scaleBy2 of the class Rectangle that scales the

rectangle object by a factor of 2 around its midpoint. Note that the length and height

4of the rectangle are doubled and the bottom left corner location may change. Though,

the midpoint should not change, since we are scaling about this point. For example, if

a rectangle has a bottom left corner location of (1, 1), a length of 2, and a height of 4,

its new bottom left corner location is (0, -1), its new length is 4, and its new height is

8. The midpoint is still at its original location (2, 3). This function must change the

rectangle object's class attributes to re

ect the scaled up rectangle.

17. Implement the member function display() of the class Rectangle that displays all

information about a rectangle object. Call this function within the function you are

writing for step (xix) of the algorithm above.

18. Be sure to modify the header comments "File", "Created by", "Creation Date", and

"Synopsis" at the top of the le. Each synopsis should contain a brief description of

what the program does.


And this is what i have so far.........

#include <isosteam>

#include <string>

#include <vector>

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:

///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

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(inLength>0)

length=inLenght;

else

{

cout<<"Length must be great than zero. Length set to 1";

length=1;

}

if (inHeight>0);

height=1;

else

{

cout<<"Hieght must be great than zero. Height set to 1";

height=1;

}

}

string Rectangle::getName() const

{

return name;

}

Point Rectangle::getBottomLeft() const

{

return blPoint;

}


double Rectangle::getLength() const

{

return length;

}


double Rectangle::getHeight() const

{

return height;

}


double Rectangle::area() const

{

return(length*height);

}


double Rectangle::perimeter() const

{

return(2(length+height));

}


Point Rectangle::midPoint() const

{

point t;

t.setX(blPoint.getX()+(length/2.0));

t.setY(blPoint.getY()+(length/2.0));

return(t);

}

void Retangle::scaleBy2()

{

point r;

blPoint.setX(blPoint.getX()-(length/2.0));

}

void Rectangle::display() const

{

// replace with your code

}


Explanation / Answer

//this is my old program from same/similar assignment: http://ideone.com/DJACBG

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