< previous page page_775 next page >

Page 775
To access the final exam score of student, we would write
student.finalExam
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif 3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
Member Selector The expression used to access components of a struct variable. It is formed by using the struct variable name and the member name, separated by a dot (period).
The component of a struct accessed by the member selector is treated just like any other variable of the same type. It may be used in an assignment statement, passed as a parameter, and so on. Figure 14-2 shows the struct variable student with the member selector for each member. In this example, some processing has already taken place, so values are stored in some of the components.
Let's demonstrate the use of these member selectors. Using our student variable, the following code segment reads in a final exam grade; adds up the program grade, the quiz grade, and the final exam grade; and then assigns a letter grade to the result.
cin >> student.finalExam;
grade = student.finalExam + student.programGrade +
        student.quizGrade;
if (grade >= 900)
    student.courseGrade = A;
else if (grade >= 800)
    student.courseGrade = B;
else .
     .
     .
0775-01.gif
Figure 14-2
Struct Variable 
student with Member Selectors

 
< previous page page_775 next page >