You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
2.0 KiB

3 years ago
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* PhoneBook.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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;
3 years ago
}
void PhoneBook::add() {
int id = _id % CONTACTS_AMOUNT;
if (_id > CONTACTS_AMOUNT - 1)
3 years ago
{
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;
3 years ago
return ;
}
std::cout << std::endl;
}
_contacts[id].set(id);
_id++;
3 years ago
}
void PhoneBook::search() {
for (int id = 0; id < _id % CONTACTS_AMOUNT; id++)
_contacts[id].summary();
3 years ago
std::string sid;
std::cout << "Which contact do you wanna see [id?]:";
std::cin >> sid;
_contacts[(int)std::strtod(sid.c_str(), 0)].get();
3 years ago
}
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;
}
3 years ago
}