Scenario:
You are required to design a system using object-oriented programming
that demonstrates an aggregation relationship. A Library aggregates
multiple Book objects. Each Book can exist independently, but the Library
uses them to provide functionality.
Part A: Book Class
Implement a Book class with the following attributes and methods:
Attributes (private):
__Title → string (e.g., "Clean Code")
__Author → string (e.g., "Robert Martin")
__Pages → integer (e.g., 464)
Methods:
getTitle(), getAuthor(), getPages() → return respective values
OutputBookDetails() → print book details in the format:
Title: <title>, Author: <author>, Pages: <pages>
Part B: Library Class
Implement a Library class that aggregates multiple Book objects.
Attributes (private):
__LibraryName → string (e.g., "City Central Library")
__Books → list of Book objects
__TotalBooks → integer (tracks number of books in the library)
Methods:
AddBook(book_obj) → adds a Book object to the library
OutputLibraryDetails() → prints library name, total books, and details of
each book
Part C: Demonstration
1. Create a Library object.
2. Create at least three Book objects with different titles, authors, and
page counts.
3. Add these Book objects to the Library.
4. Output the library details.
5. The program should output:
Library contains 3 books: Title: Clean Code, Author: Robert Martin,
Pages: 464 Title: Design Patterns, Author: Gamma et al., Pages: 395
Title: Python Crash Course, Author: Eric Matthes, Pages: 544