diff --git a/ex01/Contact.cpp b/ex01/Contact.cpp deleted file mode 100644 index 8875dd3..0000000 --- a/ex01/Contact.cpp +++ /dev/null @@ -1,60 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include "Contact.hpp" -#include "utils.hpp" - -Contact::Contact(std::string first_name, std::string last_name, std::string nickname, std::string phone_number) -{ - this->nickname = nickname; - this->last_name = last_name; - this->first_name = first_name; - this->phone_number = phone_number; -} - -Contact::Contact() -{ - this->first_name = ""; - this->last_name = ""; - this->phone_number = ""; - this->phone_number = ""; -} - -Contact::~Contact() -{ -} - -Contact &Contact::operator=(const Contact &contact) -{ - this->first_name = contact.first_name; - this->last_name = contact.last_name; - this->nickname = contact.nickname; - this->phone_number = contact.phone_number; - return (*this); -} - -bool Contact::isValid() const -{ - return (!(this->first_name == "" || this->last_name == "" || this->nickname == "" || this->phone_number == "")); -} - -std::string Contact::to_string() const -{ - std::stringstream ss; - - ss << std::setw(10) << truncated(this->first_name) << "|" - << std::setw(10) << truncated(this->last_name) << "|" - << std::setw(10) << truncated(this->nickname) << "|" - << std::setw(10) << truncated(this->phone_number); - - return(ss.str()); -} - -std::ostream& operator<<(std::ostream& os, const Contact& contact) -{ - os << contact.to_string() << std::endl; - return (os); -} diff --git a/ex01/Contact.hpp b/ex01/Contact.hpp deleted file mode 100644 index 7307234..0000000 --- a/ex01/Contact.hpp +++ /dev/null @@ -1,22 +0,0 @@ -#include -#include - -class Contact { - private: - std::string first_name; - std::string last_name; - std::string nickname; - std::string phone_number; - - public: - Contact(std::string first_name, std::string last_name, std::string nickname, std::string phone_number); - Contact(); - ~Contact(); - - Contact &operator=(const Contact &contact); - - bool isValid() const; - std::string to_string() const; -}; - -std::ostream& operator<<(std::ostream& os, const Contact& fixed); diff --git a/ex01/PhoneBook.cpp b/ex01/PhoneBook.cpp deleted file mode 100644 index 63cc741..0000000 --- a/ex01/PhoneBook.cpp +++ /dev/null @@ -1,36 +0,0 @@ -#include "PhoneBook.hpp" -#include -#include -#include - -PhoneBook::PhoneBook() -{ - this->len = 0; -} - -void PhoneBook::add_contact(Contact new_contact) -{ - size_t i; - - if (this->len < 8) - { - this->contacts[this->len] = new_contact; - this->len++; - } - else { - for (i = this->len; i < 0; i--) { - this->contacts[i] = this->contacts[i - 1]; - } - this->contacts[0] = new_contact; - } -} - -void PhoneBook::display_contacts() -{ - size_t i; - - for (i = 0; i < this->len; i++) - { - std::cout << this->contacts[i]; - } -} diff --git a/ex01/PhoneBook.hpp b/ex01/PhoneBook.hpp deleted file mode 100644 index ec2c834..0000000 --- a/ex01/PhoneBook.hpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "Contact.hpp" -#include - -class PhoneBook { - private: - Contact contacts[8]; - size_t len; - - public: - PhoneBook(); - void add_contact(Contact new_contact); - void display_contacts(); -}; diff --git a/ex01/bin/.nfs000000000c70039200000411 b/ex01/bin/.nfs000000000c70039200000411 new file mode 100755 index 0000000..a068eb4 Binary files /dev/null and b/ex01/bin/.nfs000000000c70039200000411 differ diff --git a/ex01/main.cpp b/ex01/main.cpp deleted file mode 100644 index d800766..0000000 --- a/ex01/main.cpp +++ /dev/null @@ -1,63 +0,0 @@ -#include -#include -#include -#include "PhoneBook.hpp" - -Contact read_contact() -{ - std::string first_name; - std::string last_name; - std::string nickname; - std::string phone_number; - - std::cout << "first_name: "; - std::getline(std::cin, first_name); - std::cout << "last_name: "; - std::getline(std::cin, last_name); - std::cout << "nickname: "; - std::getline(std::cin, nickname); - std::cout << "phone_number: "; - std::getline(std::cin, phone_number); - - return Contact(first_name, last_name, nickname, phone_number); - -} - -int main() -{ - std::string command; - Contact new_contact; - PhoneBook phone_book; - - phone_book = PhoneBook(); - while (true) - { - std::cout << "command: "; - std::getline(std::cin, command); - if (command == "ADD") - { - new_contact = read_contact(); - if (new_contact.isValid()) - phone_book.add_contact(new_contact); - else - { - std::cerr << "Contact Error !" << std::endl; - return (1); - } - } - else if (command == "SEARCH") - { - phone_book.display_contacts(); - } - else if (command == "EXIT") - { - return (0); - } - else - { - std::cerr << "Command not found" << std::endl; - return (2); - } - } - return (0); -} diff --git a/ex01/t b/ex01/t new file mode 100644 index 0000000..0449fa8 --- /dev/null +++ b/ex01/t @@ -0,0 +1,7 @@ +ADD +fffffffffff +fff +f +f +f +SEARCH diff --git a/ex01/utils.cpp b/ex01/utils.cpp deleted file mode 100644 index c714be3..0000000 --- a/ex01/utils.cpp +++ /dev/null @@ -1,11 +0,0 @@ -#include - -std::string truncated(const std::string str) -{ - std::string out; - - out = str.substr(0, 10); - if (str.length() > 10) - out[9] = '.'; - return (out); -} diff --git a/ex01/utils.hpp b/ex01/utils.hpp deleted file mode 100644 index aabb5da..0000000 --- a/ex01/utils.hpp +++ /dev/null @@ -1,3 +0,0 @@ -#include - -std::string truncated(const std::string str);