Question
Overview For this assignment, implement and use the methods for a class called Rectangle. Rectangle class This class represents a simple rectangle shape. Data Members
Overview
For this assignment, implement and use the methods for a class called Rectangle.
Rectangle class
This class represents a simple rectangle shape.
Data Members
The data members for the class are:
an integer that holds the height of the rectangle
an integer that holds the width of the rectangle
Constructors
This class has two constructors. The default constructor (the one that takes no arguments) should initialize both the height and width of the rectangle to 1. This should be done by calling the setDimension method that is described below.
The other constructor for the class should initialize the data members using the passed in arguments. It takes 2 arguments: an integer that holds the initial height of the rectangle and an integer that holds the initial width of the rectangle. As with the default constructor, the initialization should be done by passing the arguments to the setDimension method.
Methods
void setDimensions( int newHeight, int newWidth )
This is a public method that changes the dimensions of a Rectangle object. It takes 2 arguments: an integer that holds the new height of the rectangle and an integer that holds the new width of the rectangle. It returns nothing.
If the passed in height argument (newHeight in the header above) is less than 1, then the height data member should be set to 1. Otherwise, the passed in height argument should be used to change the height data member. If the passed in width argument (newWidth in the header above) is less than 1, then the width data member should be set to 1. Otherwise, the passed in width argument should be used to change the width data member.
int getHeight()
This is a public method that returns the height of the rectangle. It takes no argument. It returns an integer, which is the height data member.
int getWidth()
This is a public method that returns the width of the rectangle. It takes no argument. It returns an integer, which is the width data member.
void getDimensions( int &heightRef, int &widthRef )
This is a public method that passes back, using reference arguments, the height and width of the rectangle. It takes two arguments: a reference to an integer to pass back the height and a reference to an integer to pass back the width of the rectangle. It returns nothing.
void draw()
This is a public method that displays the rectangle "drawn" in hashtags (pound signs). It takes no argument and returns nothing.
For example, if a Rectangle object has height of 4 and a width of 12, then this method would display:
############ # # # # ############
void display()
This is a public method that displays a rectangle by displaying the dimensions (height and width) and drawing the rectangle in hashtags. It takes no argument and returns nothing.
This method should call the draw method to draw the rectangle in hashtags.
For example, if a Rectangle object has height of 4 and a width of 12, then this method would display:
Height: 4 Width: 12 ############ # # # # ############
bool isSquare()
This is a public method that determines if a rectangle is a square. It takes no argument. It returns a boolean value.
A rectangle is considered a square if the height and width are equal. If the height is equal to the width, then return true. Otherwise, return false.
bool isEqual( Rectangle otherRect )
This is a public method that determines if two Rectangle objects are equal. It takes 1 argument: a Rectangle object that will be used in the comparison. It returns a boolean value.
Two Rectangle objects are considered equal if their heights and widths are equal. If the current instance's height is equal to the passed in Rectangle object's (otherRect in the header above) height AND the current instance's width is equal to the passed in Rectangle object's width, then return true. Otherwise, return false.
The following condition will compare the current instance's height with the passed in Rectangle object's height:
height == otherRect.height |____| |______________| | | current passed in Rectangle's instance height data height member data member
Driver Program
A driver program that will test all of the methods can be found at:
http://faculty.cs.niu.edu/~byrnes/csci240/pgms/240pgm10driver.cpp
Programming Requirements
Each method must have a documentation box like a function.
Hand in a copy of the driver program that includes the class definition and methods using Blackboard.
Output
*** Test 1: display the first Rectangle object *** Height: 10 Width: 32 ################################ # # # # # # # # # # # # # # # # ################################ *** Test 2: display ONLY the height of the first Rectangle object *** The height of the rectangle is 10 *** Test 3: display ONLY the width of the second Rectangle object *** The width of the rectangle is 8 *** Test 4: get the dimensions of the third Rectangle object *** The height of the rectangle is 1 The width of the rectangle is 1 After changing the dimensions... The height of the rectangle is 12 The width of the rectangle is 12 *** Test 5: are the third and fourth Rectangle objects squares? *** The third rectangle is a square. This fourth rectangle is NOT a square. *** Test 6a: are the fourth and first Rectangle objects equal? *** The fourth rectangle is NOT equal to the first rectangle. *** Test 6b: are the fourth and fifth Rectangle objects equal? *** The fourth rectangle is equal to the fifth rectangle. *** Test 7: draw the fourth and fifth Rectangle objects *** The fourth Rectangle object ################################# # # ################################# The fifth Rectangle object ################################# # # #################################
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started