A contact book
The problem
Build a program that adds, searches, deletes and lists contacts from typed commands, and saves them to a file between runs.
Requirements
- Each contact is a struct or class with a name, a phone number and an email address
- Contacts are kept in a map from name to contact, so that listing is alphabetical
- Commands include add, find, delete, list, save and quit
- Saving and loading use file streams, and a missing file is handled calmly
- Errors in commands give a clear message and do not stop the program
- The program uses no raw new or delete
Technologies
- C++
- map and string
- File streams
- Exceptions
Step by step
- Define the Contact type, and write a function that prints one.
- Write functions for adding, finding and deleting, each taking the map by reference.
- Write the list function, taking the map by const reference.
- Write save and load, using one line per contact.
- Write the command loop, reading a line and splitting it with a string stream.
- Add checks for missing arguments and unknown names.
- Restart the program and confirm that the contacts came back.
- Compile with -Wall -Wextra, and fix every warning.
Expected result
A working command-line address book whose data survives between runs.
How it is evaluated
- Contacts survive a restart
- Bad commands never crash the program
- Large values are passed by const reference
- The code compiles with no warnings
Ways to improve it
- Search by part of a name
- Export the contacts as CSV
- Keep several phone numbers for each contact