-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexp9.cpp
79 lines (78 loc) · 1.62 KB
/
exp9.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
#include <iostream>
#include <vector>
#include <set>
using namespace std;
class MyClass
{
private:
int variable1;
float variable2;
char variable3;
public:
void method1()
{
variable1 = 10;
}
void method2()
{
variable2 = 3.14f;
}
void method3()
{
variable3 = 'A';
}
int getVariable1() const
{
return variable1;
}
float getVariable2() const
{
return variable2;
}
char getVariable3() const
{
return variable3;
}
int calculateLCOM() const
{
vector<set<string>> methodSets;
for (const auto &method : {"method1", "method2", "method3"})
{
set<string> methodSet;
methodSet.insert(method);
methodSets.push_back(methodSet);
}
if (variable1 == 10)
{
methodSets[0].insert("method2");
methodSets[0].insert("method3");
}
if (variable2 == 3.14f)
{
methodSets[1].insert("method1");
methodSets[1].insert("method3");
}
if (variable3 == 'A')
{
methodSets[2].insert("method1");
methodSets[2].insert("method2");
}
int disjointSets = 0;
for (const auto &set : methodSets)
{
if (!set.empty())
{
disjointSets++;
}
}
int lcom = methodSets.size() - disjointSets;
return lcom;
}
};
int main()
{
MyClass myObject;
int lcomValue = myObject.calculateLCOM();
cout << "LCOM metric: " << lcomValue << std::endl;
return 0;
}