42_CPP00/ex01/main.cpp
2023-05-19 14:59:37 +02:00

64 lines
1.2 KiB
C++

#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
{
std::cerr << "Contact Error !" << std::endl;
return (1);
}
}
else if (command == "SEARCH")
{
phone_book.display_contacts();
}
else if (command == "EXIT")
{
return (0);
}
else
{
std::cerr << "Command not found" << std::endl;
return (2);
}
}
return (0);
}