Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

CS 421 Spring 2023 homework 1

Write a C (not C++!) program in hw1.c that reads team records from a file, updates the records from a set of scores, displays the updated standings sorted by winning percentage, highest to lowest. Here are the details:

·            The team records are stored, one team to a row. Each row is broken down into the following fields, which are separated by colons ‘:’, ending with a ‘\n’ (but no colon at the end):

o   The place (like Notre Dame or New England)

o   The nickname (like 49ers or Blue Jackets – this is guaranteed to be unique)

o   Wins (an integer)

o   Losses (an integer)

o   Ties (an integer)

·            Each file contains scores for games between 2 teams – including teams not included in the records. Each row has the score for one game and can be broken down as follows, separated by pipe characters (|’s) , ending with a ‘\n’ (but no colon at the end):

o   Nickname of home team

o   Score of home team (an integer)

o   Nickname of visiting team

o   Score of visiting team

o   We are not really using the “home” and “visiting” information, but this is a standard way of reporting scores and one reason why you cannot assume the first score is bigger.

·            General restrictions:

o   The teams are from the same group, so the records are all listed together

o   The number of teams is constant, which we will make 4 for this assignment

§  Use #define to give a name to this constant

o   The number of games is not known in advance: teams may play each other, a team may play more than one game in a file.

§  Note that fgets() returns NULL if it reaches the EOF condition.

·            For example, here is what output for a simple case:

ubuntu@cs421:~/hw1$ more rec0.txt

Arizona:Cardinals:0:0:0

Los Angeles:Rams:0:0:0

San Francisco:49ers:0:0:0

Seattle:Seahawks:0:0:0

ubuntu@cs421:~/hw1$ more scores1.txt

Cardinals|21|Chiefs|44

Rams|10|Bills|31

Bears|19|49ers|10

Seahawks|17|Broncos|16

ubuntu@cs421:~/hw1$ !.

./a.out rec0.txt scores1.txt

Updated standings

Team                    W-L-T   Pct

Seattle Seahawks        1-0-0   1.000

Arizona Cardinals       0-1-0   0.000

Los Angeles Rams        0-1-0   0.000

San Francisco 49ers     0-1-0   0.000

ubuntu@cs421:~/hw1$

Note on computing winning percentage – ties count as “half a win”

Style: Provide a brief comment to describe the program and each function you define, use meaningful names for the variables. Use #define for any constants you use, and use those names in the code.

Grading:

Correctness 80%

Style 20% -- 10% comments, 10% naming (including naming and using named constants)

Overall, you want to make sure what you turn in compiles and runs correctly, so if you do not manage to finish everything, it’s better to submit something that runs, leaving out changes that cause the code to not compile or crash.

Note on saving the results: It would be natural to update your file (the rec0.txt file in the example), but then running the program a second time would be using a different input, making debugging harder. We’re skipping the save step for that reason.