Question

Write a program (C++) that shows Game sales. The program should use a structure to store...

Write a program (C++) that shows Game sales. The program should use a structure to store the following data about the Game sale:

Game company

Type of Game (Action, Adventure, Sports etc.)

Year of Sale

Sale Price

The program should use an array of at least 3 structures (3 variables of the same structure). It should let the user enter data into the array, change the contents of any element and display the data stored in the array. The program should have a menu driven interface.

Input Validation: When the data for a new game sale is entered, be sure the user enters data for all the fields. No negative amounts should be entered for a “Sale Price” of the Game.

An example:

You will use 1 structure only and then manipulate that for working with the information.

The program should use an array of at least 3 structures (3 variables of the same structure).


An example of the structure:
struct Game
{
string name;
string type;
int year;
double price;
};

0 0
Add a comment Improve this question Transcribed image text
Answer #1

In case of any query do comment. Please rate answer as well. Thanks

Code:

#include <iostream>
using namespace std;
#define MAX_SIZE 3

struct Game
{
string name;
string type;
int year;
double price;
};

//function to display menu
void displayMenu(){
std::cout << "************** Game Menu ***************" << std::endl;
std::cout << "1. Add Game" << std::endl;
std::cout << "2. Modify Game" << std::endl;
std::cout << "3. Display All Game" << std::endl;
std::cout << "4. Exit" << std::endl;
std::cout << "Enter you choice: ";
}
//take input for the game
void inputGame(struct Game& game)
{
  
cout << "Enter the name of the game: ";
cin >>game.name;
cout << "Enter type of game (Action, Adventure, Sports etc.): ";
cin >> game.type;
  
cout << "Enter the year of the game: ";
cin >> game.year;
  
game.price =-1;
  
while(game.price <0)
{
cout << "Enter the sale price of the game: ";
cin >> game.price;
}
}
//add game
void addGame(struct Game& game,int& currentSize){
inputGame(game);
currentSize++; //increase the curent size
}

//modify Game
void modifyGame(struct Game games[], int currentSize){
string name;
bool gameFound =false;
std::cout << "Enter the name of the game to be modfied: "; //take input the name of the game
cin >> name;
//search in array
for (int i = 0; i < currentSize; i++) {
if(games[i].name == name){
inputGame(games[i]); //if found then ask for new values
gameFound = true;
break;
}
}
  
if(!gameFound){
cout << name << " game is not found!!!" <<endl;
}
}

//display games
void displayGames(struct Game games[], int currentSize){
for (int i = 0; i < currentSize; i++) {
std::cout << "Name: " << games[i].name << " Type: " << games[i].type
<< " Year: " << games[i].year << " Price: " << games[i].price << std::endl;
}
}

int main()
{
struct Game games[3]; //array of three games
int currentSize =0;
int choice;
bool exitLoop = false;
  
while(!exitLoop){
displayMenu();
cin >> choice; //get choice from user
  
switch(choice){
  
case 1:
if (currentSize < MAX_SIZE ){
addGame(games[currentSize], currentSize);
}
else
{
std::cout << "Can't add more games!!!!" << std::endl;
}
break;
case 2:
if(currentSize >0)
modifyGame(games,currentSize);
else
std::cout << "No game added yet!!" << std::endl;
break;
case 3:
if(currentSize >0)
displayGames(games,currentSize);
else
std::cout << "No game added yet!!" << std::endl;
break;
case 4:
exitLoop = true;
break;
}   
}
  

return 0;
}

=============screen shot of the code=========

main.cpp 1 #include <iostream> 2 using namespace std; 3 #define MAX_SIZE 3 5 struct Game string name; 8 string type; 9 int ye

main.cpp cin >> name; //search in array for (int i = 0; i < currentsize; i++) { if(games[i].name == name) { inputGame(games[i

