-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
173 lines (146 loc) · 4.76 KB
/
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#include <iostream>
#include "p1.hpp"
#include "p2.hpp"
#include "p3.hpp"
#include "p4.hpp"
#include "p5.hpp"
#include "p6.hpp"
using namespace std;
int main() {
int x;
cout << "First Problem\n"
"Second Problem\n"
"Third Problem\n"
"Fourth Problem\n"
"Fifth Problem\n"
"Sixth Problem\n";
cout << "Your choice: ";
cin >> x;
switch (x) {
case 1: {
LabelGenerator FigureNumbers("figure", 1);
LabelGenerator pointNumbers("p", 0);
cout << "Figure numbers: ";
for (int i = 0; i < 3; i++) {
FigureNumbers.nextlabel();
if (i < 2) {
cout << ", ";
}
}
cout << endl;
cout << "Point numbers: ";
for (int i = 0; i < 5; i++) {
pointNumbers.nextlabel();
if (i < 4) {
cout << ", ";
}
}
cout << endl;
cout << "More figures: ";
for (int i = 0; i < 3; i++) {
FigureNumbers.nextlabel();
if (i < 2) {
cout << ", ";
}
}
cout << endl;
FileLableGenerator figtable("figure", 1, "ttt.txt");
cout << "Figure labels: " << endl;
figtable.nextlabel();
cout << endl;
break;
}
case 2: {
StringSet file("file.txt", false);
StringSet query("Chocolate ice cream, chocolate milk, and chocolate bars.", true);
cout << "Document set from file: ";
file.outputStrings();
cout << "Query set: ";
query.outputStrings();
double similarity = file.computeSimilarity(query);
cout << "Similarity between document and query: " << similarity << endl;
break;
}
case 3: {
string filename;
// Get the input file name from the user
cout << "Enter the name of the text file: ";
getline(cin, filename);
// Open the file
ifstream inputFile(filename);
// Check if the file is opened successfully
if (!inputFile.is_open()) {
cout << "Error opening file: " << filename << endl;
return 1;
}
// Map to store word frequencies
map<string, int> frequencyTable;
// Read the file line by line using a while loop
string line;
while (getline(inputFile, line)) {
// Process each word in the line using a stringstream and while loop
istringstream iss(line);
string word;
while (iss >> word) {
// Clean the word and update the frequency table
string cleanedWord = cleanWord(word);
if (!cleanedWord.empty()) {
frequencyTable[cleanedWord]++;
}
}
}
// Close the file
inputFile.close();
// Display the formatted frequency table
cout << "\nWord Frequency Table:\n";
for (const auto &pair : frequencyTable) {
cout << setw(15) << left << pair.first << ": " << pair.second << endl;
}
break;
}
case 4: {
new_set<int> integer;
new_set<string> strr;
integer.add(5);
integer.add(5);
integer.add(33);
strr.add("hello");
strr.add("hello");
strr.add("world");
integer.display();
strr.display();
new_set<int> neww;
neww.add(5);
neww.add(33);
cout << (neww == integer); // will print 1 referring to true
break;
}
case 5: {
TaskManager T;
T.loadProcessesFromOS();
cout << " 1-Display the process sorted by memory usage \n 2-Display the process sorted by name\n 3-Display the process sorted by ID\n 4-Exit" << endl;
int choice = 0;
while (choice != 4) {
cin >> choice;
switch (choice) {
case 1:
T.sortedByMemoryUsage();
break;
case 2:
T.sortedByName();
break;
case 3:
T.sortedByPID();
break;
}
}
break;
}
case 6: {
Universe u;
u.run(50);
break;
}
}
return 0;
}