CS 245 Homework 1
- Due Date
- 4:00 pm Friday September 11
- Assignment Name
- premier
- File Names
- premier.c
Write a program called premier that reads premier league scores for a season from standard input. The input file is a CSV file with this format:
Liverpool,4,Bournemouth,2 Aston Villa,0,Newcastle,0 Brighton,1,Fulham,1 Sunderland,3,West Ham,0 Tottenham,3,Burnley,0 Wolves,0,Man City,4 ...
It will print out the season results in this format:
Arsenal 26 7 5 85
Man City 23 9 6 78
Man United 20 11 7 71
Aston Villa 19 8 11 65
Liverpool 17 9 12 60
Bournemouth 13 18 7 57
...
The team name will be printed in a field of width 20. The other columns are wins, draws, losses, and points. Wins, draws and losses will be fields of width 2 and points will be a field of width 3. The fields are separated by a single space.
Calculating points: wins get 3 points, draws 1, and losses 0.
Your program will include the following ingredients:
- A team struct with fields for name, wins, draws, losses, and points.
- An array of team structs.
- A function that can linear search the array for a team, returning its position. As you read through the data, if a team has not appeared yet, add it into the array.
- A comparison function for teams that sorts first by points and then by name.
- Use the qsort function to sort the array.
- You can make the name fields arrays of size 20. That will be large enough for Nottingham Forest which is the longest team name.
- In class we will discuss how to read the data using scanf.
- You program should be commented appropriately. Use meaningful variable names and programming constructs.