Question
Introduction The purpose of this lab is to reinforce the principles of Modular Programming by creating a collection of games. Activity You are required to
Introduction
The purpose of this lab is to reinforce the principles of Modular Programming by creating a collection of games.
Activity
You are required to write a C++ program that maintains an Inventory of Computer Games. You are required to program this Lab using Modular Programming. Your solution should contain GameInventory.h, GameInventory.cpp and Source.cpp. Please submit these 3 files on Canvas.
Your program is expected to start with collection of games in a vector (refer to main method provided below). The main method would then try to add a game which is not already part of the vector and hence should be successfully added to the vector. The main method then tries to add a game to the vector which already exists in the vector, the program should display a message that game already exists and should not add this game to the vector.
Your program should have a class GameInventory with the following details:
private
string name;
string brand;
int year;
double price;
publicGameInventory();
A default constructor used to initialize data members to appropriate default values.
GameInventory(string name, string brand, int year, double price);
A parameterized constructor used to initialize data members to their corresponding values from the parameters
string getName();
A getter method that returns name
string getBrand();
A getter method that returns brand
int getYear();
A getter method that returns year
double getPrice();
A getter method that returns price
void displayGame();
A display method that displays all the details about this class. Refer to the screenshot below.
bool isSimilar(const GameInventory& game);
This method would compare two objects of GameInventory class and returns true if they are equal.
Hint: Objects are considered equal if values of data members of one object are equal to corresponding values of another object.
Your program should have following 3 global methods in the header file of GameInventory:
bool searchInventory(vector
Searches for a game in the vector of games. Please note that vector provided to this function is expected to contain collection of games. Use the bool isSimilar(const GameInventory& game) method created in the class above to compare this game with each element of the vector which itself is a GameInventory object. Refer to main method for more information on this.
void displayInventory(vector
Displays all the elements (games) in the vector. Refer to the screenshot on how to display the information.
bool addNewGame(vector
Adds a specific game to the vector. This function should have a try catch block. If element is inserted to the vector successfully then return true from the try block else return false from the catch block.
You can only use
You must use this main method to run your program. Save the code in this file as Source.cpp and submit it along with your code (you should not modify this file).
Below is the screenshot of the expected output of this program
Eurrent Games in the Inventory lame: Need for Speed, Brand: XBox, Year: 2e18, Price: 45 lame: Hitian 2, Brand: Playstation, Year: 2020, Price: 75.5 lame: Mario Brothers, Brand: Nintendo, Year: 2010, Price: 30 lame: Assassin's Creed, Brand: Playstation, Year: 2e21, Price: 70.5 lame: Uncharted 4: A Thief's End, Brand: Playstation, Year: 202e, Price: 85 lame: Spiderman Miles Morales, Brand: XBox, Year: 2021, Price: 65.5 lame: Resident Evi1, Brand: XBox, Year: 2018, Price: 45 Ndding another game in the Inventory... following Game added to the inventory successfully ... lame: Hitman 3, Brand: Playstation, Year: 2022, Price: 95 Eurrent Games in the Inventory lame: Need for Speed, Brand: XBox, Year: 2018, Price: 45 lame: Hitman 2, Brand: Playstation, Year: 2020, Price: 75.5 lame: Mario Brothers, Brand: Nintendo, Year: 2010, Price: 30 lame: Assassin's Creed, Brand: Playstation, Year: 2021, Price: 70.5 lame: Uncharted 4: A Thief's End, Brand: Playstation, Year: 2020, Price: 85 lame: Spiderman Miles Morales, Brand: XBox, Year: 2021, Price: 65.5 lame: Resident Evi1, Brand: XBox, Year: 2018, Price: 45 lame: Hitman 3, Brand: Playstation, Year: 2022, Price: 95 Adding another game in the Inventory... Following Game already exists in the Inventory... lame: Need for Speed, Brand: XBox, Year: 2018, Price: 45 Eurrent Games in the Inventory lame: Need for Speed, Brand: XBox, Year: 2018, Price: 45 lame: Hitman 2, Brand: Playstation, Year: 2020, Price: 75.5 lame: Mario Brothers, Brand: Nintendo, Year: 2010, Price: 30 lame: Assassin's Creed, Brand: Playstation, Year: 2021, Price: 70.5 lame: Uncharted 4: A Thief's End, Brand: Playstation, Year: 2020, Price: 85 lame: Spiderman Miles Morales, Brand: XBox, Year: 2021, Price: 65.5 lame: Resident Evil, Brand: XBox, Year: 2018, Price: 45 lame: Hitman 3, Brand: Playstation, Year: 2022, Price: 95Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started