CS 250 Computer Programming and Problem Solving - FALL 1998 |
---|
[ Home | Syllabus | Notes | Glossary | CS250 WEB Version Home Page ]
Analysis
How many recognized the need to search the lists for a specific object?
Good Example of a Scenario Major Scenarios: |
1) Major scenarios: - user attempts to add a student possible outcomes: student added student already exists - user attempts to add a new course possible outcomes: course added course already exists - user attempts to add a class for a student possible outcomes: student not found course not found student already signed up for that course student successfully registered - user attempts to drop a course for a student possible out comes: student not found course not found student not signed up for that course student successfully dropped from course - user requests student bill printouts possible outcomes: no students on file report printed - user requests a list of courses for a student possible outcomes: student not found student not signed up for any courses report printed - user requests a class roster for a course possible outcomes: course not found no students signed up for course roster printed 2. Objects and their relationships STUDENT; uses-a REGISTRATION COURSE; uses-a REGISTRATION REGISTRATION; uses-a STUDENT and COURSE |
Scenarios for the Student Registration System Problem: Scenario 1: 1. Student asks registrar to add a course. 2. Registrar checks course scheduler to see if course is full. 3. Course scheduler shows available roster spots. 4. Course scheduler adds student to course roster. 5. Student's total credit hours are (re)calculated. Scenario 2: 1. Student asks registrar to add a course. 2. Registrar checks course scheduler to see if course is full. 3. Course scheduler shows no available roster spots. 4. Course scheduler informs student that course is full. Scenario 3: 1. Student asks registrar to drop a course. 2. Registrar asks course scheduler to remove student from course. 3. Course scheduler removes student from course roster. 5. Student's total credit hours are recalculated. Scenario 4: 1. Student asks registrar to print his/her class schedule. 2. Registrar brings up student's record. 3. Registrar prints student's class schedule (list of courses). Scenario 5: 1. Registrar needs to print tuition bill for student. 2. Registrar brings up student's record. 3. Registrar calculates tuition bill for student. 4. Registrar prints tuition bill for student. Scenario 6: 1. Registrar needs to print course roster. 2. Registrar brings up course's record. 3. Registrar prints list of students enrolled in course. Scenario 7: 1. Registrar needs to add course to list of courses. 2. Registrar provides required information about course. 3. Registrar adds course to list of courses. Scenario 8: 1. Registrar needs to add student to list of students. 2. Registrar provides required information about student. 3. Registrar adds student to list of students. Scenario 9: 1. Registrar needs to remove course from list of courses. 2. Registrar deletes course from list of courses. Scenario 10: 1. Registrar needs to remove student from list of students. 2. Registrar deletes student from list of students. |
How about the circular problem of students contain lists of courses and courses contain lists of student?
How about Input and Output on List Objects?
Raw Arrays in specification files
I/O and Lists
Problem: how to do Input and Output for Lists using overloaded insertion and extraction operators.
Output is fairly easy but you need the following things:
A way to iterate through the items in the list
and overloads of the I/O for the type of the object stored in the list.
Input is trickier because you have to figure out how many items to input. Solutions:
hard code in the number of items to input (see Doctors example)
read until end of file
Put special marker on last item (this allows multiple objects to be stored in the same file)
Put the number of items in the list before the individual items themselves.
Let's explore the last option, showing an example using the LongArray object, discussed previously.
// p248.txt - LongArray Class Definition class LongArray { friend ostream & operator <<(ostream & oStream, const LongArray & theArray); friend istream & operator >>(ostream & iStream, LongArray & theArray); public: LongArray( unsigned sz = 0, long defval = 0 ); // Construct an array of size sz, initialize all // elements with defval. LongArray( const LongArray & L ); // Copy constructor. ~LongArray(); // Destructor. unsigned GetSize() const; // Return the current allocation size. void GrowBy( unsigned n ); // Increase the allocation size by n elements. void Init( long defval = 0 ); // Initialize all elements to defval. long Get( unsigned i ) const; // Retrieve element at index position i. void Put( unsigned i, long elt ); // Insert element at index position i. private: long * data; // ptr to array containing elements unsigned size; // current allocation size long initv; // initial value };
ostream & operator <<(ostream & oStream, const LongArray & theArray) { oStream << size << endl; // first record how many object will follow in the file for(int i = 0; i < size; i++) { cout << data[i] << endl; } return oStream; }
istream & operator >>(istream & iStream, LongArray & theArray) { iStream >> size; for(int i = 0; i < size: i++) { iStream >> data[i]; } return iStream; }