Advertisement
Guest User

Untitled

a guest
Dec 9th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.29 KB | None | 0 0
  1. void ConsoleUI::run() // Display "Listi", where you can get information about actions you can make
  2. {
  3.  
  4. //vector<CompScientist>listi;
  5. _service.getDatabase();
  6. //vector<CompScientist>listi;
  7. //_service.saveToList(); //reading from file
  8. cout << "Please enter one of the following commands:" << endl;
  9. cout << "Add - This will add a new computer scientist." << endl;
  10. cout << "List - This will display all computer scientists in the system." << endl;
  11. cout << "Sort - This will sort the list according to your choice" << endl;
  12. cout << "Search - This will search and display a computer scientist or computer." << endl;
  13. cout << "Help - This will display all commands and keywords you need for full function." << endl;
  14. cout << "Quit - This will end the program." << endl;
  15.  
  16. string user_input, search_name, search_option;
  17.  
  18. do
  19. {
  20. cin >> user_input;
  21.  
  22. if(user_input == "add" || user_input == "Add" || user_input == "ADD")
  23. {
  24. string pressed;
  25. cout << "To what table do you want to add?" << endl;
  26. cout << "Input '1' to add Scientist" << endl;
  27. cout << "Input '2' to add Computer" << endl;
  28. cout << "Input '3' to add connections" << endl;
  29. //todo dowhile
  30. cin >> pressed;
  31.  
  32. if(pressed == "1")
  33. { string name;
  34. string sex;
  35. int birthyear;
  36. int deathyear;
  37. cout << "Input name: ";
  38. cin.ignore();
  39. getline(cin,name);
  40. cout << "Input sex: ";
  41. cin.ignore();
  42. getline(cin,sex);
  43. cout << "Input birthyear: ";
  44. cin >>birthyear;
  45. cout << "Input deathyear: ";
  46. cin >>deathyear;
  47. _service.addScientistToDatabase(name, sex, birthyear, deathyear);
  48.  
  49. }
  50. else if(pressed == "2")
  51. {
  52. cout << "Input name: ";
  53. string name;
  54. cin.ignore();
  55. getline(cin,name);
  56. int year;
  57. cout << "Input year: ";
  58. cin >> year;
  59. cout << "Input type: ";
  60. string type;
  61. cin.ignore();
  62. getline(cin, type);
  63. cout << "Was it built? (Yes/No): ";
  64. string built;
  65. cin >> built;
  66. _service.addComputerToDatabase(name, year, type, built);
  67.  
  68. }
  69. else if(pressed == "3")
  70. {
  71. int Scientist_ID;
  72. int Computer_ID;
  73. cout << "Input Scientist ID: " << endl;
  74. cin >> Scientist_ID;
  75. cout << "Input Computer ID: " << endl;
  76. cin >> Computer_ID;
  77. _service.addConnectionToDatabase(Scientist_ID, Computer_ID);
  78. }
  79. }
  80.  
  81. else if(user_input == "list"|| user_input == "List" || user_input == "LIST")
  82. {
  83. string tableDisplay;
  84. do
  85. {
  86. cout << "What table to display?" << endl;
  87. cout << "Input '1' for Scientist table" << endl;
  88. cout << "Input '2' for Computer table" << endl;
  89. cout << "Input '3' for Connections table" << endl;
  90. cin >> tableDisplay;
  91. if(!(tableDisplay == "1") && !(tableDisplay == "2") && !(tableDisplay == "3"))
  92. {
  93. cout << "Invalid sort input. Please try again." << endl;
  94. }
  95. }while(!(tableDisplay == "1") && !(tableDisplay == "2") && !(tableDisplay == "3"));
  96. if(tableDisplay == "1")
  97. {
  98. vector <CompScientist> temp = _service.getScientistsListi();
  99. displayListOfScientists(temp);
  100. _service.getScientistsListi().clear();
  101. }
  102. else if(tableDisplay == "2")
  103. {
  104. vector <Computer> temp = _service.getComputersListi();
  105. displayListOfComputers(temp);
  106. _service.getComputersListi().clear();
  107. }
  108. }
  109.  
  110. else if(user_input == "sort"|| user_input == "Sort"|| user_input == "SORT")
  111. {
  112. string sort_input;
  113. do
  114. {
  115. cout << "Input 1 to sort computer scientist list" << endl;
  116. cout << "Input 2 to sort computer list" << endl;
  117. cin >> sort_input;
  118. if(!(sort_input == "1") && !(sort_input == "2"))
  119. {
  120. cout << "Invalid sort input. Please try again." << endl;
  121. }
  122. }while(!(sort_input == "1") && !(sort_input == "2"));
  123. Sortingfoo(sort_input);
  124. }
  125.  
  126. else if(user_input == "search"|| user_input == "Search"|| user_input == "SEARCH")
  127. {
  128. cout << "Input 1 to search for a computer scientist" << endl;
  129. cout << "Input 2 to search for a computer" << endl;
  130. string pressed;
  131. cin >> pressed;
  132.  
  133. if(pressed == "1")
  134. {
  135. cout << "Search by name or birthyear? " << endl;
  136. cin >> search_option;
  137. if(search_option == "name" || search_option == "Name" || search_option == "NAME")
  138. {
  139. cout << "Input the name of desired scientist: ";
  140. cin.ignore();
  141. getline(cin,search_name);
  142. SortingPrint(search_name,search_option);
  143. }
  144. else if(search_option == "birthyear" || search_option == "Birthyear" || search_option == "BIRTHYEAR")
  145. {
  146. cout << "Input a birthyear: ";
  147. cin.ignore();
  148. getline(cin,search_name);
  149. SortingPrint(search_name,search_option);
  150. }
  151. else
  152. {
  153. cout << "Invalid search command! Returned to main menu." << endl;
  154. }
  155. }
  156.  
  157. else if(pressed == "2")
  158. {
  159. cout << "Search by name or year?" << endl;
  160. cin >> search_option;
  161. if(search_option == "name" || search_option == "Name" || search_option == "NAME")
  162. {
  163. cout << "Input the name of desired computer: ";
  164. cin.ignore();
  165. getline(cin,search_name);
  166. sortingComputerPrint(search_name,search_option);
  167. }
  168. else if(search_option == "year" || search_option == "year" || search_option == "year")
  169. {
  170. cout << "Input a year: ";
  171. cin.ignore();
  172. getline(cin,search_name);
  173. sortingComputerPrint(search_name,search_option);
  174. }
  175. else
  176. {
  177. cout << "Invalid search command! Returned to main menu." << endl;
  178. }
  179. }
  180.  
  181. else
  182. {
  183. cout << "Invalid search command! Returned to main menu." << endl;
  184. }
  185.  
  186. }
  187.  
  188. else if(user_input =="Help" || user_input == "help" || user_input == "HELP")
  189. {
  190. Help();
  191. }
  192.  
  193. else if(!(user_input == "quit"||user_input == "Quit" || user_input == "QUIT"))
  194. {
  195. cout << "Invalid command!" << endl;
  196. }
  197.  
  198. ReAdd(); //display input options for user
  199.  
  200. }while( !(user_input == "quit"||user_input == "Quit" || user_input == "QUIT") );
  201. exit(1);
  202. }
  203.  
  204. void ConsoleUI::Help() // This contains keyword for every command you need to know for this program
  205. {
  206.  
  207. cout << " This file contains keywords for every command input you need for this program." << endl;
  208. cout <<"-----------------------------------------------------------------------------------------------------"<< endl;
  209. cout << " Add - With this command you can add scientists, computers or connections to their appropriate table." << endl;
  210. cout <<"-----------------------------------------------------------------------------------------------------"<< endl;
  211. cout << " List - Displays desired table." << endl;
  212. cout <<"-----------------------------------------------------------------------------------------------------"<< endl;
  213. cout << " Sort - With this command you can sort the 'Scientists' and 'Computers' table by name, year and type " << endl;
  214. cout << " in ascending order or descending order." << endl;
  215. cout <<"----------------------------------------------------------------------------------------------------"<< endl;
  216. cout << " Search - Input '1' to search for computer scientists, input '2' to search for computers."<<"\n"
  217. << "\t" << "Then you can input '1' to search by name, input '2' to search by year or input '3' to search" << endl;
  218. cout << "\t" << "by type in Computers table." << endl;
  219. cout <<"-----------------------------------------------------------------------------------------------------"<< endl;;
  220. }
  221.  
  222. void ConsoleUI::ReAdd() // This is the main menu after you have used any action
  223. {
  224. cout << "This is a main menu, add any of the following commands." << "\n"
  225. << "\t" << "Add - To add scientist to list." << "\n"
  226. << "\t" << "List - To display a table." << "\n"
  227. << "\t" << "Sort - To sort list."<< "\n"
  228. << "\t" << "Search - To search list."<< "\n"
  229. << "\t" << "Help - To get a review of all commands available." << "\n"
  230. << "\t" << "Quit - To quit program." << endl;
  231. cout << endl;
  232. }
  233.  
  234.  
  235. void ConsoleUI::displayListOfComputers(vector <Computer> listi) // Here you display the list of every computer that has been added to the program
  236. {
  237. vector <Computer> temp = listi;
  238. cout << left << setw(30) << "Name" << setw(7) << "Year" << setw(14) << "Type" << setw(27) << "Built" << endl;
  239. cout << setfill('-') << setw(71) << "-" << setfill(' ') << endl;
  240. for(size_t k = 0; k < temp.size(); k++)
  241. {
  242. cout << left << setw(30) << temp[k].getName() << setw(7) << temp[k].getYear() << setw(14) << temp[k].getType() << temp[k].getBuilt() << endl;
  243. }
  244. cout << endl;
  245. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement