Caeg

Untitled

Apr 5th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.76 KB | None | 0 0
  1. #include <algorithm>
  2. #include <cstdlib>
  3. #include <ctime>
  4. #include <cctype>
  5. #include <fstream>
  6.  
  7. using namespace std;
  8. void displaydata(int);
  9.  
  10. int main()
  11. {
  12.  
  13. string sChoice, sTemp, sInfo, sArray;
  14.  
  15. vector <string> vData;
  16. ifstream inputfile;
  17. ofstream outputfile;
  18. int iCounter;
  19.  
  20. const char READING = 'A', ADDING = 'B', DISPLAYING = 'C', SORTING = 'D', SAVING = 'E', SEARCHING = 'F', EXITING = 'G';
  21.  
  22. cout << "\n Student Enrollment Application";
  23. cout << "\n A. Reading an external student list";
  24. cout << "\n B. Adding student's information into student list";
  25. cout << "\n C. Displaying student list";
  26. cout << "\n D. Sorting student list";
  27. cout << "\n E. Saving student list to a file";
  28. cout << "\n F. Searching from student list";
  29. cout << "\n G. Exit the application";
  30.  
  31.  
  32. {
  33. cout << "\nWhich option would you like to preform? Select an option from A through G. ";
  34. getline(cin, sChoice);
  35. switch (toupper(sChoice[0]))
  36.  
  37. {
  38. case READING:
  39. // This case allows for you to upload a file. You must enter the file's name as the password to open it.
  40. cout << "Please enter the password: ";
  41. getline(cin, sTemp);
  42. inputfile.open(sTemp.c_str());
  43.  
  44. // This gives you an error if the password is incorrect.
  45. if (!inputfile)
  46. {
  47. cout << "\nWrong password, please re-enter: ";
  48. getline(cin, sTemp);
  49. inputfile.open(sTemp.c_str());
  50. }
  51. cout << "\nOpen succesfully! \n";
  52.  
  53. // This tells you if you've typed in the correct password.
  54. if (inputfile)
  55. {
  56. cout << "\nThat's the correct password!";
  57.  
  58. }
  59. cout << "\nReading is succesful!\n";
  60. cout << "\nThe size of the list is: " << vData.size() << endl;
  61.  
  62.  
  63. while (getline(inputfile, sTemp))
  64. iCounter++;
  65.  
  66. string sArray[iCounter];
  67.  
  68. while (inputfile >> sTemp)
  69. {
  70. if (sTemp == "|");
  71. {
  72. sTemp = " ";
  73. sInfo += (sTemp + "\t\t");
  74. }
  75. if (sTemp != "|");
  76. {
  77. sInfo += sTemp;
  78. }
  79. vData.push_text(sTemp);
  80.  
  81.  
  82. inputfile.close();
  83.  
  84. break;
  85. case ADDING:
  86. cout << "\nThe student list's size right now is: ";
  87.  
  88. break;
  89. case DISPLAYING:
  90.  
  91. if (vData.size() == 0);
  92. cout << "\nThe list is empty!\n";
  93.  
  94. for (int i = 0; i < vData.size(); i++)
  95. cout << vData[i] << endl;
  96.  
  97.  
  98. break;
  99. case SORTING:
  100.  
  101. if (vData.size() == 0)
  102. cout << "\nThe list is empty! \n";
  103.  
  104. sort(vData.begin(), vData.end());
  105. cout << "\nSorting is succesfull! \n";
  106.  
  107. break;
  108. case SAVING:
  109. cout << "\nPlease enter a file name";
  110. getline(cin, sTemp);
  111. outputfile.open(sTemp.c_str());
  112.  
  113. for (int i = 0; i < vData.size(); i++)
  114. outputfile << vData[i] << endl;
  115. outputfile.close();
  116. break;
  117. case SEARCHING:
  118.  
  119. case EXITING:
  120. break;
  121.  
  122.  
  123. }
  124. }
  125.  
  126.  
  127.  
  128.  
  129. return 0;
  130. }
Advertisement
Add Comment
Please, Sign In to add comment