Must compile using codeblocks on c++.

1. Download Lab.cpp, Rectangle.cpp and Rectangle.h files. read the code skeleton and add your own code according to the comments. To download the file, right-click on the hyperlink, pick “Save Target as”.

2. Follow this order to complete the project: complete Rectangle.h first, then Rectangle.cpp, last finish the Lab.cpp

3. To make the program to work, you will need to create a project, then add above three source codes inside the project before you can run and test your program. Click here for instruction on how to create a project under Code::Blocks

Lab.cpp (Code Skeleton)

//———————————————————————————-

// FILENAME:        Lab9.cpp

// SPECIFICATION:   This program is the driver's program that //uses the Rectangle class

//                         It creates Rectangle objects and //works on these objects.

// INSTRUCTIONS:    Read the following code skeleton and add //your own code

//When you see //—- that is where you need to add code.

//————————————————————————————-

//****************** PLEASE COMPLETE CODING Rectangle.h & Rectangle.cpp FIRST *********

#include

//Include the Rectangle.h header file below

//—-

using namespace std;

int main()

{

     //Create Rectangle object r1 using the default constructor defined in Rectangle.cpp

     //NOTE how the object is created without passing any values.

     Rectangle r1;

     //Now let user enter Rectangle object r2's length & width from keyboard

     int r2Length, r2Width;

     cout

     //get the input and save it inside variable r2Length

     //—-

     cout

     //get the input and save it inside variable r2Width

     //—-

     //Now Create Rectangle object r2 using the overloaded constructor that takes two integer arguments.

     //The actual arguments should be r2Length and r2Width which you got above

     //example: Rectangle r2(4,7);

     //—-

    cout

     //Lets print the details of Rectangles r1

     //Notice we can use toString() function to get the length and width of the rectangle

     cout

     //Lets print the details of Rectangles r2 by calling the toString() function similar as above

     //—-

     //Lets print the Perimeter of Rectangle r1

     cout

     //Print the Perimeter of Rectangle r2

     //—-

    cout

     //Lets print the area of Rectangle r1

     cout

     //Print the area of Rectangle r2

     //—-

     //lets change the length and width of rectangle r1 from (length=0,width=0) to (length=3,width=4)

     r1.setLength(3);

     //Change the width of r1 to 4

     //—-

    cout

     //Lets the print the new details of Rectangle r1

     cout

     //Calculate the new Perimeter of r1 and print it as, for example

     //'Rectangle r1 Perimeter = 14'

     //—-

     //Calculate the new area of r1 and print it as, for example

     //'Rectangle r1 Area = 12'

     //—-

    cout

     //Lets use the isSquare() function to check if the Rectangles r1 and r2 are squares

     if(r1.isSquare())

           cout

     else

           cout

     //Check if Rectangle r2 is a square and print if it so (similar to above)

     //—-

     return 0;

}

Rectangle.cpp (Code Skeleton)

//—————————————————————————

// FILENAME:        Rectangle.cpp

// SPECIFICATION:   This file contains the definitions of the //Rectangle functions.

//                         The prototypes of the functions are //declared in the Rectangle.h

//                  Check Rectangle.h to make sure you define //every member functions!

// INSTRUCTIONS:    Read the following code skeleton and add //your own code

//                  according to the comments. Ask your TA or //your class-

//                  mates for help and/or clarification. When //you see //—- that is where you need to add code.

//————————————————————————-

//****************** PLEASE COMPLETE CODING Rectangle.h FIRST ********

//Include the Rectangle.h as follows. Since it is a user defined header

//we use “Rectangle.h” instead of

#include”Rectangle.h”

#include

using namespace std;

//*****************************************************************

//The default constructor will initialize length & width to 0

//Note the scope operator :: is used here, general format to use it

// returnDataType className::functionName(formal_parameter_list)

Rectangle::Rectangle()

{

     length = 0;

     width = 0;

}

//*****************************************************************

//Overloaded constructor

//This constructor initialize the rectangle's length & width with the parameterized

//variable – newL & newWidth

Rectangle::Rectangle(int newL, int newWidth)

{

     length = newL;

     //initialize the width

     //—-

}

//*****************************************************************

//Accessor – getter for member variable length

int Rectangle::getLength()

{

     return length;

}

//*****************************************************************

//Check Rectangle.h header file to write a getter

//for member variable width

//—-

//—-

//*****************************************************************

//Mutator – setter for member variable length

void Rectangle::setLength(int newL)

{

     length = newL;

}

//*****************************************************************

//Check Rectangle.h header file to write a setter

//for member variable width

//—-

//—-

//*****************************************************************

//toString() function print out every member variables

string Rectangle::toString()

{

    stringstream sout;

    sout

        

    return sout.str();

}

//*****************************************************************

// Method that calculates the Perimeter of the Rectangle

// Perimeter of Rectangle is 2*(length + width)

int Rectangle::getPerimeter()

{

     //—-

}

//*****************************************************************

// Method that calculates the area of the Rectangle and returns it

// Area of Rectangle is length*width

// check header file to give a complete definition of the

//—-

//—-

//*****************************************************************

// Method that checks if the Rectangle is a square and returns the

// result as a boolean. A rectangle is a square when its length & width

// equal

//—-

//—-

Rectangle.h (Code Skeleton)

/*————————————————————————–

// FILENAME:        Rectangle.h

// SPECIFICATION:   This is the Header file for the Rectangle //class. It declares

//                  the data for the class and also the //prototypes of all

//                  the member functions.

// INSTRUCTIONS:    Study the following code skeleton and add //your own code according to the comments.

//                  mates for help and/or clarification. When //you see //—- that is where you need to add code.

//————————————————————————-*/

#include

using namespace std;

class Rectangle

{

     private:

           //Member variables. Every Rectangle object has length and width as the data.

           int length;

           int width;

     //Pick the correct visibility modifier for the following member functions

     //—-

           //Constructors

           //NOTE: (1)Constructor has the same name as the class's name

           //      (2)Constructor does not have any return data type, not even void.

           //      (3)The purpose of a constructor is to initialize every member variable

           Rectangle(int, int);

           Rectangle();

           //Accessor – getter for member variable length

           int getLength();

           //Accessor – declare the getter for member variable width

        //—-

           //Mutator – setter for member variable length

           void setLength(int);

           //Mutator – declare the setter for member variable width

           //—-

        //toString function

        string toString();

           //Other functions for a Rectangle

           int getPerimeter();

           int getArea();

           bool isSquare();

};

Test Case input:

6

6

Test Case Output:

Rectangle r1

Length: 0

Width: 0

Rectangle r2

Length: 6

Width: 6

Rectangle r1 Perimeter = 0

Rectangle r2 Perimeter = 24

Rectangle r1 Area = 0

Rectangle r2 Area = 36

After changing r1's length & width

Rectangle r1

Length: 3

Width: 4

Rectangle r1 Perimeter = 14

Rectangle r1 Area = 12

Rectangle r1 is NOT a square

Rectangle r2 is a square

"Get 15% discount on your first 3 orders with us"
Use the following coupon
"FIRST15"

Order Now