diff options
Diffstat (limited to 'cpp00/ex01')
| -rw-r--r-- | cpp00/ex01/Contact.hpp | 10 | ||||
| -rw-r--r-- | cpp00/ex01/PhoneBook.cpp | 12 | ||||
| -rw-r--r-- | cpp00/ex01/PhoneBook.hpp | 14 | ||||
| -rw-r--r-- | cpp00/ex01/main.cpp | 7 |
4 files changed, 21 insertions, 22 deletions
diff --git a/cpp00/ex01/Contact.hpp b/cpp00/ex01/Contact.hpp index d9fbee6..4717e55 100644 --- a/cpp00/ex01/Contact.hpp +++ b/cpp00/ex01/Contact.hpp @@ -6,7 +6,7 @@ /* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/13 07:23:11 by charles #+# #+# */ -/* Updated: 2020/04/13 08:57:01 by charles ### ########.fr */ +/* Updated: 2020/11/09 09:30:12 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,12 +22,12 @@ class Contact { public: static Contact prompt(); - void preview() const; - void put() const; + void preview() const; + void put() const; private: - static void promptString(std::string promptString, std::string &s); - static void promptInt(std::string promptString, int &i); + static void promptString(std::string promptString, std::string& s); + static void promptInt(std::string promptString, int& i); static std::string trimedName(std::string name); struct Address diff --git a/cpp00/ex01/PhoneBook.cpp b/cpp00/ex01/PhoneBook.cpp index a47307f..a28ce36 100644 --- a/cpp00/ex01/PhoneBook.cpp +++ b/cpp00/ex01/PhoneBook.cpp @@ -6,23 +6,23 @@ /* 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 */ +/* Updated: 2020/11/09 09:29:37 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ #include "PhoneBook.hpp" -PhoneBook::PhoneBook(): m_size(0) -{ -} +PhoneBook::PhoneBook() : m_size(0) {} void PhoneBook::add(Contact contact) { + if (m_size >= CONTACTS_SIZE) + return; m_contacts[m_size] = contact; m_size++; } -Contact const &PhoneBook::get(int index) const +Contact const& PhoneBook::get(size_t index) const { return m_contacts[index]; } @@ -32,7 +32,7 @@ size_t PhoneBook::getSize() const return m_size; } -std::ostream &operator<<(std::ostream &out, PhoneBook const &p) +std::ostream& operator<<(std::ostream& out, PhoneBook const& p) { for (size_t i = 0; i < p.getSize(); i++) { diff --git a/cpp00/ex01/PhoneBook.hpp b/cpp00/ex01/PhoneBook.hpp index 8510710..abf83be 100644 --- a/cpp00/ex01/PhoneBook.hpp +++ b/cpp00/ex01/PhoneBook.hpp @@ -6,7 +6,7 @@ /* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/13 09:06:23 by charles #+# #+# */ -/* Updated: 2020/04/13 09:06:39 by charles ### ########.fr */ +/* Updated: 2020/11/09 09:28:38 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,16 +22,16 @@ class PhoneBook { public: PhoneBook(); - void add(Contact contact); - Contact* search(std::string needle); - size_t getSize() const; - Contact const &get(int index) const; + void add(Contact contact); + Contact* search(std::string needle); + size_t getSize() const; + Contact const& get(size_t index) const; private: Contact m_contacts[CONTACTS_SIZE]; - int m_size; + size_t m_size; }; -std::ostream &operator<<(std::ostream &out, PhoneBook const &p); +std::ostream& operator<<(std::ostream& out, PhoneBook const& p); #endif diff --git a/cpp00/ex01/main.cpp b/cpp00/ex01/main.cpp index 5734d38..8b04fe2 100644 --- a/cpp00/ex01/main.cpp +++ b/cpp00/ex01/main.cpp @@ -6,7 +6,7 @@ /* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/13 07:23:15 by charles #+# #+# */ -/* Updated: 2020/04/13 09:18:04 by charles ### ########.fr */ +/* Updated: 2020/11/09 09:22:22 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,8 +18,7 @@ int main() { std::string input; - PhoneBook phoneBook; - int tmp; + PhoneBook phoneBook; while (true) { @@ -40,7 +39,7 @@ int main() else if (input == "SEARCH") { std::cout << phoneBook << std::flush; - tmp = getInt(); + int tmp = getInt(); if (tmp < 0 || size_t(tmp) >= phoneBook.getSize()) std::cout << "Error: Not valid index: " << tmp << std::endl; else |
