Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a C++ program using vectors and iterators that allows a user to maintain his or her favorite games. The program should allow the user

Write a C++ program using vectors and iterators that allows a user to maintain his or her favorite games. The program should allow the user to list all game titles, add a game title, and remove a game title. ** Here is what I have so far, I feel like I am almost done. I am just having a problem re-displaying the list after the user enters games to add. When I try to update the display, it lists the ones that were entered the first time, then it skips a line, and then it adds the ones that were entered second. I DON'T WANT IT TO SKIP A LINE!! Why won't it just display all of them consecutively? Then if you have any ideas on how to remove a game from the list that the user specifies! Please and Thank You! My code...

#include // STD IO Stream Library, Keyboard and Terminal Window #include // Allows String Objects Like Character Strings #include // Needed For Vector Objects #include // Needed For Standard Libraries, exit() Function, etc. using namespace std;

int main() { system("Color 0A"); // Lime Green on Black Display

short unsigned int numGames, i; // The Number of Favorite Games of the User & the Indexing Variable Declared as Short Unsigned Integers

//-------------------------Display-------------------------- cout << "\t\t** Welcome to Game Center ** " << endl << endl; cout << "Game Center Will Keep Track of Your Favorite Games. " << endl; cout << "First Think of The Favorite Games That You Like to Play. " << endl; cout << "Next, Count How Many Games That You Have In Mind. " << endl << endl; cout << "Please Enter the Number of Games on Your Favorite(s) List: "; // Prompt User to Enter the Number of Games cin >> numGames; // User Enters the Number of Games They Like to Play cout << endl; cout << "Please Enter Your List of Favorite Games: " << endl << endl;

string game; // User-Entered Game Choice Declared as a Character String vector gameList; // User's Game List Declared as a Vector of Strings

for (i = 0; i <= numGames; i++) { getline(cin, game); // User Enters Each of their Favorite Games, Accounting for Spaces gameList.push_back(game); // Load the gameList Vector with Each Game Entered by the User }

vector::iterator myIterator; // Iterator that Allows You to Edit Elements of a Vector vector::const_iterator iter; // Iterator the Only Allows You to Reference Elements of a Vector, NOT CHANGE THEM!!

cout << " Here Are The Games That You Have Told Me So Far: " << endl; //---------------Display User-Entered Games------------------ for (iter = gameList.begin(); iter != gameList.end(); ++iter) { cout << *iter << endl; // Point To and Display Each Element of gameList Vector }

numGames = 0; // Reset the numGames Variable char response; // User Response Declared as a Character Datatype cout << endl; cout << "Do You Have Any Other Titles You Wish to Add? [y or n]: "; // Ask User If They Want to Add More Games cin >> response; // User Enters Whether They Want to Add More Games cout << endl;

if (response == 'y' || response == 'Y') { cout << "Please Enter the Number of Games You Wish to Add: "; // Prompt User to Enter the Number of Games cin >> numGames; // User Enters the Number of Games They Wish to Add cout << endl; cout << "Please Enter the Games You Wish to Add: " << endl << endl; for (i = 0; i <= numGames; i++) { getline(cin, game); // User Enters Each of their Favorite Games, Accounting for Spaces gameList.push_back(game); // Load the gameList Vector with Each Game Entered by the User } //-----------------Update Display of Games------------------ for (iter = gameList.begin(); iter != gameList.end(); ++iter) { cout << *iter; // Point To and Display Each Element of gameList Vector } }

system("pause");

return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases And Information Systems 23rd European Conference Adbis 2019 Bled Slovenia September 8 11 2019 Proceedings Lncs 11695

Authors: Tatjana Welzer ,Johann Eder ,Vili Podgorelec ,Aida Kamisalic Latific

1st Edition

3030287297, 978-3030287290

More Books

Students also viewed these Databases questions

Question

Why are network layers important?

Answered: 1 week ago

Question

Explain the process of Human Resource Planning.

Answered: 1 week ago