- Introduction
- Directory Structure
- Dependencies
- Compilation and Execution
- Usage
- Commands
- Contact Format
- Code Details
The Contact Management System is a C++ program that allows users to manage contact information using a binary search tree (BST). Contacts can be imported/exported from/to CSV files, added, updated, marked as favorites, and displayed in various orders.
├── cms.out
├── contact.cpp
├── contact.h
├── contact.o
├── contactbst.cpp
├── contactbst.h
├── contactbst.o
├── contacts.csv
├── main.cpp
├── main.o
├── Makefile
├── myvector.cpp
├── myvector.h
├── myvector.o
└── README.md
This program requires the following:
- A C++ compiler (e.g., g++) supporting C++11 or later
To compile the program, use the provided Makefile by running the following command in the terminal:
makeThis will generate the executable file cms.out.
To execute the program, run:
./cms.outThe program provides an interactive command-line interface where users can execute various commands to manage contacts. Use the help command to display all available commands.
Below is a list of available commands:
| Command | Description |
|---|---|
import <path> |
Import contacts from a CSV file. |
export <path> |
Export contacts to a CSV file. |
add |
Add a new contact by providing the required details interactively. |
update <key> |
Update a contact's details. |
remove <key> |
Delete a contact. |
searchFor <key> |
Search for a contact by their name. |
markFav <key> |
Mark a contact as favorite. |
unmarkFav <key> |
Unmark a contact as favorite. |
printASC |
Print all contacts in ascending order. |
printDES |
Print all contacts in descending order. |
printFav |
Print all favorite contacts. |
help |
Display the list of available commands. |
exit |
Exit the program. |
Each contact consists of the following details:
| Field | Description |
|---|---|
First Name |
Contact's first name. |
Last Name |
Contact's last name. |
Email |
Contact's email address. |
Phone |
Contact's phone number. |
City |
City where the contact resides. |
Country |
Country where the contact resides. |
Favorite |
Whether the contact is a favorite (1 for yes, 0 for no). |
- Handles user interaction and command processing.
- Calls appropriate functions from the
ContactBSTclass.
- Defines the
Contactclass to store individual contact details.
- Implements the
ContactBSTclass, which manages contacts using a binary search tree. - Key functions:
add: Adds a new contact to the BST.remove: Removes a contact from the BST.update: Updates contact details.markFav/unmarkFav: Marks/unmarks a contact as favorite.printASC/printDES: Prints contacts in ascending/descending order.importCSV/exportCSV: Handles CSV file import/export.
- Defines a custom vector implementation
MyVector. - Used to store multiple contacts within a single BST node.
- Key functions:
push_back: Adds an element to the vector.erase: Removes an element from the vector.at: Accesses an element by index.shrink_to_fit: Adjusts capacity to match size.
- Example CSV file to store and retrieve contact data.
- Each line represents a contact in the format:
FirstName,LastName,Email,Phone,City,Country,Favorite
To import contacts from a CSV file:
> import contacts.csvTo add a new contact:
> addFollow the prompts to enter the contact details.
To export all contacts to a CSV file:
> export output.csvTo mark a contact as a favorite:
> markFav John DoeTo display all contacts in ascending order:
> printASC- Ensure that the CSV file paths are correct when importing/exporting contacts.
- Use unique names for contacts to avoid conflicts.
- The program handles invalid inputs gracefully and prompts users to retry.