Skip to article frontmatterSkip to article content

Project 05: Processing Video Game Data

Introduction

In this project, you will use the C++ Standard Template Library (STL) vector class to store and analyze video game data retrieved using the Bridges Library.

You can see an example application that pulls the video game data here. (Click on the C++ tab.)

Each Game is stored in a Game object. Information about the Game class is here.

Inspect that web page now to see what information you can retrieve about a Game.

The database contains 17,534 games in 33 genres. When you retrieve the games, they are not in any sorted order.

This assignment is to process the games to

Step 1. Setup

Make your proj5 repo as normal, using this link.

You will need to make yourself a Bridges Account here.

Please use your Calvin information, and do fill in the optional fields correctly. Use “CS112” as the Course number.

To build your program use make. It produces an executable called games.

To run your program you have to provide two command-line arguments: your Bridges UserName and your Bridges Id. E.g., I run the program this way:

./games VictorNorman 1313148564

To get your username and id, login to the bridges project, and go to the Profile page where you will see your “User Name” and “API Sha1 Key”. That second thing is your unique id.

Step 2. Information about using vector

You will use the STL’s vector class template multiple times. The functions I used from the vector class were:

In addition, you’ll need to use the find() function which is outside of the vector class. Here is an example of how to use it to search a vector<string> called genre_vec:

if (find(genre_vec.begin(), genre_vec.end(), "Pinball") == genre_vec.end()) {
    // "Pinball" was not found in genre_vec.
}

The find() function takes three parameters: where to start looking, where to stop looking, and what to look for. If the target string (“Pinball”) is not found at all, then the function returns yourvector.end(). In all uses of your code, you will always search the entire vector, so always use yourvector.begin() and yourvector.end() as the first two parameters.

To sort a vector<string> you can just do this:

sort(yourvector.begin(), yourvector.end());

Step 3: Implement collecting all the genres for the games

In the starting code you received in your repo, you’ll see that main.cpp implements a simple menu system to allow the user to choose what action to take. Your job is to fill in the code to implement those actions, and at the end, add your own option.

Start by implementing the “collect/show all genres” option in the function collectAllGenres(). This function takes one parameter — the vector of Game objects — and returns a vector of strings containing all the discovered genres, in sorted order. Make sure you pass in the parameter efficiently (do not use pass-by-value).

The function should first create a variable — I called it all_genres — that is a vector of strings. It will hold all the genres seen. Then, the function should loop through all the Game objects in the vector, and for each Game, loop through all genres the game belongs to. For each genre, it should search all_genres. If the new genre has not been seen before, add it to the end of the all_genres vector using push_back().

After getting all genres from all games, you should sort the vector and then return that vector of strings.

Your main code should print out the genres in a nice list with numbers in front, like this:

All genres:
0. Action
1. Adult
2. Adventure
3. Baseball
4. Battle
5. Board
6. Card
7. Casino
8. Compilation
... etc ...

Step 4. Print all games in a selected genre

In the case statement in the main code, ask the user for a number of a genre: (the user enters 32 below)

Enter a number of a game genre to see how many games are in that genre: 32

From that number, index into your vector of game genres to get the name of that genre. Then, call a function, described below to get all titles in that genre. After you get the titles, print each one out.

Your function needs to iterate through all games, looking for the games that belong to a given genre. I called my function getTitlesInGenre(). The function should return the vector<string> containing those games’ titles, in sorted order. My implementation of getTitlesInGenre() takes two parameters — the vector of all Games, and a string that holds the genre to search for. Make sure you pass both parameters in efficiently.

Remember that a game can belong to multiple genres, so you’ll have to get the genres for each game, and go through each genre to look to see if the game belongs to the “target” genre.

Don’t forget to sort the results before returning it from the function.

The main code should then print out the result from the function.

Step 5. Implement something else interesting

In this step, you get to implement something of your own choosing.

Add comments to your code to describe what your option does (if it isn’t obvious). Put your code in its own function.

Here are some ideas, but I’d prefer if you came up with your own:

Testing

The graders will test your code by running the pexpect script, test.exp, you see in your repo. They will do this by just running

python test.exp

That script runs your game’s executable and sends it menu items, looking for the correct output. You could try this against your code too. This should work on lab machines, but won’t work on your machine unless you install the python pexpect library.

Submission

Take a look at the Grading Rubric below and make changes to maximize your score.

Don’t forget to Commit and SYNC your changes to your repo.

Grading Rubric

This project is worth 20 points:

Ways students lost points in the past: