/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* 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() { this->id = 0; } void PhoneBook::add() { int id = this->id % CONTACTS_AMOUNT; if (this->id > 7) { 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 << "\nAbort.\n"; return ; } std::cout << std::endl; } this->contacts[id].set(id); this->id++; } void PhoneBook::search() { int id = 0; Contact ctct; ctct = this->contacts[0]; while (id++ < this->id % CONTACTS_AMOUNT) { ctct.summary(); ctct = this->contacts[id]; } std::string sid; std::cout << "Which contact do you wanna see [id?]:"; std::cin >> sid; id = std::stoi(sid); ctct = this->contacts[id]; ctct.get(); } int PhoneBook::run() { std::cout << "PhoneBook.\n" << "Commands available : ADD, SEARCH, EXIT.\n"; std::cout << "What do you want?\n"; std::cin >> this->cmd; if (cmd == "EXIT") return (EXIT_FAILURE); if (cmd == "SEARCH") this->search(); else if (cmd == "ADD") this->add(); else std::cout << "Unknown command.\n"; return (EXIT_SUCCESS); }