#include #include #include #include #include "ClassList.H" Student* GetStudent (void); void main() { int i, count, position; long idNum; Student* aStudent; ClassList theList; cout << endl << endl << "Testing Insert - How many students?" << endl; cin >> count; for (i = 1; i <= count; ++i) { aStudent = GetStudent(); position = rand() % (theList.GetCount() + 1) + 1; theList.Insert (position, aStudent); } cout << endl << endl; theList.Print(); cout << "Sum of GPA's = " << theList.GetGpaSum() << endl << endl; cout << endl << endl << "Testing Find and Delete - How many?" << endl; cin >> count; int listSize = theList.GetCount(); if (listSize == 0) { listSize = 1; // Avoid division by zero inside the loop } for (i = 1; i <= count; i++) { idNum = 100000001L + rand() % listSize; position = theList.Find (idNum); if (position == 0) { cout << "Id Number " << idNum << " not found" << endl; } else { cout << "Deleting Id Number " << idNum << endl; theList.Delete (position); } } cout << endl << endl; theList.Print(); cout << endl << endl << "End of Program" << endl; } /* This function automatically generates student data */ /* and returns a pointer to a dynamically allocated Student */ /* object intialized with the values generated. */ Student* GetStudent() { static int counter = 0; long idNum; char name [MAX_SZ_NAME + 1]; char address [MAX_SZ_ADDRESS + 1]; char major [SZ_MAJOR + 1]; int month; int day; int year; float gpa; counter++; idNum = 100000000L + counter; sprintf (name, "Student %d", counter); sprintf (address, "Address for Student %d", counter); strcpy (major, "CMSC"); month = 1; day = 1; year = 2000; gpa = 2.0F + (counter % 21) * 0.1F; return (new Student (idNum, name, address, major, month, day, year, gpa)); }