Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a C++ program that maintains a list of board games in stock for a store na

ID: 3763718 • Letter: W

Question

Write a C++ program that maintains a list of board games in stock for a store named Wildcats. The program should repeatedly print a menu of options to allow a user to select from the following operations, until the user decides to exit.

• Insert a game record • Delete a game record • Print the game list • Search the game list • Quit

Each game record in the list consists of game name (string), number of copies in stock (int), price (double) and user score (double, in the range of [0.0, 10.0]). The game list should be maintained in the lexicographical order (also called dictionary order) according to the names of each game. Option 1 should read a game record (title, quantity, and price) from the user and insert the record into the game list. Option 2 should ask the user for a game name and delete the record that exactly matches the name from the game list. Option 3 should list all the games stored in the list in the lexicographical order of the game names, which represent the games in stock of the store. Option 4 allows the user to type a search key (a string), then searches all the games with names containing the key as the substring, from the game list. For example, if the search key is “abc”, the name of “csabcuky” matches, but the name of “csabukcy” does not match. If a matched game has been found, displays the information of the found game record, otherwise, reports No Matched Game in stock. Option 5 quits the program. To make it simple, for this program, assume the game name is case sensitive. (e.g., “Battleship Game” and “battleship game” are considered as two different games) Complete the class definition of the following two classes Game and GameList and use them in your program. Note you can add other member functions to the class Game and/or the class GameList, if you need them for your program, but you should not remove either data members or member functions from the following declarations.

class Game {

public: Game(string n, int c, double p, double s):name(n), count(c),

price(p), score(s) {}

private:

string name; //game name

int count; //number of copies in stock

double price; //game price

double score; //user score, in the range [0, 10.0]

friend class GameList;

};

class GameList {

public:

GameList(); //default constructor

~GameList(); //destructor

// Insert a new game record into the game list.

// The game has name gn, number of copies in stock is gc

// price is gp, and user score is gs

// Note that the vector of Game objects should be maintained

// in the lexicographical order based on the game names.

// If the game name already exists in the list,

// then upgrade the record with gc, gp and gs.

void Insert(string gn, int gc, double gp, double gs);

// Search for matched games with the given key of GName

// A game whose name contains GName will be found

// If a game is found, print its name, number of copies in stock,

// the price and user score

// otherwise report No Matched Game is in stock. void Search(string GName);

// Delete a game record with the name of GName,

// If the game is not in the list, do nothing. void Delete(string GName);

// Print the game records in stock

// They are in the lexicographical order based on game names

void print();

private:

int gameCount; // total number of game copies in stock

vector<game>glist; // a vector to store Game objects in stock

};

I have Game.h and GameList.h created withe given code, and I have GameList.cpp created with functions needed (main has yet to be written). Could you write a program so I can compare my code with yours? I want to see if I am on the right track,

Explanation / Answer

class Game {

public: Game(string n, int c, double p, double s):name(n), count(c),

price(p), score(s) {}

private:

string name;

int count;

double price;

double score;
friend class GameList;

};

class GameList {

public:

GameList(); //default constructor

~GameList(); //destructor
int gameCount;

vector<game>glist;
int i=0;

void Insert(string gn, int gc, double gp, double gs);
{
Game gObj=new Game(gn.gc,gp,gs);
glist.insert(gObj,i); //specify position
i++;
}


void Search(string GName)
{
glist::iterator it = find_if(glist.begin(), glist.end(),
boost::bind(&Game::name, boost::placeholders::_1, GName));

if(it!=NULL)
{
cout<<"Match Found";
cout<<it.name<<it.price<<it.score;
return "found";
}
else {
cout<<"No match found";
return "Not found";
}
}

void Delete(string GName);
{
string test=search(GName);
if(test.equals("Found"))
{
  glist::iterator it = find_if(glist.begin(), glist.end(),
boost::bind(&Game::name, boost::placeholders::_1, GName));
  
  free(it);
}
else cout<<"No such game exists";

}

void print();
{
for(Game* it = a; it != (a + (sizeof a / sizeof *a)); it++) {
    cout << *it;
}
}

};

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote