Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Construct a class named rectangle that has floating point data members named len

ID: 3633910 • Letter: C

Question

Construct a class named rectangle that has floating point data members named length and width.
The class should have a member functions named perimeter( ) and area( ) to calculate the perimeter and area of a rectangle, a member function named setdata( ) to set a rectangle’s length and width, and a member function named showdata( ) that display’s a rectangle’s length, width, perimeter, and area.

Include the Rectangle class constructed in your C++ program. Your program should ask the user to input the length and width of a rectangle then use the function setdata to set the length and width. It should use the methods or functions perimeter( ), and area( ) to calculate the perimeter and area , finally display the length, width, perimeter, and area using the showdata( )

User hits Escape key to exit the program, otherwise asks data for next rectangle.
ASC code for ESC is 27

Use the following as guideline
// define the class
Class Rectangle
{
Private:
float length
float width
public:
rectangle(); //constructor
void setdata(float, float); // function to set the values
float perimeter(); // function to calculate perimeter. Formula: (2*length+ 2*width)

//other functions declarations go here. The formula for area is (l*w)
};

You should implement each member function as a separate function and test your program with the main function as follows:

Int main()
{
rectangle myrectangle;
float l, w; perim, ara
cin<< l;
cin<<w;
// call setdata to transfer the data
// call functions to calculate and return perimeter, and area. Call function to display data
//
Return 0
}

I'm especially having trouble with the "Esc" to exit part. Someone please HELP!

Explanation / Answer

Hi This program surely help you //Header files #include #include //create class Rectangle class Rectangle{ private: //Declare variables float length; float width; public: //create constructor Rectangle() { length=0; width=0; } //Define methods void setdata(float,float); float perimeter(); float area(); void showdata(); };//end class //Method setdata stores l and w values void Rectangle :: setdata(float l,float w) { length=l; width=w; } //function returns the perimeter value float Rectangle :: perimeter() { return 2*(length*width); } //function returns the area value float Rectangle :: area() { return length*width; } //function displays the data void Rectangle :: showdata() { cout