#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 Prepend - How many students?" << endl; cin >> count; for (i = 1; i <= count; ++i) { aStudent = GetStudent(); theList.Prepend (aStudent); } cout << endl << endl; theList.Print(); cout << endl << endl; theList.Dump(); cout << endl << endl << "Emptying the list..." << endl; theList.Empty(); cout << endl << endl; theList.Dump(); cout << endl << endl << "Testing Append - How many students?" << endl; cin >> count; for (i = 1; i <= count; ++i) { aStudent = GetStudent(); theList.Append (aStudent); } cout << endl << endl; theList.Print(); cout << endl << endl; theList.Dump(); 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 << endl << endl << "Testing Find and Delete - How many?" << endl; cin >> count; for (i = 1; i <= count; i++) { idNum = 100000001L + rand() % theList.GetCount(); 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; //theList.Dump(); } } 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; return (new Student (idNum, name, address, major, month, day, year)); }