Advertisement
Caeg

Untitled

Feb 23rd, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <algorithm>
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10. vector <string> vName, vID, vClass;
  11. string sName, sID, sClass;
  12. string sTemp;
  13. string sNameSearch;
  14. int iStudent;
  15.  
  16. // Displays text stating the starting size of the student list
  17. cout << "\nThe student list starts with the size of: " << vName.size() << endl;
  18.  
  19. // Displays text to the user requesting to input an amount of students to add to the list
  20. cout << "\nHow many students would you like to add: ";
  21.  
  22. // Gathers the amount of students requesting to be added
  23. cin >> iStudent;
  24.  
  25.  
  26.  
  27. //
  28. cin.ignore();
  29.  
  30. //
  31. for (int i = 0; i < iStudent; i++)
  32.  
  33. {
  34. // Displays the student number
  35. cout << "\nStudent " << i + 1 << ":";
  36.  
  37. // Displays text requesting for the student's name
  38. cout << "\nPlease enter the student's name:\t";
  39.  
  40. // Gathers the name submited
  41. getline(cin, sName);
  42.  
  43. //
  44. vName.push_back(sName);
  45.  
  46. // Displays text requsting the student's ID
  47. cout << "\nPlease enter the student's ID:\t\t";
  48.  
  49. // Gathers the ID submited
  50. getline(cin, sID);
  51.  
  52. //
  53. vID.push_back(sID);
  54.  
  55. // Displays text requesting the student's class
  56. cout << "\nPlease enter the student's class:\t";
  57.  
  58. // Gathers the class submited
  59. getline(cin, sClass);
  60.  
  61. //
  62. vClass.push_back(sClass);
  63.  
  64. }
  65. // Displays a line of text stating the size of the class, and the information for each student
  66. cout << "\nThe student list has a size of: " << vName.size() << "\n";
  67. cout << "\nThe student list is:\n\ ";
  68. cout << "\nName: \t\t ID: \t\t Enrolled classes";
  69. cout << "\n--------------------------------------------------------------------------------\n";
  70.  
  71. for (int i = 0; i < vName.size(); i++)
  72. {
  73. cout << endl << vName[i] << "\t\t" << vID[i] << "\t\t" << vClass[i];
  74.  
  75. }
  76.  
  77. cout << " \n\nThe student list after sorting: \n";
  78.  
  79. for (int i = 0; i < vName.size(); i++)
  80. {
  81. cout << endl << vName[i];
  82. }
  83.  
  84. cout << "\n\nPlease enter the name to be searched: ";
  85. cin >> (vName.begin(), vName.end(), sTemp);
  86.  
  87. if (binary_search(vName.begin(), vName.end(), sTemp))
  88. {
  89. cout << "The name was found!";
  90. }
  91. else
  92. {
  93. cout << "This name was not found.";
  94. }
  95.  
  96.  
  97. do
  98. {
  99. cout << "\n\nPlease enter the name to be searched: ";
  100. getline(cin, sTemp);
  101.  
  102. if (binary_search(vName.begin(), vName.end(), sTemp))
  103. {
  104. cout << "The name was found!";
  105. }
  106. else
  107. {
  108. cout << "This name was not found.";
  109. }
  110. cout << "\nWould you like to do this again: Y for Yes, N for No?\n";
  111. getline(cin, sTemp);
  112. cout << endl;
  113.  
  114. } while (sTemp[0] == 'Y' || sTemp[0] == 'y');
  115.  
  116.  
  117. if (sTemp[0] == 'N' || sTemp[0] == 'n')
  118. cout << "\nThanks for using this program!\n";
  119.  
  120. return 0;
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement