// Ch. 12 Demo Program #2
// Mr. Minich // purpose - to review the use of a struct definition
#include <iostream.h> #include "M:\C++ Programming\AP classes\apstring.h" struct Student { apstring name; int gradeLevel; char grade; }; int main() { Student teachersPet; Student classClown; cout << "Enter name and grade level of teacher's pet: "; cin >> teachersPet.name; cin >> teachersPet.gradeLevel; cout << "Enter name and grade level of class clown: "; cin >> classClown.name; cin >> classClown.gradeLevel; teachersPet.grade = 'A'; classClown.grade = 'F'; cout << "The teachers pet's grade is " << teachersPet.grade << endl; cout << "The class clown's grade is " << classClown.grade << endl; return 0; }// end of main // If you need to use Student variables in future programs, you can easily reuse the same struct definition // by placing the struct definition into another file, say student.h, and then replacing the struct definition // above with the compiler directive // #include "student.h" // (It is conventional to use a .h file extension for such header files. // Of course, you would type the file's pathname in the double quotes if it were not stored in the same folder // as your executable file.) Note that double quotes are used and not angle brackets. // Remember that the variables within the Student struct definition are called member variables and that you still have // to declare two Student variables within the main function.