From 7080f89bb2800917bfd9a560046a1ab7505f819e Mon Sep 17 00:00:00 2001 From: Charles Date: Tue, 3 Dec 2019 14:57:21 +0100 Subject: Initial commit with cpp00 start --- cpp00/ex01/PhoneBook.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 cpp00/ex01/PhoneBook.cpp (limited to 'cpp00/ex01/PhoneBook.cpp') diff --git a/cpp00/ex01/PhoneBook.cpp b/cpp00/ex01/PhoneBook.cpp new file mode 100644 index 0000000..44c7ea9 --- /dev/null +++ b/cpp00/ex01/PhoneBook.cpp @@ -0,0 +1,25 @@ +#include "PhoneBook.hpp" + +PhoneBook::PhoneBook() +{ + contacts_len = 0; +} + +bool +PhoneBook::add(Contact contact) +{ + if (contacts_len >= CONTACTS_SIZE) + return false; + contacts[contacts_len] = contact; + contacts_len++; + return true; +} + +Contact* +PhoneBook::search(std::string needle) +{ + for (int i = 0; i < contacts_len; i++) + if (needle == contacts[i].name) + return contacts + i; + return NULL; +} -- cgit