// Ch. 12 Demo Program #5
// Mr. Minich
// purpose - to illustrate the use of a class with 3 files (the main source file,
// the header file (interface) and an implementation source file.
#include <iostream.h>
#include "M:\C++ Programming\AP classes\apstring.h"
#include "student.h"
int main()
{
Student teachersPet;
Student classHacker;
teachersPet.GetNameAndGradeLevel();
classHacker.GetNameAndGradeLevel();
return 0;
}
// ****************************************************************
// student.h header file (the interface of the Student class)
#include "M:\C++ Programming\AP classes\apstring.h"
class Student
{
public:
void GetNameAndGradeLevel();
private:
apstring name;
int gradeLevel;
char grade;
};
// ****************************************************************
// student.cpp source file (the implementation of the Student class)
#include "student.h"
#include <iostream.h>
void Student::GetNameAndGradeLevel()
{
cout << "Enter a name and grade level: ";
cin >> name;
cin >> gradeLevel;
}
// Note that you must use the MS Visual C++ menu command "Project/Add to Project/Files..."
// to include the student.cpp file to your project workspace before executing this program.
// Realize that the implementation for a class is often not able to be viewed by other programmers
// since that code is precompiled into object code. The interface (student.h) must be accessible
// by those who want to use the class since other programmers need to know what the public functions
// and member variables are. Technically, the private section doesn't have to be seen by such programmers
// but even if a hacker knew what the private member variable names are, he still can't access it from
// a main function.