Main

Lab 1

Assignment 1

In this lab, unlike the rest of the labs in this class, we will focus on getting through as much of Assigment 1 as possible, so work on that, and ask questions about anything that is unclear.

If you are done with the assignment, you can tackle the following problems.

I/O and Memory practice

1. A simple data structure for storing scores for a class: Define a struct that contains a string (can be a fixed-sized char array) for the student's name and an array to store the (integer) scores for various assignments -- at this point we won't worry about what assignments these scores correspond to, we just want to associate them with the name. Note that we also don't know how many scores each student has, but you can assume a reasonably high maximum and define this as a static array, or you may choose to allocate memory for it dynamically later. Finally, this struct should also have a floating-point field for storing the average (which you'll compute later).

For a refresher on C structs, see Chapter 4.7 in Sventek (C book on Canvas).

2. The student data is in a file (example file students.txt; fake names courtesy of this blog). Read it in, and create an array of student records, each of the records is an instance of the struct described in 1. For an added challenge, you can make the number of scores for each student different (in the given students.txt file, all students have the same number of scores).

3. Calculate the average of all scores for each student, store it in the average field of the student structs.

4. Print out nicely formatted list of names and averages (e.g., CSV).

5. Clean up dynamically allocated memory.

Optionally, you can try implementing different versions and comparing their performance. The very simplest way to do this is to run each example with the bash time command, but also use the -v flag, so you can see more details, such as the memory footprint.

Green Marinee theme adapted by David Gilbert, powered by PmWiki