aboutsummaryrefslogtreecommitdiff
path: root/cpp00/ex01/PhoneBook.cpp
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2020-04-13 09:18:30 +0200
committerCharles <sircharlesaze@gmail.com>2020-04-13 09:18:30 +0200
commit629d52b1262879a346e9ca17567a8f483c60ba0a (patch)
treeb6d32f764980b08cea6327e9b8a472d88331aae9 /cpp00/ex01/PhoneBook.cpp
parent8fc4395b9a61416e9bfee500e064dce7be9c8d7c (diff)
downloadpiscine_cpp-629d52b1262879a346e9ca17567a8f483c60ba0a.tar.gz
piscine_cpp-629d52b1262879a346e9ca17567a8f483c60ba0a.tar.bz2
piscine_cpp-629d52b1262879a346e9ca17567a8f483c60ba0a.zip
Fixed cpp00/ex01
Diffstat (limited to 'cpp00/ex01/PhoneBook.cpp')
-rw-r--r--cpp00/ex01/PhoneBook.cpp49
1 files changed, 34 insertions, 15 deletions
diff --git a/cpp00/ex01/PhoneBook.cpp b/cpp00/ex01/PhoneBook.cpp
index 44c7ea9..a47307f 100644
--- a/cpp00/ex01/PhoneBook.cpp
+++ b/cpp00/ex01/PhoneBook.cpp
@@ -1,25 +1,44 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* PhoneBook.cpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/13 07:23:13 by charles #+# #+# */
+/* Updated: 2020/04/13 08:43:05 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
#include "PhoneBook.hpp"
-PhoneBook::PhoneBook()
+PhoneBook::PhoneBook(): m_size(0)
+{
+}
+
+void PhoneBook::add(Contact contact)
+{
+ m_contacts[m_size] = contact;
+ m_size++;
+}
+
+Contact const &PhoneBook::get(int index) const
{
- contacts_len = 0;
+ return m_contacts[index];
}
-bool
-PhoneBook::add(Contact contact)
+size_t PhoneBook::getSize() const
{
- if (contacts_len >= CONTACTS_SIZE)
- return false;
- contacts[contacts_len] = contact;
- contacts_len++;
- return true;
+ return m_size;
}
-Contact*
-PhoneBook::search(std::string needle)
+std::ostream &operator<<(std::ostream &out, PhoneBook const &p)
{
- for (int i = 0; i < contacts_len; i++)
- if (needle == contacts[i].name)
- return contacts + i;
- return NULL;
+ for (size_t i = 0; i < p.getSize(); i++)
+ {
+ out << i << "|";
+ p.get(i).preview();
+ std::cout << std::endl;
+ }
+ return out;
}