-
Notifications
You must be signed in to change notification settings - Fork 0
/
rectangleusingclasses.cpp
59 lines (56 loc) · 1.15 KB
/
rectangleusingclasses.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
//Program to define member f'n of a class outside a class
#include<iostream>
using namespace std;
template <class T>
class Rectangle
{
T length;
T breadth;
public:
Rectangle() {length=breadth=1;}
Rectangle(T l, T b){ length=l; breadth=b;}
T area();
T perimeter();
void manipulators(T l, T b);
~Rectangle();
};
template <class T>
T Rectangle <T>::area()
{
return length*breadth;
}
template <class T>
T Rectangle <T> ::perimeter()
{
return 2*(length+breadth);
}
template <class T>
void Rectangle<T>::manipulators(T l, T b)
{
length=l;
breadth=b;
}
template <class T>
Rectangle<T>::~Rectangle()
{
cout<<"\nDestructor is called.";
}
int main()
{
int n,l,b;
cout<<"\nEnter the number: ";
cin>>n;
Rectangle <float>r[n];
for(int i=0;i<n;i++)
{
cout<<"\n\n-----#"<<i+1<<"-----";
cout<<"\nEnter the length: ";
cin>>l;
cout<<"\nEnter the breadth: ";
cin>>b;
r[i].manipulators(l,b);
cout<<"\nThe area is: "<<r[i].area();
cout<<"\nThe perimeter is: "<<r[i].perimeter();
}
return 0;
}