Video Games Write a program that stores the following data about a video game in
ID: 3591642 • Letter: V
Question
Video Games Write a program that stores the following data about a video game in a structure: Field Name title genre rank time Description string (name of qame) enum (type of game) float/double Use an enumerated type for the genre field that contains the following enumerators: FPS, MOBA, RolePla The program should create an array of 5 game structures and initialize it with the following information: Rank Time (days) Title League of Legends Team Fortress 2 Hearth Stone Halo Genre MOBA FPS RolePlay FPS MOBA 16.75 425 0.75 6.75 TA 2 Use a menu-driven interface to allow the user to n for all games, sorted in decreasing order by rank, in table form. 1. Print the informatio 2. Print the information for a specific game, using a full or partial title match 3. Print the total time spent for all games 4. Print the average rank for all games. Options 1 and 2 should use a function to print the text corresponding to a given genre Your program should be modular with separate functions for input and each part of the processing. You may put the output for a given option in the function that processes that option. Your output should be well- organized, neat, and easy to read an nocument. Be sure to include a structureExplanation / Answer
#include<iostream>
#include<string>
using namespace std;
enum type { FPS, MOBA, RolePlay };
struct game{
string title;
type gener;
int rank;
double time;
};
double averageTime(game data[]){
double sum = 0;
for (int i = 0; i<5; i++)
sum = sum + data[i].time;
return sum/5;
}
double totalTime(game data[]){
double sum = 0;
for (int i = 0; i<5; i++)
sum = sum + data[i].time;
return sum;
}
void search(game data[], string str){
double sum = 0;
size_t found;
for (int i = 0; i<5; i++) {
found = data[i].title.find(str);
if (found != string::npos){
cout << "Title: " << data[i].title << endl;
cout << "Gener: " << data[i].gener << endl;
cout << "Rank: " << data[i].rank << endl;
cout << "Time: " <<data[i].time << endl;
}
}
cout << "Not Found ";
return;
}
void display(game data[]){
double sum = 0;
for (int i = 0; i<5; i++){
cout << "Title: " << data[i].title << endl;
cout << "Gener: " << data[i].gener << endl;
cout << "Rank: " << data[i].rank << endl;
cout << "Time: " <<data[i].time << endl;
}
}
void sort(game data[]){
game temp;
for (int i = 0; i<5; i++){
for (int j = i; j<5; j++){
if (data[i].rank < data[j].rank){
temp.title = data[i].title;
temp.gener = data[i].gener;
temp.rank = data[i].rank;
temp.time = data[i].time;
data[i].title = data[j].title;
data[i].gener = data[j].gener;
data[i].rank = data[j].rank;
data[i].time = data[j].time;
data[j].title = temp.title;
data[j].gener = temp.gener;
data[j].rank = temp.rank;
data[j].time = temp.time;
}
}
}
}
int main(){
game data[5];
int n;
string title;
data[0].title = "League of Legends";
data[0].gener = MOBA;
data[0].rank = 3;
data[0].time = 9.5;
data[1].title = "Team Fortress 2";
data[1].gener = FPS;
data[1].rank = 5;
data[1].time = 16.75;
data[2].title = "Hearth Stone";
data[2].gener = RolePlay;
data[2].rank = 2;
data[2].time = 4.25;
data[3].title = "Halo";
data[3].gener = FPS;
data[3].rank = 1;
data[3].time = 0.75;
data[4].title = "DOTA 2";
data[4].gener = MOBA;
data[4].rank = 2;
data[4].time = 6.75;
sort(data);
cout << "1.Print all games ";
cout << "2.Search a game ";
cout << "3.Print time for all games ";
cout << "4.Print average rank ";
cout << " Enter your choice :";
cin >> n;
switch (n) {
case 1 : display(data);
break;
case 2 : cout << "Enter the title :";
cin >> title;
search(data,title);
break;
case 3 : cout << "Total Time : " << totalTime(data) << endl;
break;
case 4 : cout << "Average Time : " << averageTime(data) << endl;
break;
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.