Modern C++ • C++20 baseline
Capstone: Build a Tested Command-Line Catalog
Combine value types, containers, algorithms, file handling, and error reporting in a real program.
Build a small catalog manager that reads records from a text file, validates each field, supports search and sorting, and writes a summary. Separate parsing from domain logic and output. Use RAII for files and containers, and make invalid records observable rather than silently skipping them.
Key points
- Keep a record type independent of the command-line interface.
- Test malformed input, empty files, duplicate identifiers, and write failures.
Example
#include <string>
#include <vector>
struct Entry {
std::string id;
std::string title;
};
std::vector<Entry> load_entries(const std::string& path);
void write_summary(const std::vector<Entry>& entries,
const std::string& output_path);
What to expect
A complete implementation should validate each record, sort deterministically, and report read/write failures.
Practice exercise
Add a test plan before implementation. Include valid input, malformed rows, duplicate IDs, and missing files.
Key idea: Professional C++ is the consistent application of types, ownership, error handling, tests, and measured design.