/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* PhoneBook.cpp :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: narnaud +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/06/13 10:14:16 by narnaud #+# #+# */ /* Updated: 2022/06/13 16:00:30 by narnaud ### ########.fr */ /* */ /* ************************************************************************** */ #include "PhoneBook.hpp" PhoneBook::PhoneBook() { _id = 0; } void PhoneBook::add() { int id = _id % CONTACTS_AMOUNT; if (_id > CONTACTS_AMOUNT - 1) { std::cout << "You gonna remove the contact n." << id; std::cout << "\nTo continue, type 'y': "; std::string confirm = 0; std::cin >> confirm; if (confirm != "y") { std::cout << std::endl << "Abort." << std::endl; return ; } std::cout << std::endl; } _contacts[id].set(id); _id++; } void PhoneBook::search() { for (int id = 0; id < _id % CONTACTS_AMOUNT; id++) _contacts[id].summary(); std::string sid; std::cout << "Which contact do you wanna see [id?]:"; std::cin >> sid; _contacts[(int)std::strtod(sid.c_str(), 0)].get(); } void PhoneBook::run() { std::string cmd; while (cmd != "EXIT" && cmd != "3") { std::cout << "=== PHONEBOOK ===" << std::endl; std::cout << "Commands available : 1-ADD, 2-SEARCH, 3-EXIT.\n"; std::cout << "What do you want? "; std::cin >> cmd; if (cmd == "ADD" || cmd == "1") this->add(); else if (cmd == "SEARCH" || cmd == "2") this->search(); else if (cmd != "EXIT" && cmd != "3") std::cout << "Unknown command." << std::endl; } }