Advertisement
deadlinesarefun

GamesList

Feb 23rd, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.75 KB | None | 0 0
  1. // ConsoleApplication1.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. #include <vector>
  7. #include <algorithm>
  8. #include <cstdlib>
  9. #include <ctime>
  10. #include <string>
  11. using namespace std;
  12.  
  13.  
  14. void AddGames(vector<string> &games);
  15. void PrintGames(vector<string> &games);
  16. void replaceGame(vector<string> &games);
  17.  
  18. int main()
  19. {
  20.    
  21.     vector<string> games;
  22.  
  23.     bool end = false;
  24.     int choice = 0;
  25.     while (end != true)
  26.     {
  27.         cout << "1) Add game, 2) print games, 3) replace game 4)exit" << endl;
  28.         cin >> choice;
  29.  
  30.         if (choice == 1)
  31.         {
  32.             AddGames(games);
  33.             choice = 0;
  34.         }
  35.  
  36.         if (choice == 2)
  37.         {
  38.  
  39.             PrintGames(games);
  40.             choice = 0;
  41.         }
  42.  
  43.         if (choice == 3)
  44.         {
  45.             replaceGame(games);
  46.             choice = 0;
  47.         }
  48.         if (choice == 4)
  49.         {
  50.             return 0;
  51.         }
  52.  
  53.     }
  54.    
  55.  
  56.    
  57.    
  58.  
  59.     return 0;
  60. }
  61.  
  62. void AddGames(vector<string> &games)
  63. {
  64.     cout << "Enter name of game or 1) to exit OR EXIT TO GO BACK:" << endl;
  65.     string tempGame = "";
  66.     while (tempGame != "Exit")
  67.     {
  68.        
  69.         getline(cin, tempGame);
  70.         if (tempGame == "Exit")
  71.         {
  72.             break;
  73.         }
  74.         games.push_back(tempGame);
  75.         tempGame = "";
  76.     }
  77. }
  78.  
  79. void PrintGames(vector<string> &games)
  80. {
  81.     vector<string>::const_iterator iter;
  82.    
  83.     for (iter = games.begin(); iter != games.end(); ++iter)
  84.     {
  85.         cout << *iter << endl;
  86.     }
  87. }
  88.  
  89. void replaceGame(vector<string> &games)
  90. {
  91.     cout << "Chose game to replace:" << endl;
  92.     vector<string>::iterator myIterator;
  93.     string tempFind = "";
  94.     cin.ignore();
  95.     getline(cin, tempFind);
  96.    
  97.    
  98.    
  99.     cout << "New game name:" << endl;
  100.     string NewGame ="";
  101.    
  102.     cin>>NewGame;
  103.     //vector<string>::const_iterator iter;
  104.  
  105.  
  106.     std::replace(games.begin(), games.end(), tempFind,NewGame);
  107.  
  108.     tempFind = "";
  109.     NewGame = "";
  110.    
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement