Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include using namespace std; class rect { private: int length; int width; public: void set_length(int l) { length = 0; } // Fix this void

image text in transcribed

#include using namespace std;

class rect { private: int length; int width; public: void set_length(int l) { length = 0; } // Fix this void set_width(int w) { width = w; } int get_length() { return length; } int get_width() { return 0; } // Fix this int area() { return length * width; } int perimeter() { return 0; } // Fix this void print() { // Add print code here. return; } };

You are given incomplete code for a rectangle class. As given, this code compiles but does not all functions are implemented. You are to complete the following . The set length0 method currently sets the length of the rectangle to 0. Fix this to set the length to the passed in parameter. See the warking set width for assistance The get widthO method currently returis O. Fix it to return the width of the rectangle. See the working get length0 for assistance. . The area method works correctly, but the parameter) method does not. It just returns 0. Make the perimeter) method compute and return the perimeter of the rectangle object. The print) methad currently does nothing. Using cout, make the print0 method print out the length and width of the rectangle as shown in the sample runs below. A ain function is provided for you to check the methods in the rect class. Sample runs are below. User input is in bold italics. Sample run 1: Enter length and width for rectl: 4 3 Area of rectangle 1 is:12 Perimeter of rectangle 1 is: 14 Length: 4 Width: 3 Sample run 2: Enter length and width for recti: 2 7 Area of rectangle 1 is: 14 Perimeter of rectangle 1 is: 18 Length: 2 Width: 7 YOUR ANSWER Start tour Hw more about handling STDIN and STDOUT in other langua Original Code C

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions