Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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 (but no colon at the end):

The place (like Notre Dame or New England)

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

Wins (an integer)

Losses (an integer)

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 (but no colon at the end):

Nickname of home team

Score of home team (an integer)

Nickname of visiting team

Score of visiting team

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:

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

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

Use #define to give a name to this constant

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, its 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. Were skipping the save step for that reason.

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

Modern Database Management

Authors: Jeffrey A. Hoffer Fred R. McFadden

4th Edition

0805360476, 978-0805360479

More Books

Students also viewed these Databases questions