File: README Name: XXXXXXXXXXXX (English as Second Language student) CS 70 - Assignment 3 Date: October 8, 1999 ============================================================================= PROGRAM PURPOSE This program works as a registrar database of a school. This program maintains database of students and courses so user can periodically update courses' schedule and students' hair color. This program can enroll a student who is already in the database to a course that also in the database. Similarly, it can also drop a student from a course. Also, this program can print a display of the information of all students and courses in the database. INCLUDED FILES 1. A Makefile for this program 2. assign_03.cc It is the driver program of this assignment. It provides interactive interface of the school registrar database for the user. It supports 9 commands. When it takes a valid command, it prompts the user for inputs. 3. registrar.hh This file describes the interface of the Registrar_DB class. 4. registrar.cc This file is the implementation of the Registrar_DB class. It is supported by Student class and Course class. 5. student.hh This file describes the interface of the Student class. 6. student.cc This file is the implementation of the Student class. It interacts with the Course class and supports the Registrar_DB class. 7. course.hh This file describes the interface of the Course class. 8. course.cc This file is the implementation of the Course class. It interacts with the Student class and supports the Registrar_DB. 9. readstring.hh This file describes the interface of the readString function. 10. readstring.cc This file is the implementation of the readString function. This readString function is used to read inputs by assign_03.cc THE CLASSES I. Registrar_DB class The data members of Registrar_DB class are: 1. students - an array of all students. 2. courses - an array of all courses. 3. maxStudents - an integer type, the maximum number of students allowed in the database. 4. maxCourse - an integer type, the maximum number of courses allowed in the database. 5. numStudents - an integer type, the current number of students. 6. numCourses - an integer type, the current number of courses. Functions defined in Registrar_DB class are: 1. The constructor and destructor The constructor initializes all data members of the class. While the destructor destroys everything that is created by new. 2. canAcceptStudents A function that returns a boolean true value if there is still room to add a new student. It simply compares the current number student less than the maximum number of students. 3. canAcceptCourses It is similar to canAcceptStudents except it checks whether there is still room to add course. It simply compares the current number of courses to the maximum course number 4. newStudent It adds new student to the database. First, it calls canAcceptStudents to check if the database still have room for another student. If it is, then it calls the fillInInfo of Student class to act as a constructor. 5. newCourse Similar to newStudent. It adds new course to the database if the true value is returned by canAcceptCourses. Then it calls the fillInInfo of the Course class to construct the data in the new course. 6. findStudentByName It returns a pointer to Student with the same full name as the argument. First, it combines the inputs which are first and last name into a temporary full name. Then, compares the result with every students' full name in the database by calling function name of the Student. 7. findCourseByName Similar to findStudentByName. It returns a pointer to Course with the same department name and course number. It calls courseIs of the Course to compare all the courses in the database with the inputs. 8. showStudents Displays a presentation of all students. It calls print function of Student for each student in the database. 9. showCourses Similar to showStudents. It displays a presentation of all courses in the database. It calls print function of Course for each course. II. Student class The data member of Student class are: 1. fullName - an array of char, represents the full name 2. hairColor - an array of char, represents the hair color 3. schedule - an array of pointer to Course that are being taken. 4. courseCount - an integer type, number of courses currently taken. Functions defined in Student class are: 1. The constructor and destructor The constructor initializes all data members, combining together fullName from firstName and lastName also initializes and allocates spaces for the schedule. The destructor deletes all data members allocated by new. 2. fillInInfo Basically, it does the same thing as the constructor. Only that it does not create a new student, just filling in the null equivalent data. 3. name It simply return the full name of a Student. 4. isOverloaded It simply checks whether a Student is overloaded or not by comparing the current course taken with the maximum course allowed. 5. alreadyInCourse It simply checks whether a Student is already enrolled to a specific course or not by comparing each course name in his/her schedule to the specific course name. 6. itsMe It simply compares two Students' full name whether they are the same. It returns a boolean true value if they are the same. 7. imBehind It simply compares two Students' full name, in order to alphabetized the names. It returns boolean true value if the caller should go after the other one. 8. changeHairColor It changes the hairColor data of a Student. It first deletes the old hair color, and then initializes a new array of char for the new hair color. 9. addCourseToSchedule It inserts a course to a Student's schedule if the student hasn't enrolled to that course. It finds the first available location to put the course. Also it automatically calls the addStudent function of Course and increment the course counter. It returns boolean true value if it is successful. 10. removeCourseFromSchedule It does the opposite of addCourseToSchedule. First, it checks whether the student has enrolled before. Then, finds the course in the Student's schedule. Sets that location to NULL. Also decrement the course counter. It also automatically calls the removeStudent of Course. If it is successful then return a boolean true value. If not, it returns false. 11. dropAllCourses It simply cleans up the schedule in a student. The routine is very similar to removeCourseFromSchedule, except that it does not find a specific course first. 12. print It simply prints the presentation of the Student. The full name, hair color and the list of all currently taken courses. 13. makeFullName It is a private function. What it does is combine the first name and the last name into a full name. III. Course class The data members of Course class: 1. department - array of char, represents the department name 2. courseNumber - an integer, represents the course ID 3. meetingTime - array of char, represents the scheduled time 4. maxEnrollment - an integer type, the limit of how many students can enroll. 5. numStudsInCourse - an integer type, number of students currently enroll. 6. roster - an array of pointer to Student that are enroll. Function defined in Course class are: 1. The constructor and destructor The constructor initializes all data members of the class and set all the Student pointer in roster to point at NULL. The destructor deletes all the things created by new in constructor. 2. fillInInfo Basically, it does the same thing as the constructor. Only that it does not create a new student, just filling in the null equivalent data. 3. getDepartment It is simply a function that returns the department name. 4. getCourseNumber It is simply a function that returns the course number. 5. isFull It returns a boolean true value if the course has reached its maximum enrollment. 6. courseIs It returns a boolean true value if the course department and number match the inputs. 7. addStudent This function adds a student to a course. But, before adding a student to the course, first we need to check whether the course is not full yet. Because it is called by a student function that already checked if the enrollee is not in this course, so it doesn't have to do it again. When there's room for the enrollee, add him/her to the first available slot. If the total student in the course is only one, it doesn't have to bother to alphabetized the roster. If there are more than one, so it should alphabetized the roster. 8. removeStudent This function drops a student from a course. It is called by a student function that remove this course from his schedule. Because it is called by a function which already checked whether this dropper is in this course, it doesn't have to do the same thing again. So what it does first is finding the student who wants to drop this course in its roster list. If he's found, set the slot to available (NULL) and note that there's a gap in that exact spot. Removing only a student at a time means that the list is still alphabetized. So, the next thing it should do is only to remove the gap. Then reduce the current size of the course. 9. changeMeetingTime This function change the meetingTime data of a course. First, it deletes the old meetingTime so there won't be any memory leak. And then allocates the exact space for the new meetingTime (remember to reserve one space for the null terminator). After that use the string copy function to copy the new meetingTime. 10. kickOutStudents Kick all roster out from the course. It forces all the roster to call their removeCourseFromSchedule function, so it will also automatically call the removeStudent function for each roster. 11. showName The purpose of this function is to print a display of just only the course name, which consist of department and courseNumber. e.g., "CS70". 12. print This function prints representation of a course. It prints the department, the course number, the meeting time. And also, the list of the roster enrolled in this course. To print a roster full name, it calls the Student's name function. It also use '\t' which is a tab to align the roster' names. It ignores an empty slot in roster. 13. removeGap This is a function that is called each time a student drop a course. It will remove the gap left by the student, so the roster list will be kept packed. The only thing to do is to move all the slots after the gap one location left, because nothing happened to the slots before the gap. And there is an exception for the last slot, because there is nothing after it. Remember, that there is at least a gap because of the dropper, so the last slot must be empty. 14. alphabetized This function maintain the roster in alphabetical order according to their full names. It compares two roster at a time. It takes a roster starting from the one in the second slot), and compares him to the roster in front of him, without paying attention to the ones behind. After it has reached the first slot roster, it takes another roster whose slot was just one location behind him (before he got sorted). And it does this routine to all the remaining roster. This function is called every time a student enroll to a course and there are more than one roster in the course. 15. swapRoster This function maintain the roster in alphabetical order according to their full names. It compares two roster at a time. It takes a roster starting from the one in the second slot), and compares him to the roster in front of him, without paying attention to the ones behind. After it has reached the first slot roster, it takes another roster whose slot was just one location behind him (before he got sorted). And it does this routine to all the remaining roster. This function is called every time a student enroll to a course and there are more than one roster in the course. THE COMMANDS - INPUTS / OUTPUTS There are 10 supported commands in the registrar database: 1. quit Terminate the program 2. help Print a simple help message 3. student Add a new student, prompting for name and hair color 4. course Add a new course, prompting for department, course number, meeting time, and maximum enrollment. 5. enroll Enroll a student in a course, prompting for the student's name, course' department and number 6. drop Drop a student from a course, prompting as for "enroll" 7. hair Change a student's hair color, prompting for name and hair color 8. time Change a course' meeting time, prompting for the new information 9. show students Display all students, including the names of the course they are currently enrolled 10. show courses Display all courses, including the names of the students currently enrolled in each. How the commands work? In getting a command, the program performs a loop from the readString function and return a string then match it with one of the commands. If it's not matched, it returns an error message and asks to enter a command again. If the command entered is quit, the program simply goes to the end of the program and halts. If help is entered, the program simply prints a help message. If student is entered, the program will call the doAddStudent routine which first calls the Registrar_DB canAcceptStudents() function and check whether there's room. If yes, it takes the input from user and then creating new strings from the input (lastName, firstName, and hairColor). Then it calls the addStudent function from the Registrar_DB which calls the fillInInfo function from Student class. The course command is similar only it calls the fillInInfo from Course class. If enroll command entered, the findStudentByName will be called and then the findCourseByName will also be called. If the student is not overload, it then check if the course is not full. If everything is fine, then the program will call the addCourseToSchedule from Student class which then will call addStudent from Course class. Drop command is similar to enroll except it just calls removeCourseFrom Schedule function which will check if the student really enrolls there. If not, it will print some error messages. On the other hand, if she does enroll, it will set the Course* to NULL and call the removeStudent from Course class. The hair command will only call findStudentByName, after that it will call the changeHairColor from Student class. The time command will only call findCourseByName and calls changeMeetingTime from Course class. show students command will call the showStudents function from Registrar_DB class which will call print function from Student class. This print function will also call the showName function from Course class. show courses command will call the showCourses function from Registrar_DB class which will call print function from Course class. this print function will call the name function from Student class. ALGORITHMS The sorting algorithm is used in the Course class. The roster list should be kept in alphabetical order according to their full names. The sorting works like this. It takes a value and compares it to the values in front of it (the values behind it are ignored). It starts by taking the value in the second position, and compares it with the first position. If they are in the right places, goes to the value in the position after it (in this example, the third position). If not, swap them. This goes all the way until the last position is the one that is taken. DATA STRUCTURES The data structures used in this program is a fixed multiple array for the registrar database. They are an array of students and an array of courses where both of them also contains arrays of pointer to either course or student. In every student there's also an array of courses, while in every course there is an array of pointer to students. RESTRICTION, LIMITATION AND BUGS First, there is only a limited commands to this database. We can not cancel a registered course or expel a student. The program will halt if we enter a string when it expects an integer for the input. Also, if we typed student or course command, we cannot cancel it. So, everything we type after that will be saved as a new student or course. However, there is no known bug in the program.