< previous page page_781 next page >

Page 781
Arrays of Records
Although single records can be useful, many applications require a collection of records. For example, a business needs a list of parts records, and a teacher needs a list of students in a class. Arrays are ideal for these applications. We simply define an array whose components are records.
Let's define a grade book to be a list of students as follows:
const int MAX_STUDENTS = 150;

enum GradeType {A, B, C, D, F};

typedef char NameString[16];

struct StudentRec
{
    NameString firstName;
    NameString lastName;
    float      gpa;
    int        programGrade;
    int        quizGrade;
    int        finalExam;
    GradeType  courseGrade;
};

StudentRec gradeBook[MAX_STUDENTS];
int        length;
int        count;
This data structure can be visualized as shown in Figure 14-3.
An element of gradeBook is selected by an index. For example, gradeBook[2] is the third component in the array variable gradeBook. Each component of gradeBook is a record of type StudentRec. To access the course grade of the third student, we use the following expression:
0781-01.gif
To access the first character in the last name of the third student, we use the following expression:

 
< previous page page_781 next page >