-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocessData.cpp
More file actions
260 lines (224 loc) · 6.91 KB
/
processData.cpp
File metadata and controls
260 lines (224 loc) · 6.91 KB
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
/* Created by Nguyen Duc Dung on 2019-09-03.
* =========================================================================================
* Name : processData.cpp
* Author : Duc Dung Nguyen
* Email : nddung@hcmut.edu.vn
* Copyright : Faculty of Computer Science and Engineering - HCMUT
* Description : Implementation of main features in the assignment
* Course : Data Structure and Algorithms - Fall 2019
* =========================================================================================
*/
#include "processData.h"
#include "dbLib.h"
#include <cstring>
/* TODO: You can implement methods, functions that support your data structures here.
* */
using namespace std;
void Initialization() {
// If you use global variables, please initialize them explicitly in this function.
}
void Finalization() {
// Release your data before exiting
}
void ProcessRequest(const char* pRequest, void* pData, void* &pOutput, int &N) {
// TODO: Implement this function for processing a request
// NOTE: You can add other functions to support this main process.
// pData is a pointer to a data structure that manages the dataset
// pOutput is a pointer reference. It is set to nullptr and student must allocate data for it in order to save the required output
// N is the size of output, must be a non-negative number
TDataset* p = static_cast <TDataset*>(pData);
if (strcmp("CL",pRequest)==0) {
cout << pRequest << ":";
cout << ' ' << p->CL() << endl;
}
///////////////////////////////////////////////////////////////////////////////
else if (pRequest[0] == 'C' && pRequest[1] == 'L' && pRequest[2] == ' ') {
int i = 3;
string req = "";
while (pRequest[i] != '\0') {
req += pRequest[i];
i++;
}
cout << pRequest << ":" << ' ';
p->CLC(req);
}
////////////////////////////////////////////////////////////////////////////////
else if (pRequest[0] == 'L' && pRequest[1] == 'S' && pRequest[2] == 'C' && pRequest[3] == ' ') {
int i = 4;
string req = "";
while (pRequest[i] != '\0') {
req += pRequest[i];
i++;
}
cout << pRequest << ":";
p->LSC(req);
}
///////////////////////////////////////////////////////////////////////////////////
else if (pRequest[0] == 'L' && pRequest[1] == 'L' && pRequest[2] == 'C' && pRequest[3] == ' ') {
int i = 4;
string req = "";
while (pRequest[i] != '\0') {
req += pRequest[i];
i++;
}
cout << pRequest << ":";
p->LLC(req);
}
//////////////////////////////////////////////////////////////////////////////////////////
else if (pRequest[0] == 'L'&&pRequest[1] == 'S'&&pRequest[2] == 'L' && pRequest[3] == ' '){
int i = 4, number = 0;
string req = "";
while (pRequest[i] != '\0') {
req += pRequest[i];
i++;
}
int k = 0;
int len = req.length();
while (k < len) {
number += int( (req[k] - 48)*pow(10,len - k-1));
k++;
}
cout << pRequest << ":";
p->LSL(number);
}
///////////////////////////////////////////////////////////////////////////////////
else if (pRequest[0] == 'F' && pRequest[1] == 'C' && pRequest[2] == ' ') {
int i = 3;
string req = "";
while (pRequest[i] != '\0') {
req += pRequest[i];
i++;
}
cout << pRequest << ":" <<' ' <<p->FC(req) <<endl;
}
//////////////////////////////////////////////////////////////////////////////////
else if (pRequest[0] == 'F' && pRequest[1] == 'S' && pRequest[2] == ' ') {
int i = 3;
string req = "";
while (pRequest[i] != '\0') {
req += pRequest[i];
i++;
}
cout << pRequest << ":" << ' ' << p->FS(req) << endl;
}
//////////////////////////////////////////////////////////////////////////////////
else if (pRequest[0] == 'S' && pRequest[1] == 'L' && pRequest[2] == 'P' && pRequest[3] == ' ') {
int i = 4;
string req1 = "";
string req2 = "";
while (pRequest[i] != ' ') {
req1 += pRequest[i];
i++;
}
i++;
while (pRequest[i] != '\0') {
req2 += pRequest[i];
i++;
}
int k = 0,id1=0,id2=0;
int len = req1.length();
while (k < len) {
id1 += int((req1[k] - 48)*pow(10, len - k - 1));
k++;
}
k = 0;
int len2 = req2.length();
while (k < len2) {
id2 += int((req2[k] - 48)*pow(10, len2 - k - 1));
k++;
}
cout << pRequest << ":" << ' ' << p-> SLP(id1,id2) << endl;
}
//////////////////////////////////////////////////////////////////////////////////
else if (pRequest[0] == 'R' && pRequest[1] == 'S' && pRequest[2] == ' ') {
int i = 3;
string req = "";
while (pRequest[i] != '\0') {
req += pRequest[i];
i++;
}
int k = 0, id1 = 0;
int len = req.length();
while (k < len) {
id1 += int((req[k] - 48)*pow(10, len - k - 1));
k++;
}
cout << pRequest << ":" << ' ' << p->RS(id1) << endl;
}
//////////////////////////////////////////////////////////////////////////////////
else if (pRequest[0] == 'R' && pRequest[1] == 'S' && pRequest[2] == 'L' && pRequest[3] == ' ') {
int i = 4;
string req1 = "";
string req2 = "";
while (pRequest[i] != ' ') {
req1 += pRequest[i];
i++;
}
i++;
while (pRequest[i] != '\0') {
req2 += pRequest[i];
i++;
}
int k = 0, id1 = 0, id2 = 0;
int len = req1.length();
while (k < len) {
id1 += int((req1[k] - 48)*pow(10, len - k - 1));
k++;
}
k = 0;
int len2 = req2.length();
while (k < len2) {
id2 += int((req2[k] - 48)*pow(10, len2 - k - 1));
k++;
}
cout << pRequest << ":" << ' ' << p->RSL(id1, id2) << endl;
}
//////////////////////////////////////////////////////////////////////////////////
else if (pRequest[0] == 'I' && pRequest[1] == 'S' && pRequest[2] == 'L' && pRequest[3] == ' ') {
int staid = 0, lineid = 0, idx = 0;
string text = "";
stringstream s;
s << pRequest;
getline(s, text, ' ');
s >> staid;
s >> lineid;
s >> idx;
cout << pRequest << ":" << ' ' << p->ISL(staid,lineid,idx) << endl;
}
//////////////////////////////////////////////////////////////////////////////////
else if (pRequest[0] == 'U' && pRequest[1] == 'S' && pRequest[2] ==' ') {
int i = 3;
string req1 = "";
string req2 = "";
while (pRequest[i] != ' ') {
req1 += pRequest[i];
i++;
}
i++;
while (pRequest[i] != '\0'){
req2 += pRequest[i];
i++;
}
int k = 0, id=0;
int len = req1.length();
while (k < len) {
id += int((req1[k] - 48)*pow(10, len - k - 1));
k++;
}
cout << pRequest << ":" << ' ' << p->US(id, req2) << endl;
}
//////////////////////////////////////////////////////////////////////////////////
else if (pRequest[0] == 'I' && pRequest[1] == 'S' && pRequest[2] == ' ') {
int i = 3;
string req = "";
while (pRequest[i] != '\0'){
req += pRequest[i];
i++;
}
cout << pRequest << ":" << ' ' << p->IS(req) << endl;
}
//////////////////////////////////////////////////////////////////////////////////
else {
cout << pRequest << ":" << " error\n";
}
}