-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path08_rectangle.cpp
84 lines (67 loc) · 1.78 KB
/
08_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
72
73
74
75
76
77
78
79
80
81
82
83
84
// // Define a class Rectangle and define an instance member function to find the area of the rectangle.
// // Header files
#include <iostream>
// // use namespace
using namespace std;
// // define class Rectangle
class Rectangle
{
private:
// // instance member variables
double length, breadth, area = 0;
public:
// // instance member function to set length of rectangle
void setLength(int l)
{
length = l;
}
// // instance member function to set breadth of rectangle
void setBreadth(int b)
{
breadth = b;
}
// // instance member function to set dimensions of rectangle
void setDimensions(int l, int b)
{
setLength(l);
setBreadth(b);
}
// // instance member function to get length of rectangle
double getLength(int l)
{
return length;
}
// // instance member function to get breadth of rectangle
double getBreadth(int b)
{
return breadth;
}
// // instance member function to calculate area of rectangle
double calculateArea()
{
area = length * breadth;
return area;
}
// // instance member function to get the area of rectangle
double getArea()
{
return area;
}
};
// // Main Function Start
int main()
{
Rectangle rec1; // create object of Rectangle
double l, b, area;
// // Get length and breadth of a rectangle to find its area
cout << "\nEnter Length and Breadth of A Rectangle => ";
cin >> l >> b;
rec1.setDimensions(l, b); // set dimensions of rectangle
area = rec1.calculateArea(); // find area
// // display area of rectangle
cout << "\nArea of Rectangle => " << area;
cout << endl; // Add new line
cin.ignore();
return 0;
}
// // Main Function End