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

(Rectangle Class) Create a class Rectangle with attributes length and width, eac

ID: 3535069 • Letter: #

Question


(Rectangle Class) Create a class Rectangle with attributes length and width, each of which
defaults to 1. Provide member functions that calculate the perimeter and the area of the rectangle. Also, provide set and get functions for the length and width attributes. The set functions should verify that length and width are each floating-point numbers larger than 0.0 and less than 20.0.

- Three file must be submitted. two cpp files and one h file.
- Make sure to use #ifndef
- Add destructor function for your class which will print out "destructor function called."

Explanation / Answer

#include<iostream.h>

class rectangle

{

float length,breath;

public:

rectangle()

{

length=1;

breath=1;

}

void set(flaot a,float b)

{

if(a>0.0 &&a<20.0)

length=a;

if(b>0.0&&b<20.0)

breath=b;

else

cout<<"enter correct dimension";

}

float getlength()

{

return length;

}

float getbreath()

{

return breath;

}

void perimeter()

{

float p;

p=2*(length+breath);

cout<<"Perimeter is "<<p;

}

void area()

{

flaot area;

area=length*breath;

cout<<"area is "<<area;

}

~rectangle()

{

cout<<"destructor function is called";

}

};

void main()

{

reactangle a;

float l,b;

cout<<"enter length and breath of rectangle";

cin>>l>>b;

a.set(l,b);

a.perimeter();

a.area();

l=getlength();

b=getbreath();

}