Struct
Objective #1: Understand what structures are and how to use them.
struct Student
{
apstring socSecNum;
apstring lastName;
apstring firstName;
int pointsEarned;
double gpa;
};
allows the programmer to keep related data referring to individual students
together. Notice that this example groups strings, integer, and double variables
together into one structure. Each of the different variables are called members of the structure.
You still need to create an actual variable of the type,
Student, before you make use of this structure. This would be done with
a statement like,
Student freshmen;
which creates a variable called freshmen of the type Student (which happens
to be a structure as opposed to an int or a float.) Then, to assign a GPA
of 3.4 to the GPA field of the variable, freshmen, you would use the statement,
freshmen.gpa = 3.4;
The period symbol (.) that is used between the structure identifier, freshmen,
and the member, GPA, is called the dot operator. The dot
operator simply allows the
programmer to reference individual members of a structure.