Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

C++ Program The players.txt file (the 4 columns are name, gender, occupation, and gold respectively, aligned with tabs) Specifications - players.txt is a tab-delimited text

C++ Program

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

The players.txt file (the 4 columns are name, gender, occupation, and gold respectively, aligned with tabs) Specifications - "players.txt" is a tab-delimited text file that contains the information of all player characters in an RPG game. Each player character has the name (a string), the occupation (a string), the gender (a string) and the number of gold coins (an integer). Both name and gender must allow spaces. - The program should create two enumerations: the first one is named Command, with five enumerators display, add, remove, exit, and invalid, and the values start at 1; the second is named Occupation, with five enumerators Warrior, Mage, Bowman, Thief and InvalidOccupation. - The program should create a structure named GamePlayer with four member variables, name of string type, gender of string type, occupation of Occupation type and gold of int type, to store the information of a player character. - The program should create a vector of GamePlayer objects named player characters to store the information of all player characters in the game as a local variable of main(). - The program should create two functions get_occupation from_string(string) and get string from occupation(Occupation) to perform conversions between the string type and the Occupation type. - The program should create a function read file_into_vector(vector \&) to load the data from the file "players.txt" into this vector player characters. In the process, each character's occupation will be converted into the corresponding Occupation value by calling get_occupation from_string(string) and only the object with occupation value unequal to Occupation::InvalidOccupation will be inserted into the vector. This function should be called first before the program is ready to receive commands from the user. - The program will later call a function print command menu( providing a menu of commands as shown in the Console Sample including displaying information of all player characters, adding a player character, removing a player character and exiting the program. If an invalid command is received, the command menu will be displayed again besides an error message as shown in the Console Sample. - To get user's current command, the program should call a function get command 0 to ask for user's input and return the corresponding Command value converted from the integer received. Then a function process_command(Command, vector & ) will be called to deal with each command received from the user. - A function will be created for each command except for exiting the program. - In the function adding a player character, the occupation input by the user will be converted into the corresponding Occupation value before being compared with Occupation::InvalidOccupation and it will keep asking for the next input of occupation until a valid occupation has been received. - In the function adding a player character, there is no need to check whether the character to be added has already existed or not as duplicate entries are allowed in the vector player_characters. - After adding or removing a player character, a function write players file(const vector \&) will be called to save the updated data back to the same file. Your program should be able to handle unexpected data in file. (Hint: use the stringstream class together with the ifstream class.) Create a program to manage player characters in an RPG game. Note: Bold words are output while non-bold words are input in the following console sample. Console Sample RPG Character Manager COMMAND MENU 1. Display information of all player characters 2. Add a player character 3. Remove a player character 4. Exit program Command: 5 Invalid command. COMMAND MENU 1. Display information of al1 player characters 2. Add a player character 3. Remove a player character 4. Exit program Command : 2 Create a Mage, Warrior, Bowman, or Thief. Name: Terry Occupation: bowman Invalid occupation, try again. Occupation: Bowman Gender: M Gold: 340 Command : 3 Number to delete: 4 Removed player character. Command: 3 Number to delete: 4 Invalid number entered. Try again. Command: 4 Bye

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions

Question

What is the formula to calculate the mth Fibonacci number?

Answered: 1 week ago