forked from arin2002/Hacktoberfest-2022
/
Class main.cpp
76 lines (72 loc) · 1.24 KB
/
Class main.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
#include "Rectangle.h"
#include <iostream>
using namespace std;
// for const members intialize with list initializer as :
Rectangle::Rectangle() : length(0), width(0)
{
cout << "Constructor is called !\n";
}
Rectangle::Rectangle(double l, double w)
{
length = l;
width = w;
cout << "Parametrized constructor is called !\n";
}
Rectangle::~Rectangle()
{
cout << "Destructor is called !";
}
void Rectangle::setLength(double l)
{
length = l;
}
void Rectangle::setWidth(double w)
{
width = w;
}
double Rectangle::getLength()const
{
return length;
}
double Rectangle::getWidth()const
{
return width;
}
double Rectangle::getArea()const
{
return width * length;
}
double Rectangle::getPerimeter()const
{
return 2 * (width + length);
}
void Rectangle::draw()const
{
for (int i = 0; i < length; i++)
{
for (int j = 0; j < width; j++)
{
cout << "*";
}
cout << "\n";
}
}
int main()
{
double l, w;
cout << "Enter length : ";
cin >> l;
cout << "Enter width : ";
cin >> w;
Rectangle a(l, w);//implicit call
Rectangle& adrs = a;
//or(pointer)Rectangle *p=&a then p->getArea();
adrs.setLength(l);
adrs.setWidth(w);
cout << "Area = " << a.getArea();
cout << "\n";
cout << "Perimeter = " << a.getPerimeter();
cout << "\n";
adrs.draw();
return 0;
}