// Constructors and Destructors // destructors.cpp // OOP244 // Feb 5 2009 #include #include #include using namespace std; const int M = 13; class Student { int no; char grade[M+1]; public: Student(); ~Student(); void set(int n, const char* g); void display() const; }; // initializes the data values // Student::Student() { cout << "Entering constructor" << endl; no = 0; grade[0] = '\0'; } // exectued just before object goes out of scope // Student::~Student() { cout << "Entering destructor for " << no << endl; } // resets the data values of the object // void Student::set(int n, const char* g){ // see former example for validation code no = n; strcpy(grade, g); } void Student::display() const { cout << no << ' ' << grade << endl; } int main () { Student harry, josee; harry.set(1234, "ABACA"); josee.set(1235, "BBCDC"); harry.display(); josee.display(); return 0; }