Advertisement
Koalaazz

Vector Assignment 2

Dec 15th, 2020
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.24 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <algorithm>
  5.  
  6. using namespace std;
  7.  
  8. int menu()
  9. {
  10. int input; //users input
  11.  
  12. system("CLS");
  13. cout << "Choose an option: \n";
  14. cout << "1. Display Games\n";
  15. cout << "2. Add Game\n";
  16. cout << "3. Count How Many Games You Have\n";
  17. cout << "4. Delete A Game\n";
  18. cout << "5. Sort Ascending\n";
  19. cout << "6. Sort Descending\n";
  20. cout << "7. Quit\n";
  21. cin >> input; //accepts input from user
  22. return input;
  23. }
  24.  
  25. int main()
  26. {
  27. vector<string> gaming = { "guitar hero", "guitar hero 2", "guitar hero 3" }; //current games inside string
  28. vector<string> ::iterator it;
  29. bool flag = true;
  30. int game;
  31. int deletegame; //deleting game
  32. string gamingGame;
  33. char quit;
  34.  
  35. do
  36. {
  37. game = menu();
  38.  
  39. switch (game)
  40. {
  41. case 1: //displays games...BLUFF!!!!!!
  42. system("CLS");
  43. for (unsigned int i = 0; i < gaming.size(); i++)
  44. {
  45. cout << gaming[i] << endl;
  46. }
  47. system("PAUSE");
  48. break;
  49.  
  50. case 2: //adds games
  51. system("CLS");
  52. cin.ignore();
  53. cout << "Please enter the gaming name you want to add:\n";
  54. getline(cin,gamingGame); //gets input with spaces
  55. gaming.push_back(gamingGame); //adds game to the end of string
  56. break;
  57.  
  58. case 3:
  59. system("CLS"); //counts how many games are in string
  60. cout << "You Have " << gaming.size() << " games to game\n";
  61. system("PAUSE");
  62. break;
  63.  
  64. case 4:
  65. system("CLS"); //deletes game
  66. cout << "Which game would you like to delete?\n";
  67. for (unsigned int i = 0; i < gaming.size(); i++)
  68. {
  69. cout << gaming[i] << endl;
  70. }
  71. cin.ignore();
  72. getline(cin, gamingGame); //gets input with spaces
  73. it = find(gaming.begin(), gaming.end(),gamingGame);
  74. if (it != gaming.end())
  75. {
  76. gaming.erase(it);
  77. }
  78. else
  79. {
  80. cout << "Game not found.";
  81. }
  82. system("PAUSE");
  83. break;
  84.  
  85. case 5: //sorts ascending
  86. system("CLS");
  87. sort(gaming.begin(), gaming.end());//sort the vector
  88. for (vector<string>::iterator it = gaming.begin(); it != gaming.end(); ++it)
  89. cout << *it << ',' << ' ';
  90. cout << '\n';
  91. system("PAUSE");
  92. break;
  93.  
  94. case 6: //sorts decending
  95. system("CLS");
  96. sort(gaming.begin(), gaming.end(), greater<>());//sort the vector reverse
  97. for (vector<string>::iterator it = gaming.begin(); it != gaming.end(); ++it) //loop to sort
  98. cout << *it << ',' << ' ';
  99. cout << '\n';
  100. system("PAUSE");
  101. break;
  102.  
  103. case 7: //quits
  104. flag = false;
  105. break;
  106.  
  107. default: //if invalid entry
  108. cout << "invalid entry...try again.\n\n";
  109. system("PAUSE");
  110. break;
  111. }
  112. } while (flag);
  113. return 0;
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement