CS 250 Computer Programming and Problem Solving - FALL 1998 

[ Home | Syllabus | Notes | Glossary | CS250 WEB Version Home Page | Project Page | Final Study Guide]


Analysis

How about the circular problem of students contain lists of courses and courses contain lists of student?

Here are a couple of solutions and non-solutions:

class Student {
   Student(const Student &); // copy constructor
private:
   SeqList<Course> Schedule;
}
class Course {
   Course(const Course &); // copy constructor
private:
   SeqList<Student> Roster;
}
// copy constructors do deep copies
// SeqList has a copy constructor which does deep copy

Problem: Circular construction = goes into infinite loop (check out the code)

img001.GIF (6525 bytes)

 


Same as above but use a constructor which creates a "truncated copy" - that is copies everything but the List

Problem: What if something changes in original object.

img002.GIF (6228 bytes)

 


 

class Student {
   Student(const Student &); // copy constructor
private:
   SeqList<Course *> Schedule;
}
class Course {
   Course(const Course &); // copy constructor
private:
   SeqList<Student *> Roster;
}
// copy constructors do deep copies
// SeqList has a copy constructor which does deep copy

img003.GIF (7314 bytes)

 


class Student {
   Student(const Student &); // copy constructor
private:
   SeqList<VString> Schedule;
}
class Course {
   Course(const Course &); // copy constructor
private:
   SeqList<FixedString> Roster;
}
// copy constructors do deep copies
// SeqList has a copy constructor which does deep copy

img004.GIF (7933 bytes)

 

 


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