switch(choice) { case 1: if (currentsize < MAX SIZE ){ addGame (games(currentsize), currentsize); else std::cout << Cant ad

Output:

input M A X&tis Game Menu 1. Add Game 2. Modify Game 3. Display All Game 4. Exit Enter you choice: 2 No game added yet!! AAAA

input 3. Display All Game 4. Exit Enter you choice: 1 Enter the name of the game: Test3 Enter type of game (Action, Adventure

input ਆ ਜਾਂਦਾ ਸੀ ਜਾਂਦਾ ਸੀ । ਜੇ ਜੇ ਜੀਵ ਜੇ ਲਾ ਸ ਜੀ E m wri੫ ਫੈਲ ਜੇਲ ਭੇਲ ਜੋਲ ਸੀ ਜੋ ਜੀ 1. Add Game 2. Modify Game 3. Display All

Add a comment
Know the answer?
Add Answer to:
Write a program (C++) that shows Game sales. The program should use a structure to store...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a program that keeps track of a speakers’ bureau. The program should use a structure...

    Write a program that keeps track of a speakers’ bureau. The program should use a structure to store the following data about a speaker: (this is in C++) Name Telephone Number Speaking Topic Fee Required The program should use a vector of structures. It should let the user enter data into the vector, change the contents of any element, and display all the data stored in the vector. The program should have a menu-driven user interface. Input Validation: When the...

  • Write a program that uses a structure to store the following data about a customer account: Name Address City, sta...

    Write a program that uses a structure to store the following data about a customer account: Name Address City, state, and ZIP Telephone number Account Balance Date of last payment The program should use an vector of at least 20 structures. It should let the user enter data into the vector, change the contents of any element, and display all the data stored in the array. The program should have a menu-driven user interface. Input Validation: When the data for...

  • Football Game Scores Write a C++ program that stores the following data about a football game...

    Football Game Scores Write a C++ program that stores the following data about a football game in a structure: Field Name Description visit_team string (name of visiting team) home_score int visit_score int The program should read the number of games from a data file named “games.txt”, dynamically allocate an array of structures for the games using one structure for each game, and then read the information for each game from the same file (visiting team, home score, visiting team’s score)....

  • Write a C++ program that simulates a lottery game. Your program should use functions and arrays....

    Write a C++ program that simulates a lottery game. Your program should use functions and arrays. Define two global constants: - ARRAY_SIZE that stores the number of drawn numbers (for example 5) -MAX_RANGE that stores the highest value of the numbers ( for example 9 ) The program will use an array of five integers named lottery, and should generate a random number in the range of 0 through 9 for each element of the array. The user should enter...

  • Structures in C++ :- 1. Write a program that declares a structure to store the code...

    Structures in C++ :- 1. Write a program that declares a structure to store the code number, salary and grade of an employee. The program defines two structure variables, inputs record of two employees and then displays the record of the employee with more salary. 2. Write a program that declares a structure to store the distance covered by player along with the time taken to cover the distance. The program should input the records of two players and then...

  • Structures in C++ :- 2. Write a program that declares a structure to store the distance...

    Structures in C++ :- 2. Write a program that declares a structure to store the distance covered by player along with the time taken to cover the distance. The program should input the records of two players and then display the record of the winner. 3. Write a program that declares a structure to store income, tax rate and tax of a person. The program defines an array of structure to store the records of five person. It inputs income...

  • Write a C++ program that simulates playing the Powerball game. The program will generate random numbers...

    Write a C++ program that simulates playing the Powerball game. The program will generate random numbers to simulate the lottery terminal generated numbers for white balls and red Powerball. The user will have the option to self-pick the numbers for the balls or let the computer randomly generate them. Set the Grand Prize to $1,000,000,000.00 in the program. Project Specifications Input for this project: Game mode choice – self pick or auto pick Five numbers between 1 and 69 for...

  • please write in C++ Write a program that uses a structure to store the following inventory...

    please write in C++ Write a program that uses a structure to store the following inventory data in a file: The data can be either read from a text file or the keyboard Item name (string) Quantity on hand(int) Wholesale cost(double) Retail Cost(double) The program should have a menu that allows the user to perform the following tasks: Add new records to the file Display any record in the file User will provide the name of the item or the...

  • C++, data structure Write a program that plays a game called "guess the state, guess the...

    C++, data structure Write a program that plays a game called "guess the state, guess the capital". How do you play? The program randomly selects a state or a state capital. The program asks the player to guess the state's capital (or the capital's state). The program reads the user's guess; and, tells the user if its guess is right, or if the guess is wrong, tells the user that its guess is wrong and displays the correct answer. Before...

  • Write a C++ program that calculates the discount of the original price of an item and...

    Write a C++ program that calculates the discount of the original price of an item and displays the new price, and the total amount of savings. This program should have a separate header (discount.h), implementation (discount.cpp) and application files (main.cpp). The program must also have user input: the user must be prompted to enter data (the original price, and the percent off as a percentage). There must also be a validation, for example: Output: “Enter the original price of the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT