Caeg

Untitled

Apr 6th, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.24 KB | None | 0 0
  1. #include <algorithm>
  2. #include <iomanip>
  3. #include <cstdlib>
  4. #include <iostream>
  5. #include <string>
  6. #include <vector>
  7. #include <algorithm>
  8. #include <cstdlib>
  9. #include <ctime>
  10. #include <cctype>
  11. #include <fstream>
  12.  
  13. using namespace std;
  14.  
  15. int main()
  16. {
  17.  
  18. string strOpt, strFileName, strInfo = "";
  19. string strFirstName, strMiddleName, strLastName, strID, strClass, strClasses, strSearch;
  20. vector <string> vecName, vecFirstName, vecMiddleName, vecLastName, vecClass, vecClasses, vecData, vecID;
  21. ifstream FileIn;
  22. ofstream FileOut;
  23. int intStudent, intCounter, intClass;
  24.  
  25. const char READING = 'A', ADDING = 'B', DISPLAYING = 'C', SORTING = 'D', SAVING = 'E', SEARCHING = 'F', EXITING = 'G';
  26. do
  27. {
  28. //this is a reference table that allows users to view all the capabilities of the app
  29. cout << "\tStudent Enrollment Application\n\n";
  30. cout << "A. Reading an external student list\n";
  31. cout << "B. Adding student's informations into student list\n";
  32. cout << "C. Displaying student list\n";
  33. cout << "D. Sorting student list\n";
  34. cout << "E. Saving student list to a file\n";
  35. cout << "F. Searching from student list\n";
  36. cout << "G. Exit the application\n\n";
  37.  
  38. cout << "What would you like to perform? ";
  39. getline(cin, strOpt);
  40.  
  41. switch (toupper(strOpt[0]))
  42.  
  43. {
  44. //allows you to add a student list and see how many poeple are on it
  45. case READING:
  46. //This opens the file.
  47. cout << "\nPlease enter the file's name you would like to open: ";
  48. getline(cin, strFileName);
  49. FileIn.open(strFileName.c_str());
  50.  
  51. // This gives you an error if the file name typed is incorrect
  52. if (!FileIn)
  53. {
  54. FileIn.clear();
  55. cout << "Could not find file name! Please re-enter the file name: ";
  56. getline(cin, strFileName);
  57. FileIn.open(strFileName.c_str());
  58.  
  59. }
  60.  
  61. // This tells you if you've typed in the correct password.
  62. if (FileIn)
  63. {
  64. cout << "\nThat's the correct file name!";
  65. }
  66.  
  67. cout << "\nOpened Successfully! \n";
  68.  
  69. while (getline(FileIn, strFileName))
  70.  
  71. if (strOpt == "|")
  72. {
  73. strOpt = "\t";
  74. strInfo += "\t\t";
  75.  
  76. }
  77. cout << strFileName << endl;
  78. //This tells you how many students are within the list.
  79. cout << "\nReading is successful! \n";
  80. cout << "\nThe size of the list is: " << vecData.size() << endl << endl;
  81. break;
  82.  
  83. // This case allows you to add more students to the list
  84. case ADDING:
  85.  
  86. //asks how many students you want to add
  87. cout << "How many Students would you like to add:";
  88. cin >> intStudent;
  89. cin.ignore();
  90.  
  91. //if you input something other than a number this will prevent the app from continuing
  92. while (cin.fail())
  93. {
  94. cout << "Invalid Choice. Select again: ";
  95. cin.clear();
  96. cin.ignore(std::numeric_limits<int>::max(), '\n');
  97. cin >> intStudent;
  98. cin.ignore();
  99. }
  100.  
  101. //allows you to add students to the list
  102. for (int i = 0; i < intStudent; i++)
  103. {
  104.  
  105. cout << "\nStudent " << i + 1 << ":";
  106. cout << "\nPlease enter the Student's First Name: ";
  107. getline(cin, strFirstName);
  108. vecFirstName.push_back(strFirstName);
  109. cout << "\nPlease enter the Student's Middle Name: ";
  110. getline(cin, strMiddleName);
  111. vecMiddleName.push_back(strMiddleName);
  112. cout << "\nPlease enter the Student's Last Name: ";
  113. getline(cin, strLastName);
  114. vecLastName.push_back(strLastName);
  115. cout << "\nPlease enter the Student's ID: ";
  116. getline(cin, strID);
  117. vecID.push_back(strID);
  118. cout << "\nHow many classes for this student? ";
  119. getline(cin, strClass);
  120. vecClass.push_back(strClass);
  121. cout << "\nPlease enter the Studnet's class: ";
  122. getline(cin, strClasses);
  123. vecClasses.push_back(strClasses);
  124.  
  125. vecName.push_back(strFirstName + "\t" + strMiddleName + "\t" + strLastName + "\t");
  126. }
  127. break;
  128.  
  129. //this displays student list
  130. case DISPLAYING:
  131. if (vecData.size() == 0)
  132. {
  133. cout << "\nThe list is empty! Perhaps you need to load information into the list.\n\n";
  134. }
  135. for (int i = 0; i < vecData.size(); i++)
  136. cout << vecData[i] << endl;
  137. break;
  138.  
  139. //This case sorts the students by their names.
  140. case SORTING:
  141.  
  142. //If a file was not loaded, this causes an error message to occur.
  143. if (vecData.size() == 0)
  144. {
  145. cout << "\nThe list is empty! Please load a file.\n\n";
  146. }
  147.  
  148. //This will sort the students by their names.
  149. else
  150. {
  151. sort(vecData.begin(), vecData.end());
  152. sort(vecName.begin(), vecName.end());
  153. cout << "This list was successfuly sorted.\n\n";
  154. }
  155. break;
  156.  
  157. //This case allows for you to create a new save file
  158. case SAVING:
  159. cout << "\nPlease enter a file name: ";
  160. getline(cin, strOpt);
  161. FileOut.open(strOpt.c_str());
  162.  
  163. for (int i = 0; i < vecData.size(); i++)
  164. FileOut << vecData[i] << endl;
  165. FileOut.close();
  166. break;
  167.  
  168. //This case lets you search students on the list by their name
  169. case SEARCHING:
  170. char response;
  171.  
  172. // This provides an error message if students could not be found.
  173. if (vecData.size() == 0)
  174. {
  175. cout << "\nThe list is empty! Perhaps you need to load information into the list.\n\n";
  176. }
  177.  
  178. // This allows for you to search the names of students.
  179. else
  180. {
  181. do
  182. {
  183. cout << "\nPlease enter the name to be searched: ";
  184. getline(cin, strSearch);
  185.  
  186. if (binary_search(vecName.begin(), vecName.end(), strSearch))
  187. {
  188. cout << "\nThe name: " + strSearch + " was found in the Student List.\n";
  189. }
  190. else
  191. {
  192. cout << "\nThe name: " + strSearch + " could not be found in the Student List.\n";
  193. }
  194.  
  195. cout << "\nWould you like to search more?\nPlease enter Y for Yes, and N for No: ";
  196. cin >> response;
  197. cin.ignore();
  198. } while (response == 'Y' || response == 'y');
  199. }
  200. break;
  201. //exiting lab section that allows you to terminate the app or continue
  202. case EXITING:
  203. cout << "\nExiting application!";
  204. cout << "\nAre you sure to exit this application? Yes or No: ";
  205. cin >> response;
  206. cin.ignore();
  207. while (response == 'Y' || response == 'y');
  208. break;
  209.  
  210. default:
  211. cout << "\nInvalid Input! \n\n";
  212. break;
  213. }
  214. } while (toupper(strOpt[0]) != EXITING);
  215.  
  216. cout << "\nApplication is terminating. \n";
  217.  
  218.  
  219. return 0;
  220. }
Advertisement
Add Comment
Please, Sign In to add comment