Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ CodeBlocks wont allow me to print in letters for the genre such as FPS #include #include #include #include #include using namespace std; //Enum type

C++ CodeBlocks

wont allow me to print in letters for the genre such as FPS

#include #include #include #include #include using namespace std;

//Enum type of game enum type{A,B};

// Structure for video game struct videoGame { string title; type genre; int rank; double time; };

// Add game void addGame() { struct videoGame *v=new videoGame; ofstream out;

// Open the text file in append mode out.open("games.txt", std::ios_base::app); cin.ignore();

// Read the values from the user cout<<"Enter the title: "; getline(cin,v->title); int typ; cout<<"Enter the type: "; cin>>typ; if(typ==0) v->genre=A; else v->genre=B; cout<<"Enter the rank: "; cin>>v->rank; cout<<"Enter the time: "; cin>>v->time;

// Write it to the file out<title<<" "<genre<<" "<rank<<" "<time<

// Function to print the gamne void printGame() { // Open the input file ifstream in; in.open("games.txt"); struct videoGame *v=new videoGame; cout<<"Title"<<"\t"<<"Type"<<"\t"<<"Rank"<<"\t"<<"Time"<

// Read the file while(in>>v->title) { int typ; in>>typ; if(typ==0) v->genre=A; else v->genre=B; in>>v->rank; in>>v->time;

// Print the information cout<title<<"\t"<genre<<"\t"<rank<<"\t"<time<

// Calculate teh total time taken void totalTime() { ifstream in; double tim=0.0; in.open("games.txt"); struct videoGame *v=new videoGame; while(in>>v->title) { int typ; in>>typ; if(typ==0) v->genre=A; else v->genre=B; in>>v->rank; in>>v->time;

// Add the time tim=tim+v->time; } cout<<"Total time taken :"<

// Calculate the average rank void averageRank() { ifstream in; double ran=0.0; double avg; int count=0; in.open("games.txt"); struct videoGame *v=new videoGame; while(in>>v->title) { int typ; in>>typ; if(typ==0) v->genre=A; else v->genre=B; in>>v->rank; in>>v->time;

// Total rank ran=ran+v->rank; count++; } avg=ran/count; cout<<"Average rank :"<

// Function to edit the data file. // Ask the user to give the tiltle of the game // of which the dta has to be edited // Here the data edited is time void editData() { cin.ignore(); string tit; ifstream in; in.open("games.txt"); ofstream out; out.open("games1.txt"); cout<<"Enetr the title whose data to be changed: "; getline(cin,tit); cout<>v->title) { int typ; in>>typ; if(typ==0) v->genre=A; else v->genre=B; in>>v->rank; in>>v->time; if(v->title==tit) { cout<<"Enter the updated time: "; cin>>v->time; } out<title<<" "<genre<<" "<rank<<" "<time<

// Write back to the orginal file in.open("games1.txt"); out.open("games.txt"); while(in>>v->title) { int typ; in>>typ; if(typ==0) v->genre=A; else v->genre=B; in>>v->rank; in>>v->time; out<title<<" "<genre<<" "<rank<<" "<time<>ch; switch(ch) { case 1: addGame(); break; case 2: printGame(); break; case 3:totalTime(); break; case 4:averageRank(); break; case 5: editData(); break; case 6: break; default: cout<<"Wrong choice"<

}while(ch!=6);

// Pause the output terminal system("pause"); return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle PL/SQL Programming Database Management Systems

Authors: Steven Feuerstein

1st Edition

978-1565921429

More Books

Students also viewed these Databases questions