1 answer

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

Question:

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;
};


Answers

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.</p><p>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.</p><p>Display All

.

Similar Solved Questions

1 answer
Acrylic bone cement is sometimes used in hip and knee replacements to fix an artificial joint...
Acrylic bone cement is sometimes used in hip and knee replacements to fix an artificial joint in place. The force required to break an acrylic bone cement bond was measured for six specimens under specified conditions, and the resulting mean and standard deviation were 306.09 newtons and 41.92 newto...
1 answer
A city mayor you know is interested in recruiting Amazon to build in their city but...
A city mayor you know is interested in recruiting Amazon to build in their city but doesn't know what a company considers before choosing where to build a processing plant. She has hired you to help her and her city council understand what decision factors Amazon might consider before making its...
1 answer
Consider the following partially completed income statements for merchandising companies and compute the missing amounts: (Click...
Consider the following partially completed income statements for merchandising companies and compute the missing amounts: (Click the icon to view the Income Statements.) Data Table Fit Apparel Laura's Bakery $ 99,000 Fit Apparel Laura's Bakery 99,000 32,000 $ (d) 48,000 Net Sales Revenue Cos...
1 answer
The p-value for a hypothesis test is shown Use the P-value to decide whether to re...
The p-value for a hypothesis test is shown Use the P-value to decide whether to re ed HO when the level of significance is a)a:0。1 b 0 05 and c r:0 10. P 0.0612 (a) Do you reject or fail to reject Ho at the 0.01 level of significance? O A. Fal to reject Ho because the P-value, o 0612, is less...
1 answer
Find the 8 errors in the following paragrah and put the correct information. a stomach preparation...
find the 8 errors in the following paragrah and put the correct information. a stomach preparation is required for several procedures that visualize the lower bowel. This preparation is important for effective test results. An incomplete bowel preparation mag prevent the test from being done or cau...
1 answer
Consider a 82 m x 43 m, nine-storey Supermarket building. Is it a 'high building according...
Consider a 82 m x 43 m, nine-storey Supermarket building. Is it a 'high building according to OBC Subsection 3.2.6? Assume a typical storey height of 3.2 m, that average grade is 763 mm below the ground floor level, and its exit stair risers are 187 mm. Use the minimum Code permitted exit stair ...
1 answer
How do you find the limit of #1/(x^3 +4)# as x approaches #oo#?
How do you find the limit of #1/(x^3 +4)# as x approaches #oo#?...
1 answer
Hi! Please help me on this question #41. Thank you so much! (by giving the p.m.f....
Hi! Please help me on this question #41. Thank you so much! (by giving the p.m.f. or p.d.f.) whose the cumulative distribution function F(t) satisfies F(n) = 1 - 1 for each positive integer n. Exercise 3.41. We produce a random real number X through the following two- stage experiment. First roll a...
1 answer
Lagrange Polynomials You just watched some poor kid let go of her balloon in a 8-m...
Lagrange Polynomials You just watched some poor kid let go of her balloon in a 8-m high mall food court. The four data points at right represent the height of a balloon (H, in meters) as a function of time (t, in seconds). (a) Create the 3rd-order Lagrange polynomial that exactly passes through all ...
1 answer
3. A 55 kg student is standing on a rigid, 3 meter, 10 kg, plank that...
3. A 55 kg student is standing on a rigid, 3 meter, 10 kg, plank that is resting on two scales, one on either end of the plank. The student is standing 0.9 meters from the left scale. a) (10 pts) What does the right scale read (in kg)? 855kg lokg Tons Slot x 1,5 m 3n= right = (2.1 XSS 1 - (3.0 xloxy...
1 answer
How do you solve #2cos(x/3)+sqrt2=0#?
How do you solve #2cos(x/3)+sqrt2=0#?...
1 answer
Nment MESSAGE MY İNSTRUCTOR FULL SCREEN : PRINTER VERSION : BACK NEXT Chapter 32, Problem 009...
nment MESSAGE MY İNSTRUCTOR FULL SCREEN : PRINTER VERSION : BACK NEXT Chapter 32, Problem 009 In the figure a uniform electric field is directed out of the page within a circular region of radius R electric at radial distances (a)2.50 cm and (b)7.00 cm? 3.50 cm. The magnitude of the (4.00 x 10 ...
1 answer
Required Information Problem 13-2A Ratios, common-size statements, and trend percents LO P1, P2, P3 [The following...
Required Information Problem 13-2A Ratios, common-size statements, and trend percents LO P1, P2, P3 [The following information applies to the questions displayed below.) Selected comparative financial statements of Korbin Company follow KORBIN COMPANY Comparative Income Statements For Years Ended De...
1 answer
A chemical manufacturer produces three different chemical products. The profit per unit, the labor and raw material required per unit, and the pollution emitted per unit are given in the file. This co...
A chemical manufacturer produces three different chemical products. The profit per unit, the labor and raw material required per unit, and the pollution emitted per unit are given in the file. This company’s two objectives are to maximize profit and minimize pollution produced. The company wan...