-
Notifications
You must be signed in to change notification settings - Fork 0
/
Metrics.cpp
94 lines (70 loc) · 2.58 KB
/
Metrics.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*This GitHub code has been crafted by TIRTH JIGNESHKUMAR DALAL from CHARUSAT UNIVERSITY with a focus on simplifying and streamlining processes.
It offers a user-friendly approach to solving problems, ensuring accessibility and ease of use for all stakeholders.
The code demonstrates a commitment to clarity and efficiency, providing intuitive solutions to complex challenges.
With clear documentation and concise implementation, this code fosters collaboration and empowers users to navigate and contribute effectively.
It reflects a dedication to enhancing the developer experience and fostering a welcoming environment for innovation and growth.*/
#include <iostream>
#include <iostream>
#include <cmath>
class Circle {
private:
static int totalObjects;
static int activeObjects;
static int deletedObjects; // Corrected variable name
double radius;
public:
Circle() : radius(1.0) {
totalObjects++;
activeObjects++;
}
explicit Circle(double r) : radius(r) {
totalObjects++;
activeObjects++;
}
Circle(const Circle& other) : radius(other.radius) {
totalObjects++;
activeObjects++;
}
~Circle() {
activeObjects--;
deletedObjects++;
}
void setRadius(double r) {
radius = r;
}
double getRadius() const {
return radius;
}
double area() const {
return M_PI * radius * radius;
}
static int getTotalObjects() {
return totalObjects;
}
static int getActiveObjects() {
return activeObjects;
}
static int getDeletedObjects() {
return deletedObjects;
}
};
int Circle::totalObjects = 0;
int Circle::activeObjects = 0;
int Circle::deletedObjects = 0;
int main() {
Circle* circle1 = new Circle();
Circle* circle2 = new Circle(20.0);
Circle* circle3 = new Circle(*circle2);
std::cout << "Area of circle1: " << circle1->area() << std::endl;
std::cout << "Area of circle2: " << circle2->area() << std::endl;
std::cout << "Area of circle3: " << circle3->area() << std::endl;
std::cout << "Total circle objects created: " << Circle::getTotalObjects() << std::endl;
std::cout << "Active circle objects: " << Circle::getActiveObjects() << std::endl;
delete circle1;
delete circle2;
delete circle3;
std::cout << "Deleted circle objects: " << Circle::getDeletedObjects() << std::endl;
std::cout << "Total circle objects created: " << Circle::getTotalObjects() << std::endl;
std::cout << "Active circle objects: " << Circle::getActiveObjects() << std::endl;
return 0;
}