lecture_4-aggregation-New[1]
lecture_4-aggregation-New[1]
Composition (aggregation):
• Composition (aggregation)is a way to relate two classes.
• In composition (aggregation), one or more members of a class are
objects of another class type.
• It is another way to reuse the class. It is a form of association that
represents HAS-A relationship
Aggregation :
public:
Course(string course, string instrLastName, string instrFirstName, string instrOffice,
string textTitle, string author, string publisher)
{courseName = course;
instructor.set(instrLastName, instrFirstName, instrOffice); //Assign the instructor.
textbook.set(textTitle, author, publisher); // Assign the textbook
}
void print() const
{ cout << "Course name: " << courseName << endl << endl;
cout << "Instructor Information:\n";
instructor.print();
cout << "\nTextbook Information:\n";
textbook.print();
cout << endl;}
};
int main()
{
// Create a Course object.
Course myCourse("Intro to Computer Science", // Course name
"Kramer", "Shawn", "RH3010", // Instructor info
"Starting Out with C++", "Gaddis", // Textbook title and author
"Addison-Wesley"); // Textbook publisher