-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass#3 function rectangle.cpp
More file actions
36 lines (30 loc) · 1006 Bytes
/
Copy pathclass#3 function rectangle.cpp
File metadata and controls
36 lines (30 loc) · 1006 Bytes
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
#include <iostream>
using namespace std;
class Rectangle { //Rectangle -------- class name
private:
double length, width;
public:
// Constructor to initialize the Rectangle object with length and width
Rectangle(double len, double wid): length(len), width(wid)
{
}
double Area() { // function for the area
return length * width; // Formula for area
}
double Perimeter() { // function for the perimeter
return 2 * (length + width); // Formula for perimeter
}
};
int main() {
double length, width;
cout<<"The length of the rectangle is: ";
cin>>length;
cout<<"The width of the rectangle is: ";
cin>>width;
Rectangle r(length,width); // Create a r object with the provided length and width
double area = r.Area(); //area using the r object
cout<<"Area: " <<area<<endl;
double perimeter = r.Perimeter(); //perimeter using the r object
cout<<"Perimeter: " <<perimeter<<endl;
return 0;
}