Caeg

Untitled

Apr 6th, 2016
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.64 KB | None | 0 0
  1. #include <fstream>
  2. #include <string>
  3. #include <iostream>
  4. #include <vector>
  5. #include <algorithm>
  6.  
  7. using namespace std;
  8. int main()
  9. {
  10. string sResponse, sPass, sInfo = "";
  11. ifstream fStream;
  12. ofstream oStream;
  13. int iStudent, iCounter, iClass;
  14. vector <string> vFName, vMName, vLName, vID, vData, vClass,vClasses, vName;
  15. string sFName, sMName, sLName, sID, sClass,sClasses, sSearch;
  16. const char READING = 'A', ADDING = 'B', DISPLAYING = 'C', SORTING = 'D', SAVING = 'E', SEARCHING = 'F', EXITING = 'G';
  17. do
  18. {
  19. //this is a reference table that allows users to view all the capabilities of the app
  20. cout << "\tStudent Enrollment Application\n\n";
  21. cout << "A. Reading an external student list\n";
  22. cout << "B. Adding student's informations into student list\n";
  23. cout << "C. Displaying student list\n";
  24. cout << "D. Sorting student list\n";
  25. cout << "E. Saving student list to a file\n";
  26. cout << "F. Searching from student list\n";
  27. cout << "G. Exit the application\n\n";
  28.  
  29. cout << "What would you like to perform?";
  30. getline(cin, sResponse);
  31.  
  32. switch (toupper(sResponse[0]))
  33. {
  34. //allows you to add a student list and see how many poeple are on it
  35. case READING:
  36. //opens file
  37. cout << "\nPlease enter the password:";
  38. getline(cin, sPass);
  39. fStream.open(sPass.c_str());
  40.  
  41. if (!fStream)
  42. {
  43. fStream.clear();
  44. cout << "Wrong password! Please re-enter the password: ";
  45. getline(cin, sPass);
  46. fStream.open(sPass.c_str());
  47.  
  48. }
  49. cout << "\nOpened Successfully! \n";
  50.  
  51. while (getline(fStream, sPass))
  52.  
  53. if (sResponse == "|")
  54. {
  55. sResponse = "\t";
  56. sInfo += "\t\t";
  57. }
  58. else
  59. {
  60. if (iCounter % 5 == 0)
  61. cout << endl;
  62. sInfo += sResponse;
  63.  
  64. iCounter++;
  65. vData.push_back(sPass);
  66. }
  67. cout << sPass << endl;
  68. //tells you how many students are on the list
  69. cout << "\nReading is successful! \n";
  70. cout << "\nThe size of the list is: " << vData.size() << endl << endl;
  71. break;
  72. case ADDING:
  73. //asks how many students you want to add
  74. cout << "How many Students would you like to add:";
  75. cin >> iStudent;
  76. cin.ignore();
  77. //if you input something other than a number this will prevent the app from continuing
  78. while (cin.fail())
  79. {
  80. cout << "Invalid Choice. Select again: ";
  81. cin.clear();
  82. cin.ignore(std::numeric_limits<int>::max(), '\n');
  83. cin >> iStudent;
  84. cin.ignore();
  85. }
  86. //allows you to add students to the list
  87. for (int i = 0; i < iStudent; i++)
  88. {
  89.  
  90. cout << "\nStudent " << i + 1 << ":";
  91. cout << "\nPlease enter the Student's First Name: ";
  92. getline(cin, sFName);
  93. vFName.push_back(sFName);
  94. cout << "\nPlease enter the Student's Middle Name: ";
  95. getline(cin, sMName);
  96. vMName.push_back(sMName);
  97. cout << "\nPlease enter the Student's Last Name: ";
  98. getline(cin, sLName);
  99. vLName.push_back(sLName);
  100. cout << "\nPlease enter the Student's ID: ";
  101. getline(cin, sID);
  102. vID.push_back(sID);
  103. cout << "\nHow many classes for this student? ";
  104. getline(cin, sClass);
  105. vClass.push_back(sClass);
  106. cout << "\nPlease enter the Studnet's class: ";
  107. getline(cin, sClasses);
  108. vClasses.push_back(sClasses);
  109.  
  110. vName.push_back(sFName + "\t" + sMName + "\t" + sLName + "\t");
  111. }
  112. break;
  113. //this displays student list
  114. case DISPLAYING:
  115. if (vData.size() == 0)
  116. {
  117. cout << "\nThe list is empty! Perhaps you need to load information into the list.\n\n";
  118. }
  119. for (int i = 0; i < vData.size(); i++)
  120. cout << vData[i] << endl;
  121. break;
  122. //sorts student list
  123. case SORTING:
  124. //if no information is avalible this will be displayed
  125. if (vData.size() == 0)
  126. {
  127. cout << "\nThe list is empty! Perhaps you need to load information into the list.\n\n";
  128. }
  129. //otherwise the list wil be sorted
  130. else
  131. {
  132. sort(vData.begin(), vData.end());
  133. sort(vName.begin(), vName.end());
  134. cout << "Sorting successfully the list.\n\n";
  135. }
  136. break;
  137. //creates a new saved file
  138. case SAVING:
  139. cout << "\nPlease enter a file name: ";
  140. getline(cin, sResponse);
  141. oStream.open(sResponse.c_str());
  142.  
  143. for (int i = 0; i < vData.size(); i++)
  144. oStream << vData[i] << endl;
  145. oStream.close();
  146. break;
  147. //allows you to search for a student by name
  148. case SEARCHING:
  149. char response;
  150. // if no students are present on the list this wil be displayed
  151. if (vData.size() == 0)
  152. {
  153. cout << "\nThe list is empty! Perhaps you need to load information into the list.\n\n";
  154. }
  155. // if students are present you will then be able to search by name
  156. else
  157. {
  158. do
  159. {
  160. cout << "\nPlease enter the name to be searched: ";
  161. getline(cin, sSearch);
  162.  
  163. if (binary_search(vName.begin(), vName.end(), sSearch))
  164. {
  165. cout << "\nThe name: " + sSearch + " was found in the Student List.\n";
  166. }
  167. else
  168. {
  169. cout << "\nThe name: " + sSearch + " was not found in the Student List.\n";
  170. }
  171.  
  172. cout << "\nWould you like to search more?\nPlease enter Y for Yes, and N for No: ";
  173. cin >> response;
  174. cin.ignore();
  175. } while (response == 'Y' || response == 'y');
  176. }
  177. break;
  178. //exiting lab section that allows you to terminate the app or continue
  179. case EXITING:
  180. cout << "\nExiting application!";
  181. cout << "\nAre you sure to exit this application? Yes or No: ";
  182. cin >> response;
  183. cin.ignore();
  184. while (response == 'Y' || response == 'y');
  185. break;
  186.  
  187. default:
  188. cout << "\nInvalid Input! \n\n";
  189. break;
  190. }
  191. } while (toupper(sResponse[0]) != EXITING);
  192.  
  193. cout << "\nApplication is terminating. \n";
  194.  
  195.  
  196. return 0;
  197. }
Advertisement
Add Comment
Please, Sign In to add comment