diff options
| author | Charles Cabergs <me@cacharle.xyz> | 2020-11-09 11:26:50 +0100 |
|---|---|---|
| committer | Charles Cabergs <me@cacharle.xyz> | 2020-11-09 11:26:50 +0100 |
| commit | b799c007a1b6911fcbe5141429ea541e1277ebdd (patch) | |
| tree | d70ad0826ad2fc2d635adf9afecf89af0838d20b /cpp00 | |
| parent | 1e9d90bdf9ef5fc05093d3449d883597c7f896de (diff) | |
| download | piscine_cpp-b799c007a1b6911fcbe5141429ea541e1277ebdd.tar.gz piscine_cpp-b799c007a1b6911fcbe5141429ea541e1277ebdd.tar.bz2 piscine_cpp-b799c007a1b6911fcbe5141429ea541e1277ebdd.zip | |
Fixing some edge cases in cpp00 and cpp01, Updated formatting
Diffstat (limited to 'cpp00')
| -rw-r--r-- | cpp00/ex00/Makefile | 12 | ||||
| -rw-r--r-- | cpp00/ex00/megaphone.cpp | 12 | ||||
| -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 | ||||
| -rw-r--r-- | cpp00/ex02/.keep | 0 |
7 files changed, 45 insertions, 22 deletions
diff --git a/cpp00/ex00/Makefile b/cpp00/ex00/Makefile index 466a51e..2bfc080 100644 --- a/cpp00/ex00/Makefile +++ b/cpp00/ex00/Makefile @@ -1,3 +1,15 @@ +# ############################################################################ # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: cacharle <me@cacharle.xyz> +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2020/11/09 09:16:44 by cacharle #+# #+# # +# Updated: 2020/11/09 09:16:45 by cacharle ### ########.fr # +# # +# ############################################################################ # + RM = rm -f CC = clang++ diff --git a/cpp00/ex00/megaphone.cpp b/cpp00/ex00/megaphone.cpp index 32b4d14..1956510 100644 --- a/cpp00/ex00/megaphone.cpp +++ b/cpp00/ex00/megaphone.cpp @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* megaphone.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <me@cacharle.xyz> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/11/09 09:15:55 by cacharle #+# #+# */ +/* Updated: 2020/11/09 09:16:00 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + #include <iostream> #include <cctype> 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 diff --git a/cpp00/ex02/.keep b/cpp00/ex02/.keep deleted file mode 100644 index e69de29..0000000 --- a/cpp00/ex02/.keep +++ /dev/null |
