Assignment: Write a C++ program that uses structs, arrays, files, and command line arguments. The program processes data for soccer players, inputs data from a file and outputs data to a file.

Discussion: You program should utilize 3 files.

player.txt - Player name data file It has: player ID, player first name, middle initial, last name
soccer.txt Player information file It has: player ID, goals scored, number of penalties, jersey number

output file - formatted according to the example provided later in this assignment

  • Define a struct to hold the information for a person storing first name, middle initial, and last name).
  • Define a struct to store the data for a Soccer player storing the player's name (use the struct created earlier), position (Forward, etc.), number of goals scored, number of penalties committed, his/her Jersey number, and status.
  • Declare an array of 30 (use a named constant) components/structs, one for each player.

Include the following capabilities:

1) A bool function to check if a given file (its parameter) exists or not. The function will have the file name as parameters. The function should return false, if the file cannot be found. You can use the returned value to terminate the program, if a valid file name has not been entered by the user. You can call this function twice, once to check for the player name file and once to check for the player information file.

2) A void function to read the data into the array from the data files (player name and player information data files). The function should accept as parameters the input data file names and the array of struct. The file names are supplied through the command line arguments.

3) A void function to identify the status of a player: 0-1 goals scored is Poor, 2-4 goals scored is Good, and more than 4 goals scored is Excellent. The identification is INVALID for any other situation. This value will be stored in the status field of the struct.

4) A void function to write the data to a file whose named is entered through the command line argument. The function accepts the file name and the data array as its parameter. Display the data using a tabular format placing a space after each data item. See the sample output a bit later.

The main function should only be a collection of function calls in addition to the required declaration of variables. You will also process the command line arguments in the main function.

Input data file example (player.txt):

Item 1: ID
Item 2: First name
Item 3: Middle initial
Item 4: last name

Input data file example (soccer.txt):

Item 1: ID
Item 2: position
Item 3: Number of goals scored
Item 4: Number of penalties
Item 5: Jersey number

Here is an example of the input data file (player.txt):

1 Larry L Page
2 Sergey B Brin
3 Marissa A Mayer

Here is an example of the input data file (soccer.txt):

1 forward 8 2 21
2 defense 12 0 82
3 goalkeeper -1 0 5

Here are some sample runs:

./a.out
Error: program needs arguments – Example: ./a.out player.txt soccer.txt output.txt

./a.out player.txt soccer.txt output.txt

Here is a sample output file - output.txt

Larry L Page 8 2 21 forward Excellent
Sergey B Brin 12 0 82 defense Excellent
Marissa A Mayer -1 0 5 goalkeeper INVALID

Of course, above is just a sample example. Anyone with 2 - 4 goals will be considered Good, etc. make sure to fully test your code with various data values.

./a.out playerzz.txt soccer.txt output.txt

Missing input data file: playerzz.txt - terminating program

./a.out player.txt socceroo.txt output.txt

Missing input data file: socceroo.txt - terminating program

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.