-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rectangle.cpp
63 lines (46 loc) · 1.17 KB
/
Rectangle.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
//
// Created by Vijay on 14/03/23.
//
#include "Rectangle.h"
#include <iostream>
using namespace std;
void Rectangle::draw() const {
cout << "Drawing a rectangle..." << endl;
cout << "Dimensions: " << width << ", " << height << endl;
}
int Rectangle::getArea() const {
return width * height;
}
int Rectangle::getWidth() const {
return width;
}
void Rectangle::setWidth(int width) {
if(width < 0)
throw invalid_argument("The width can not be negative!");
if(width > 100)
throw out_of_range{"The width can not be greater than 100!"};
this->width = width;
}
int Rectangle::getHeight() const {
return height;
}
void Rectangle::setHeight(int height) {
if(height < 0)
throw invalid_argument("height");
this->height = height;
}
Rectangle::Rectangle(int width, int height) {
objectsCount++;
setWidth(width);
setHeight(height);
}
Rectangle::Rectangle(int width, int height, const string &color) : Rectangle(width, height) {
this->color = color;
}
Rectangle::~Rectangle() {
// cout << "Destructor Called";
}
int Rectangle::objectsCount = 0;
int Rectangle::getObjectsCount() {
return objectsCount;
}