Answer to Question #292432 in C++ for Ianidy

Question #292432

Create a class called Rectangle with data members: width, length and area. The class should have functions to allow for setting of both length and width, calculate the area, and retrieve the width, length and area.

1
Expert's answer
2022-02-01T04:12:27-0500
#include<iostream>

using namespace std;




class Rectangle

{

private:

double width;

double length;

double area;

public:

void set_width(double _width)

{

width = _width;

}

void set_length(double _length)

{

length = _length;

}

void set_area()

{

area = 2 * (width + length);

}

double get_width()

{

return width;

}

double get_length()

{

return length;

}

double get_area()

{

return area;

}

};




int main()

{

Rectangle rectangle;

rectangle.set_length(5);

rectangle.set_width(2);

rectangle.set_area();

cout<< rectangle.get_length()<<endl;

cout<<rectangle.get_width()<<endl;

cout<<rectangle.get_area()<<endl;

system("pause");

return 0;

}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

ianidy mugendi
16.11.22, 17:36

great

Leave a comment

LATEST TUTORIALS
New on Blog