Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Exercise 1
- // Game title tracking app
- #include <iostream>
- #include <string>
- #include <vector>
- #include <algorithm>
- #include <limits>
- using namespace std;
- int main(){
- enum menu
- {
- ENTER=1,
- DELETE,
- LIST,
- SORT_LIST,
- QUIT
- };
- vector<string> gameTitles;
- vector<string>::iterator gameTitleIter;
- bool running = true;
- int choice;
- string title;
- cout << "\t\t\tWelcome to my game title list program\n\n";
- do
- {
- cout << "Select an option:\n";
- cout << "\t" << ENTER << " - Enter a title\n";
- cout << "\t" << DELETE << " - Delete a title\n";
- cout << "\t" << LIST << " - List titles\n";
- cout << "\t" << SORT_LIST << " - Sort list\n";
- cout << "\t" << QUIT << " - Quit\n";
- cout << "Enter choice: ";
- cin >> choice;
- title="sanwich0";
- switch(choice){
- case ENTER:
- cout << "\nEnter Game title (to add): ";
- getline(cin, title);
- cout << "\n title " << title << endl;
- gameTitles.push_back(title);
- break;
- case DELETE:
- cout << "\nEnter a title (to delete): ";
- getline(cin, title);
- gameTitleIter = find(gameTitles.begin(), gameTitles.end(), title);
- if (gameTitleIter != gameTitles.end())
- {
- gameTitles.erase(gameTitleIter);
- }else{
- cout << "\nTitle was not found.";
- }
- break;
- case LIST:
- cout << "\nGame titles:\n";
- for (gameTitleIter = gameTitles.begin(); gameTitleIter != gameTitles.end(); ++gameTitleIter)
- {
- cout << "\t" << *gameTitleIter << endl;
- }
- break;
- case SORT_LIST:
- sort(gameTitles.begin(), gameTitles.end());
- cout << "\nList sorted.";
- break;
- case QUIT:
- running = false;
- break;
- default:
- cout << "\nInvalid option.\n";
- }
- cin.ignore( numeric_limits<streamsize>::max(), '\n' );
- } while (running);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement