Caeg

Untitled

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