CS-211 Fall 2015 Lab 6 Arrays


This week, things are pretty simple. The scenario is that you are a teacher, and have given some tests to your students. The grades for these tests are kept in a file called grades.txt. You already have a C program that reads this file, and puts the grades into a matrix in C with one row for each student, and one column for each test. The program already prints out all the grades, as well as preserving space for information about each test... the minimum, maximum, and average grade for each test. However, the values for the minimum, maximum, and average grades are bogus. You get to fix that problem in this lab.

Getting Started

Download the code that has been started for you in lab6.tar.gz. Use the command tar -xvzf lab6.tar.gz. This will unpack the tar file and make a new lab6 subdirectory. The lab6 directory will have a Makefile, a sample grades file called grades.txt, and the C code to start from in file gradeBook.c

The gradeBook.c File

The gradeBook.c file starts of with the standard includes for standard library functions, and a couple of #defines to establish the biggest number of students and the biggest number of grades (rows and columns) we can deal with.

The next thing that appears in the gradeBook.c file is declaration for three variables... grades, which is a matrix to hold the specific grade values, as well as two integers, numStudents which holds the number of students for which grades are available, and numGrades which holds the number of different tests for which grades are available. Since these three variables are defined outside of any specific function, they are "global" variables, which means that any function can read or write the values for these variables.

What follows the global declaratios is just the normal function declarations and definitions that we are used to seeing. I've included a description of each of these functions below.

Using The Makefile

The Makefile file in the lab6 directory contains "targets" which allow you to do several things using the make command. The following targets are supported:

Getting Minimums, Maximums, and Averages

Your job, after you get a feel for how this code works (compile it, run it, look at the code), is to modify the minGradeForTest, maxGradeForTest, and avgGradeForTest functions so that they work correctly (find the minimum, maximum, and average grade for a test.) Each of these functions gets a "gr" parameter which defines which test (column) of the grades matrix you should work on. You need to figure out how to go through the grades in that column, for all students (from student 0 up to student (numStudents-1)), and figure out for those grades... what is the lowest grade, the highest grade, and the average grade.

Lab Report

Download and edit the following file: lab6_report.txt. Then submit your editted file on Blackboard in the Lab_06 report area.