CS 250 Computer Programming and Problem Solving - FALL 1998 

[ Home | Syllabus | Notes | Glossary | CS250 WEB Version Home Page ]


Analysis

Good Example of a Scenario

Major Scenarios:

1) Student calls Registrar to enroll in a class
Registrar gives the student a list of classes offered
Student chooses class
Registrar enrolls student in class

2) Student calls Registrar to drop a class
Registrar gives the student a list of classes in which he is enrolled
Student chooses class
Registrar drops student from class

3) Student calls Registrar to get his schedule
Registrar displays list of courses in which student is enrolled

4) Student calls Registrar to get current bill
Registrar prints total credist and tuition bill for student

5) Registrar is directed to add a class to current offerings
Registrar queries for Course information // from where?
Registrar adds course to current offerings

6) Registrar is directed to add a student to the current students registered
Registrar queries for Student Information
Registrar adds student to current registration

7) Registrar is directed to display class roster
Registrar lists current course offerings
Class is selected
Registrar prints class roster

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.


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:

Input is trickier because you have to figure out how many items to input. Solutions:

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;
}


Copyright chris wild 1998.
For problems or questions regarding this website contact [Chris Wild (e-mail:wild@cs.odu.edu].
Last updated: November 11, 1998.