pgrm_005.cpp ​
Metadata ​
- Author — Amit Dutta (amitdutta4255@gmail.com)
- Last updated — 29 Jun 2026
- License — MIT
Problem Statement ​
Problem Statement
Write a program to calculate area and perimeter of a rectangle.
Source Code ​
Printing the code
To print this file, open it on GitHub and click Raw before printing, or use the Download Raw button above and print directly from that page.
cpp
#include<iostream>
using namespace std;
class rectangle {
private:
double len, bre;
public:
rectangle() {
len = 0;
bre = 0;
}
void getData() {
cout << "Enter the length: ";
cin >> len;
cout << "Enter the breadth: ";
cin >> bre;
}
double getArea() {
return len * bre;
}
double getPeri() {
return 2 * (len + bre);
}
void display() {
cout << "Area: " << getArea() << endl;
cout << "Perimeter: " << getPeri();
}
~rectangle() {}
};
int main() {
rectangle rec;
rec.getData();
rec.display();
return 0;
}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
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