-
Notifications
You must be signed in to change notification settings - Fork 0
/
rectangle.cpp
72 lines (69 loc) · 1.31 KB
/
rectangle.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include<iostream>
using namespace std;
class Rectangle{
float length, width, thelength, thewidth, a, p;
public:
rectangle()
{
setlength(1.0);
setwidth(1.0);
}
rectangle(float thelength, float thewidth)
{
setlength(thelength);
setwidth(thewidth);
}
void setlength(float thelength);
void setwidth(float thewidth);
int getlength();
int getwidth();
void area();
void perimeter();
void display();
};
void Rectangle::setlength(float thelength)
{
length = ( thelength > 0.0 && thelength < 20.0 ? thelength : 1.0 );
}
void Rectangle::setwidth(float thewidth)
{
width = ( thewidth > 0 && thewidth < 20.0 ? thewidth : 1.0 );
}
int Rectangle::getlength()
{
return length;
}
int Rectangle::getwidth()
{
return width;
}
void Rectangle::area()
{
a=length*width;
}
void Rectangle::perimeter()
{
p=(2*(length+width));
}
void Rectangle::display()
{
cout<<"\nThe length of the rectangle is: "<<length;
cout<<"\nThe width of the rectangle is: "<<width<<endl;
cout<<"\nArea of rectangle: "<<a;
cout<<"\nPerimeter of rectangle: "<<p;
}
int main()
{
float thelength, thewidth;
Rectangle r;
cout<<"\nEnter length and width of rectangle:"<<endl;
cin>>thelength>>thewidth;
r.setlength(thelength);
r.setwidth(thewidth);
r.getlength();
r.getwidth();
r.area();
r.perimeter();
r.display();
return 0;
}