Guest User

Untitled

a guest
Dec 22nd, 2019
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.61 KB | None | 0 0
  1. /* Created by Nguyen Duc Dung on 2019-09-03.
  2. * =========================================================================================
  3. * Name : processData.cpp
  4. * Author : Duc Dung Nguyen
  5. * Email : [email protected]
  6. * Copyright : Faculty of Computer Science and Engineering - HCMUT
  7. * Description : Implementation of main features in the assignment
  8. * Course : Data Structure and Algorithms - Fall 2019
  9. * =========================================================================================
  10. */
  11.  
  12. #include "processData.h"
  13. #include "dbLib.h"
  14. /* TODO: You can implement methods, functions that support your data structures here.
  15. * */
  16. int* temp;
  17. using namespace std;
  18.  
  19. template <typename T>
  20. void PrintReqOutput(const char* pRequest, T* pOutput, int N) {
  21. cout << pRequest << ":";
  22. if (pOutput == nullptr) {
  23. cout << " error\n";
  24. return;
  25. }
  26. for (int i = 0; i < N; ++i) {
  27. cout << ' ' << *pOutput++;
  28. }
  29. cout << '\n';
  30. }
  31.  
  32. void Initialization() {
  33. // If you use global variables, please initialize them explicitly in this function.
  34. }
  35.  
  36. void Finalization() {
  37. // Release your data before exiting
  38. }
  39.  
  40. void ProcessRequest(const char* pRequest, void* pData, void*& pOutput, int& N) {
  41. // TODO: Implement this function for processing a request
  42. // NOTE: You can add other functions to support this main process.
  43. // pData is a pointer to a data structure that manages the dataset
  44. // pOutput is a pointer reference. It is set to nullptr and student must allocate data for it in order to save the required output
  45. // N is the size of output, must be a non-negative number
  46. int* temp = new int(0);
  47. TDataset* ptr = static_cast<TDataset*>(pData);
  48. N = 1;
  49. string req = pRequest;
  50. if (req == "CL")
  51. *temp = GetNumOfLine(ptr->LLine);
  52. else if (req[0] == 'C' && req[1] == 'L')
  53. {
  54. string str_temp = req.substr(3);
  55. *temp = countLinesInCity(ptr, str_temp);
  56. }
  57. else if (req[0] == 'L' && req[1] == 'S' && req[2] == 'C')
  58. {
  59. string str_temp = req.substr(4);
  60. temp = listStationInCity(ptr, str_temp);
  61. }
  62. else if (req[0] == 'L' && req[1] == 'L' && req[2] == 'C')
  63. {
  64. string str_temp = req.substr(4);
  65. temp = listLinesInCity(ptr, str_temp);
  66. }
  67. else if (req[0] == 'L' && req[1] == 'S' && req[2] == 'L')
  68. {
  69. string str_temp = req.substr(4);
  70. temp = listStaionLines(ptr, str_temp);
  71. }
  72. else if (req[0] == 'F' && req[1] == 'C')
  73. {
  74. string str_temp = req.substr(3);
  75. *temp = findIDCity(ptr, str_temp);
  76. }
  77. else if (req[0] == 'F' && req[1] == 'S')
  78. {
  79. string str_temp = req.substr(3);
  80. *temp = findStationID(ptr, str_temp);
  81. }
  82. else if (req[0] == 'S' && req[0] == 'L' && req[0] == 'P')
  83. {
  84. int i = 0, t = 0;
  85. int arr[2];
  86. string str_temp;
  87. while (i < req.length())
  88. {
  89. if (req[i] == ' ')
  90. {
  91. i++;
  92. while (req[i] != ' ')
  93. {
  94. str_temp += req[i];
  95. i++;
  96. }
  97. arr[t++] = stoi(str_temp);
  98. str_temp = "";
  99. }
  100. i++;
  101. }
  102. *temp = findStationFromTrack(ptr, arr[0], arr[1]);
  103. }
  104. else if (req[0] == 'I' && req[1] == 'S' && req[2] != 'L')
  105. {
  106. string str_temp = req.substr(3);
  107. *temp = insertNewStation(str_temp, ptr);
  108. }
  109. else if (req[0] == 'R' && req[1] == 'S' && req[2] != 'L')
  110. {
  111. string str_temp = req.substr(3);
  112. int input = stoi(str_temp);
  113. *temp = removeStation(ptr, input);
  114. }
  115. else if (req[0] == 'U' && req[0] == 'S')
  116. {
  117. int a;
  118. string str_temp;
  119. int i = 0;
  120. while (req[i] != ' ')
  121. {
  122. i++;
  123. }
  124. i++;
  125. while (req[i] != ' ')
  126. {
  127. str_temp = str_temp + req[i];
  128. i++;
  129. }
  130. a = stoi(str_temp);
  131. i++;
  132. str_temp = "";
  133. while (i < req.length())
  134. {
  135. str_temp = str_temp + req[i];
  136. i++;
  137. }
  138. *temp = updateStation(a, str_temp, ptr);
  139. }
  140. else if (req[0] == 'I' && req[1] == 'S' && req[2] == 'L')
  141. {
  142. int a, b, c;
  143. string str_temp;
  144. int i = 0;
  145. while (req[i] != ' ')
  146. i++;
  147. i++;
  148. while (req[i] != ' ')
  149. {
  150. str_temp += req[i];
  151. i++;
  152. }
  153. a = stoi(str_temp);
  154. i++;
  155. str_temp = "";
  156. while (req[i] != ' ')
  157. {
  158. str_temp += req[i];
  159. i++;
  160. }
  161. b = stoi(str_temp);
  162. i++;
  163. str_temp = "";
  164. while (req[i] != ' ')
  165. {
  166. str_temp += req[i];
  167. i++;
  168. }
  169. c = stoi(str_temp);
  170. *temp = insertStationLines(ptr, a, b, c);
  171. }
  172. else if (req[0] == 'R' && req[1] == 'S' && req[2] == 'L')
  173. {
  174. int a, b;
  175. string str_temp;
  176. int i = 0;
  177. while (req[i] != ' ')
  178. i++;
  179. i++;
  180. while (req[i] != ' ')
  181. {
  182. str_temp = str_temp + req[i];
  183. i++;
  184. }
  185. a = stoi(str_temp);
  186. i++;
  187. str_temp = req.substr(i);
  188. b = stoi(str_temp);
  189. *temp = removeStationLines(ptr, a, b);
  190. }
  191. pOutput = temp;
  192. }
Advertisement
Add Comment
Please, Sign In to add comment