Question: PLEASE FOLLOW THIS AND FILL IN THE RECTANGLE.CPP //************************************************************************************************** // FILE: lab09.cpp // // DESCRIPTION: This program draws rectangles of a user specified height and

PLEASE FOLLOW THIS AND FILL IN THE RECTANGLE.CPP

//************************************************************************************************** // FILE: lab09.cpp // // DESCRIPTION: This program draws rectangles of a user specified height and width. // It also diplays the area or each rectagle it draws. // // This lab project illustrates the following C++ concepts: // 1. Writing implementation code for user defined classes. // 2. Declaring and using user defined objects. // // AUTHORS:  ( () // // COURSE: CSE100 Principles of Programming with C++, Spring 2015 // // LAB INFO: Lab Number 9; Date/Time: ; TA:  // // ------------------------------------------------------------------------------------------------- #include  #include  #include  using namespace std; #include "Rectangle.h" //-------------------------------------------------------------------------------------------------- // FUNCTION: int getInt() // // Displays a prompt for the user // Then collects the user's input as an int // // if the user enters a number that is not within the range of min to max, // then display the promt again. // // if the user enters a valid value, // then return that value. //-------------------------------------------------------------------------------------------------- int getInt(string prompt, int min = INT_MIN, int max = INT_MAX) { int value; do { cout << prompt; cin >> value; }while(value < min || value > max); return value; } //-------------------------------------------------------------------------------------------------- // FUNCTION: void displayArea(Rectangle rectangle) // // takes a Rectaqngle object as an argument // Then displays a message showing the area of that rectangle //-------------------------------------------------------------------------------------------------- void displayArea(Rectangle rectangle) { int area = rectangle.getHeight() * rectangle.getWidth(); cout << "This rectangle has an area of " << area << endl; } //-------------------------------------------------------------------------------------------------- // FUNCTION: bool drawAnother() // // Displays a prompt asking the user if they woulf like to draw another rectangle // Then collects the user's input as an string // // if the user enters a string that is not either "yess" or "no", // then display the promt again. // // if the user "yes",then return true, else return false. //-------------------------------------------------------------------------------------------------- bool drawAnother() { string answer; do { cout << "Would you like to raw another rectangle (yes or no) ? "; cin >> answer; }while (answer != "yes" && answer != "no"); return answer == "yes"; } int main() { int height, width; // declare a Rectangle variable and create Rectangle object Rectangle myRectangle; do { // get a height and a width from the user height = getInt("Enter height (1 - 20): ", 1, 20); width = getInt("Enter width (1 - 20): ", 1, 20); // set the height and width attributes for the rectangle object myRectangle.setHeight(height); myRectangle.setWidth(width); // display the rectangle area and draw the rectangle displayArea(myRectangle); myRectangle.draw(); } while (drawAnother()); // ask if user wants to draw another rectangle cout << "Good bye!" << endl; cin.sync(); cin.get(); return 0; } 

This is the Rectangle.cpp

#include "Rectangle.h" #include  using namespace std; //-------------------------------------------------------------------------- // default constructor // initializes both height and width to 1 //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- // parametrized constructor // initializes both height and width // using the values supplied by the arguments initHeight, and initWidth //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- // getHeight member function // returns the value stored in this rectangle's height variable //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- // setHeight member function // assigns the value passed to the newHeight argument to this rectangle's height variable //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- // getWidth member function // returns the value stored in this rectangle's width variable //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- // setWidth member function // assigns the value passed to the newWidth argument to this rectangle's width variable //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- // getArea member function // calculates and returns the area of this rectangle based on its height and width //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- // draw member function // diplays a rectangle made of '*' (asterisks) // that is the hight and the width of this rectangle //-------------------------------------------------------------------------- 

This is the rectangle.h

#pragma once class Rectangle { private: // private variables to store what each car object knows int height; int width; public: // public member functions (methods) to define what each Car object can do // constructors Rectangle(); Rectangle(int initHeight, int initWidth); // GETTERS and SETTERS // getter and setter for height int getHeight(); void setHeight(int newHeight); // getter and setter for width int getWidth(); void setWidth(int newWidth); // member function to calculate and return the area of the rectangle int getArea(); // member function to draw the rectangle on the screen void draw(); }; 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!