pretest homework

Task

Your task is to generate a F1 racing event results. The results will be displayed on the screen with an option to store them to a file.

Generic requirements

  • Program must be written in either C90, C99, C11 or C17 standard. GNU extensions are permitted. The necessary C standard version must be specified in the header of the code file.
  • You can only use standard libraries and the GNU extensions.
  • The program must compile under either
    • Ubuntu 24.04 with GCC-13 (based on the recommended software)
    • OpenSUSE Linux 15 SP5 with GCC-11 (lab configuration)
  • All arrays must be created with static sizes
    • Arrays must be large enough that the program can operate within the specified limitations. Specification is listed under task specifications
    • Program does not need to work with larger inputs, but also must not crash when those are entered. The decision on how to handle improper input is left to the developer.
  • If the program uses dynamic memory allocation, all of the best practices regarding it must be followed. All dynamically allocated memory must be freed before exit. Note that dynamic memory is not a part of Programming 1, so it is not necessary to use it.
  • Program must be divided into functions.
  • Use of global variables is forbidden
  • Use of GOTO statements is forbidden
  • The user experience for the program must be clear. Any errors  that occur must be described to the user of the application in a clear manner. The program is not allowed to “just close” without informing the user what happened.

Program flow general description

  1. The program will read the names of the pilots from an input file and pick the participating pilots.
  2. The number of laps will be specified by the user inside of the program by inputting the number..
  3. All lap times are generated as random numbers.
  4. Total time is calculated for each pilot who participated.
  5. Pilots, their lap times and the total time is shown on the screen as a table.
  6. If an output file name was specified as a command line argument, all results are also written to the output file with that name as a CSV file.

Task specific requirements

  • The program will take either 1 or 2 arguments from the command line
    • Execution pattern:   ./binary_name number_of_pilots [name_of_output_file]
    • First argument is the number of pilots participating. This argument is mandatory.
    • Second argument is the name of the output file. This argument is optional. If this argument is given, an output file that name with the name will be created. Results will be stored into that file.
  • The program must support up to 10 participating pilots. The maximum length for the name name of a participant is 32 characters. The number of laps can range from 5 – 15.
  • The first n pilots will be chosen to participate in the race, based on the order that they are given in the input file. n is the number of pilots, given from the command line. You must validate that you have enough pilots given in the data file.
  • Each lap time will be a randomly generated number between 70 and 125 seconds.
  • Each pilot will have a 3% probability that they have to abandon the race during any lap. If a pilot needs to abandon, they will no longer drive the following laps. The decision (dice roll) will be redone on each lap.
  • For pilots who abandon the race, a -  symbol will be used for the lap that they stopped on and all the following laps. Previous lap times must be present. The total time for that pilot will be presented as DNF (did not finish).

Data file requirements

Input file

The names of pilots will be read by the program from a file called pilots.dat.  The data file must be in the same directory as the binary fine. Name of the file will be hardcoded into the program.

The data file is formatted as an ASCII text file, containing all pilots with the format  initial.last_name.  Names are separated by a space. The number of names can range from 5 – 10.

Names for the input file

Output file

The program will generate a CSV file. File must contain a header with the column names. As data, you need to include the name, all lap times and total time. The output file will be created in the same directory as the binary file.

Examples of expected output

Example  1

Example 2:

Example 3: