This is your capstone — every concept from the course comes together here. Design a program that manages a collection of books using classes, vectors, file I/O, and exception handling.
YOUR TASK
Write a C++ program that:
Defines a Book class with title, author, and year
Stores books in a vector<Book>
Has an addBook() method and a displayAll() method
Finds and prints the oldest book in the collection
Uses at least one constructor and one getter
Prints Total books: N at the end
Hint 1 — Class Structure
Suggested class: class Book { string title, author; int year; public: Book(string t, string a, int y) string getTitle() { return title; } int getYear() { return year; } void display() { ... } };
Then use a vector<Book> library; and push books with library.push_back(Book(...));
Hint 2 — Finding the Oldest
Loop through the vector tracking the minimum year: Book oldest = library[0]; for (auto& b : library) if (b.getYear() < oldest.getYear()) oldest = b;
For the test, hardcode 3 books — e.g. Dune (1965), 1984 (1949), Neuromancer (1984). The checker looks for "1984" as the oldest and "Total books: 3".
Example output (3 hardcoded books):
--- Library ---
Dune by Frank Herbert (1965)
1984 by George Orwell (1949)
Neuromancer by William Gibson (1984)
Oldest book: 1984 (1949)
Total books: 3
Code Editor
Ready
Output
Console
Console initialized...
Ready for the Final Project: Library System
> This is your capstone — bring everything together!
> Use "Check My Code" to validate, then complete the course!