Kat H.

asked • 03/31/21

The Rectangle class has been declared and main makes use of it. Add the function implementations so the code compiles and runs successfully.

The Rectangle class has been declared and main makes use of it. Add the function implementations so the code compiles and runs successfully.


Hint: Every function name is going to need Rectangle:: in front of its name.


Code:


#include <iostream>

using namespace std;


class Rectangle {

public:

Rectangle(double theWidth, double theHeight);

double getWidth();

double getHeight();

double getPerimeter();

double getArea();

void scale(double scaleFactor);


private:

double width;

double height;

};


//Do not modify anything on or above the line below this

//YOUR_CODE_BELOW


//YOUR_CODE


//YOUR_CODE_ABOVE

//Do not modify anything on or below the line above this


int main()

{

//create a rectangle with a width of 10 and a height of 20

Rectangle r1(10, 20);


cout << r1.getWidth() << " " << r1.getHeight() << endl;

cout << r1.getPerimeter() << endl;

cout << r1.getArea() << endl;



//reduce the rectangle to half its former size

r1.scale(0.5);


cout << r1.getWidth() << " " << r1.getHeight() << endl;

cout << r1.getPerimeter() << endl;

cout << r1.getArea() << endl;

}


1 Expert Answer

By:

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.