# SI 204 Spring 2017 / Labs

This is the archived website of SI 204 from the Spring 2017 semester. Feel free to browse around; you may also find more recent offerings at my teaching page.

# Lab 04: Sports Stats

This lab will exercise your skill with nested loops and iterative refinement. Some useful references will be the Unit 3 notes, Unit 4 notes, and, as always, the C functions reference for this class.

Submit in the normal way, being sure to put your files in a directory called lab04.

In this lab, you’re going to analyze some sports statistics that I copied from here and here. The files you want are basketball.txt and baseball.txt. Download them now and save them to your lab directory.

# 1 The best stat

Have a look at the two files you just downloaded. Something we clearly should be able to do with these files is write a program where the user enters a heading (like 3P%), and get back which team had the highest number for that column, and the value in that column:

roche@ubuntu\$ ./stats
Filename: basketball.txt
Column heading: 3P%
San_Antonio_Spurs 40.8

We’re going to write this program, in such a way that it will work for either file. By working on solving smaller problems along the way, we can build up gradually to a full solution.

Here are the steps we’re going to follow in a file called stats.c:

// get a filename and column heading from the user
// figure out which column has that header
//for each line
// get that team's name
// get that team's value at that column
// track the largest value seen so far
// print out the team name and value which was the largest

For this problem, pick small chunks to work on at a time, then combine those chunks to make a full program.

Important Notes:

• In case of a tie value in the selected field, your program should output the name of the first team in the file with the maximum value for that field.
• You can assume that the second line of the file always starts with the number 1.
• You can assume that the file always has 30 teams in it.

# 2 Going further: Spaces in team names

The rest of this lab is optional for your enrichment and enjoyment. Be sure to work on this only after getting everything else perfect. You should still submit this work, but make sure it doesn't break any of the parts you already had working correctly!

Actually, there is one way in which I modified the files above: I replaced space characters in the team names with underscores _.

For this part, download the actual copy/pasted files baseraw.txt and basketraw.txt and improve your stats.c program to be able to handle multiple space-separated words in the team names.

Hint: you may have to read ahead a bit in the Unit 4 notes in order to complete this part.