Caeg

Untitled

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