-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPerimeter.cpp
69 lines (58 loc) · 1.13 KB
/
Perimeter.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
#include<iostream>
using namespace std;
class Perimeter
{
float p;
public:
Perimeter()
{
p = 0.0;
}
void calc(float, float);
void display();
};
void Perimeter ::calc(float a, float b)
{
p = 2 * (a + b);
}
void Perimeter ::display()
{
cout << " = " << p << endl;
}
class Square : public Perimeter
{
float a;
public:
Square(float x)
{
a = x;
}
void show();
};
void Square ::show()
{
calc(a, a);
cout << "\nPerimeter of Square is ";
display();
}
int main()
{
float a;
Square sq(5);
sq.show();
cout << "-------------------------------------------------";
cout << "\nEnter side of a square : ";
cin >> a;
Square sq2(a);
sq2.show();
cout << "-------------------------------------------------";
float l, b;
cout << "\nEnter length and breadth of rectangle : \n";
cin >> l >> b;
Perimeter p;
cout << "Perimeter of rectangle is ";
p.calc(l, b);
p.display();
cout << "-------------------------------------------------\n";
return 0;
}