// File: main8.C // // Testing the Person class #include #include #include "person2.h" void SortByAge(Person **, int) ; void SortByAge(Person **A, int n) { int i, j, min, mindex ; Person* temp ; for(i = 0 ; i < n - 1 ; i++) { min = A[i]->age ; mindex = i ; for( j = i + 1; j < n ; j++) { if (A[j]->age < min) { min = A[j]->age ; mindex = j ; } } temp = A[i] ; A[i] = A[mindex] ; A[mindex] = temp ; } } int main() { int i ; Person **B = new Person * [5] ; B[0] = new Student("John Smith", 30, 1, 3.2) ; B[1] = new Student("Jane Doe", 27, 2, 3.4) ; B[2] = new Student("Groucho Marx", 40, 4, 2.1) ; B[3] = new Student("Tiny Tim", 6, 0, 3.0) ; B[4] = new Student("Bugs Bunny", 36, 0, 1.2) ; cout << "\nSorting Students as Persons:" << endl ; SortByAge(B, 5) ; for (i=0 ; i < 5 ; i++) { B[i]->id() ; } delete B[1] ; delete B[3] ; B[1] = new Faculty("Dr. Foo", 45, 17) ; B[3] = new Faculty("Dr. No", 37, 12) ; cout << "\nSorting Students & Faculty as Persons:" << endl ; SortByAge(B, 5) ; for (i=0 ; i < 5 ; i++) { B[i]->id() ; } }