2023-05-17 12:41:46 -04:00
|
|
|
#include <iostream>
|
|
|
|
#include <bits/stdc++.h>
|
|
|
|
#include <string>
|
|
|
|
#include "PhoneBook.hpp"
|
|
|
|
|
|
|
|
Contact read_contact()
|
|
|
|
{
|
|
|
|
std::string first_name;
|
|
|
|
std::string last_name;
|
|
|
|
std::string nickname;
|
|
|
|
std::string phone_number;
|
|
|
|
|
|
|
|
std::cout << "first_name: ";
|
|
|
|
std::getline(std::cin, first_name);
|
|
|
|
std::cout << "last_name: ";
|
|
|
|
std::getline(std::cin, last_name);
|
|
|
|
std::cout << "nickname: ";
|
|
|
|
std::getline(std::cin, nickname);
|
|
|
|
std::cout << "phone_number: ";
|
|
|
|
std::getline(std::cin, phone_number);
|
|
|
|
|
|
|
|
return Contact(first_name, last_name, nickname, phone_number);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
std::string command;
|
|
|
|
Contact new_contact;
|
|
|
|
PhoneBook phone_book;
|
|
|
|
|
|
|
|
phone_book = PhoneBook();
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
std::cout << "command: ";
|
|
|
|
std::getline(std::cin, command);
|
|
|
|
if (command == "ADD")
|
|
|
|
{
|
|
|
|
new_contact = read_contact();
|
|
|
|
if (new_contact.isValid())
|
|
|
|
phone_book.add_contact(new_contact);
|
|
|
|
else
|
2023-05-19 08:59:37 -04:00
|
|
|
{
|
2023-05-17 12:41:46 -04:00
|
|
|
std::cerr << "Contact Error !" << std::endl;
|
2023-05-19 08:59:37 -04:00
|
|
|
return (1);
|
|
|
|
}
|
2023-05-17 12:41:46 -04:00
|
|
|
}
|
|
|
|
else if (command == "SEARCH")
|
|
|
|
{
|
|
|
|
phone_book.display_contacts();
|
|
|
|
}
|
|
|
|
else if (command == "EXIT")
|
|
|
|
{
|
|
|
|
return (0);
|
|
|
|
}
|
2023-05-19 08:59:37 -04:00
|
|
|
else
|
|
|
|
{
|
|
|
|
std::cerr << "Command not found" << std::endl;
|
|
|
|
return (2);
|
|
|
|
}
|
2023-05-17 12:41:46 -04:00
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|