A类,注册类包含B类对象的私有数组,即Course类。
这是否意味着注册类取决于课程类,因为A类使用B类?或者更确切地说,它是一种聚合关系,因为A类有一个B类?
class Registration {
public:
Registration();
unsigned GetCredits() const;
unsigned GetCount() const;
friend ostream & operator <<( ostream & os, const Registration & R);
friend istream & operator >>( istream & input, Registration & R );
private:
long studentId; // student ID number
unsigned semester; // semester year, number
unsigned count; // number of courses
Course courses[MaxCourses]; // array of courses
};
class Course {
public:
Course();
Course( const char * nam, char sect, unsigned cred );
unsigned GetCredits() const;
void SetCredits( unsigned cred );
friend ostream & operator <<( ostream & os, const Course & C );
friend istream & operator >>( istream & input, Course & C );
private:
char name[CourseNameSize]; // course name, C style string. not a C++ string object
char section; // section (letter) can be enrolment mode
int credits; // number of credits
};