Advertisement
Guest User

Untitled

a guest
Oct 17th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <string>
  4. #include <vector>
  5. #include <algorithm>
  6. #include <sstream>
  7. #include <fstream>
  8.  
  9.  
  10. using namespace std;
  11.  
  12. int main()
  13. {
  14. string sChoice, sTemp, sFName, sMName, sLName, sFullName, sID, sClass;
  15. ifstream iFile;
  16. ofstream oFile;
  17. int iTemp;
  18. const char READING = 'A', ADDING = 'B', DISPLAYING = 'C', SORTING = 'D', WRITING = 'E', SEARCHING = 'F', ENDING = 'G';
  19. vector <string> vName, vID, vClass;
  20.  
  21. do {
  22. //Display menu
  23. cout << "\nStudent List Menu\n";
  24. cout << " A. Reading student list from a file \n";
  25. cout << " B. Adding student information into student list \n";
  26. cout << " C. Displaing the content of the student list \n";
  27. cout << " D. Sorting and displaying he content of student list \n";
  28. cout << " E. Writing thestudent list to a file \n";
  29. cout << " F. Searching for a students info from list \n";
  30. cout << " G. Ending program \n";
  31.  
  32. cout << " Please select a choice: ";
  33. getline(cin, sChoice);
  34. switch (toupper(sChoice[0]))
  35. {
  36. case READING:
  37. cout << "\Please enter the password: ";
  38. getline(cin, sTemp);
  39. iFile.open(sTemp.c_str());
  40.  
  41. //testfor error
  42. while (iFile.fail())
  43. {
  44. iFile.clear();
  45. iFile.ignore();
  46. cout << " \nOpening error! Please re enter: \n";
  47. getline(cin, sTemp);
  48. iFile.open(sTemp.c_str());
  49. }
  50. while (getline(iFile, sTemp))
  51. {
  52. istringstream isObject(sTemp);
  53. isObject >> sFName >> sMName >> sLName >> sID >> sClass;
  54. if (sMName == "|")
  55. {
  56. sMName = " ";
  57. sFullName = sFName + " " + sLName;
  58. }
  59. else
  60. {
  61. sFullName = sFName + " " + sLName;
  62. }
  63. cout << left << setw(30) << sFName << setw(10) << sMName << setw(10) << sLName << setw(10) << sID << setw(10) << sClass << endl;
  64.  
  65. vName.push_back(sFullName);
  66. vID.push_back(sID);
  67. vClass.push_back(sClass);
  68. }
  69. iFile.close();
  70. cout << " \nReading is successful \n";
  71. break;
  72.  
  73. case ADDING:
  74.  
  75. break;
  76. case DISPLAYING:
  77. cout << "content of stident list \n";
  78. for (int i = 0; vName.size(); i++)
  79. cout << setw(30) << vName[i] << setw(10) << vID[i] << setw(10) << vClass[i] << endl;
  80. break;
  81. case SORTING:
  82. cout << "\n The student list after sorting: \n";
  83. sort(vName.begin(), vName.end());
  84. //sort vName.begin
  85.  
  86. break;
  87. case WRITING:
  88.  
  89. break;
  90. case SEARCHING:
  91.  
  92. break;
  93. case ENDING:
  94.  
  95. break;
  96. default:
  97. cout << " Invalid password";
  98. }
  99. } while (toupper(sChoice[0]) != '6');
  100.  
  101. return 0;
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement