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/ex00/Makefile | 25 +++++++++++++++++++++++++ cpp00/ex00/megaphone.cpp | 29 +++++++++++++++++++++++++++++ cpp00/ex01/Contact.cpp | 16 ++++++++++++++++ cpp00/ex01/Contact.hpp | 25 +++++++++++++++++++++++++ cpp00/ex01/Makefile | 25 +++++++++++++++++++++++++ cpp00/ex01/PhoneBook.cpp | 25 +++++++++++++++++++++++++ cpp00/ex01/PhoneBook.hpp | 20 ++++++++++++++++++++ cpp00/ex01/main.cpp | 35 +++++++++++++++++++++++++++++++++++ cpp00/ex02/.keep | 0 9 files changed, 200 insertions(+) create mode 100644 cpp00/ex00/Makefile create mode 100644 cpp00/ex00/megaphone.cpp create mode 100644 cpp00/ex01/Contact.cpp create mode 100644 cpp00/ex01/Contact.hpp create mode 100644 cpp00/ex01/Makefile create mode 100644 cpp00/ex01/PhoneBook.cpp create mode 100644 cpp00/ex01/PhoneBook.hpp create mode 100644 cpp00/ex01/main.cpp create mode 100644 cpp00/ex02/.keep (limited to 'cpp00') diff --git a/cpp00/ex00/Makefile b/cpp00/ex00/Makefile new file mode 100644 index 0000000..466a51e --- /dev/null +++ b/cpp00/ex00/Makefile @@ -0,0 +1,25 @@ +RM = rm -f + +CC = clang++ +CCFLAGS = -Wall -Wextra -Werror + +NAME = megaphone +SRC = megaphone.cpp +OBJ = $(SRC:.cpp=.o) + + +all: $(NAME) + +$(NAME): $(OBJ) + $(CC) $(CCFLAGS) -o $@ $^ + +%.o: %.c + $(CC) $(CCFLAGS) -o $@ $< + +clean: + $(RM) $(OBJ) + +fclean: clean + $(RM) $(NAME) + +re: fclean all diff --git a/cpp00/ex00/megaphone.cpp b/cpp00/ex00/megaphone.cpp new file mode 100644 index 0000000..13ee0fc --- /dev/null +++ b/cpp00/ex00/megaphone.cpp @@ -0,0 +1,29 @@ +#include +#include + +// not sure +// char +// ft_toupper(char c) +// { +// if (c >= 'a' && c <= 'z') +// return (c ^ 0b00100000); +// return (c); +// } + +int +main(int argc, char **argv) +{ + if (argc == 1) + { + std::cout << "* LOUD AND UNBEARABLE FEEDBACK NOISE *" << std::endl; + return 0; + } + for (int i = 1; i < argc; i++) + { + for (int j = 0; argv[i][j]; j++) + argv[i][j] = toupper(argv[i][j]); + std::cout << argv[i]; + } + std::cout << std::endl; + return 0; +} diff --git a/cpp00/ex01/Contact.cpp b/cpp00/ex01/Contact.cpp new file mode 100644 index 0000000..6e8764c --- /dev/null +++ b/cpp00/ex01/Contact.cpp @@ -0,0 +1,16 @@ +#include +#include "Contact.hpp" + +Contact::Contact(std::string name) +{ + this->name = name; +} + +std::string +Contact::phone_str() +{ + std::string s; + for (int i = 0; i < 10; i++) + s.push_back(phone[i] - '0'); + return s; +} diff --git a/cpp00/ex01/Contact.hpp b/cpp00/ex01/Contact.hpp new file mode 100644 index 0000000..3d04889 --- /dev/null +++ b/cpp00/ex01/Contact.hpp @@ -0,0 +1,25 @@ +#ifndef CONTACT_HPP +# define CONTACT_HPP + +# include + +class Contact +{ +public: + Contact(std::string name); + // std::string phone_str(); + + std::string first_name; + std::string last_name; + std::string nickname; + std::string login; + std::string postal_address; + std::string email; + std::string phone; + std::string birthday; + std::string fav_meal; + std::string underware_color; + std::string darkest_secret; +}; + +#endif // CONTACT_HPP diff --git a/cpp00/ex01/Makefile b/cpp00/ex01/Makefile new file mode 100644 index 0000000..a69e4f5 --- /dev/null +++ b/cpp00/ex01/Makefile @@ -0,0 +1,25 @@ +RM = rm -f + +CC = clang++ +CCFLAGS = -Wall -Wextra -Werror + +NAME = crapyphonebook +SRC = main.cpp PhoneBook.cpp Contact.cpp +OBJ = $(SRC:.cpp=.o) + + +all: $(NAME) + +$(NAME): $(OBJ) + $(CC) $(CCFLAGS) -o $@ $^ + +%.o: %.c + $(CC) $(CCFLAGS) -o $@ $< + +clean: + $(RM) $(OBJ) + +fclean: clean + $(RM) $(NAME) + +re: fclean all 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; +} diff --git a/cpp00/ex01/PhoneBook.hpp b/cpp00/ex01/PhoneBook.hpp new file mode 100644 index 0000000..c4f8a23 --- /dev/null +++ b/cpp00/ex01/PhoneBook.hpp @@ -0,0 +1,20 @@ +#ifndef PHONE_BOOK_HPP +# define PHONE_BOOK_HPP + +# define CONTACTS_SIZE 8 + +# include +# include "Contact.hpp" + +class PhoneBook +{ +public: + PhoneBook(); + bool add(Contact contact); + Contact* search(std::string needle); +private: + Contact contacts[CONTACTS_SIZE]; + int contacts_len; +}; + +#endif // PHONE_BOOK_HPP diff --git a/cpp00/ex01/main.cpp b/cpp00/ex01/main.cpp new file mode 100644 index 0000000..051f0e8 --- /dev/null +++ b/cpp00/ex01/main.cpp @@ -0,0 +1,35 @@ +#include +#include "PhoneBook.hpp" +#include "Contact.hpp" + +int +main() +{ + std::string user_input; + size_t found_index; + PhoneBook phone_book = PhoneBook(); + + while (true) + { + std::cin >> user_input; + if (user_input == "EXIT") + break; + else if ((found_index = user_input.find("ADD")) == 0) + { + Contact tmp = Contact(user_input.substr(found_index)); + phone_book.add(tmp); + } + else if ((found_index = user_input.find("SEARCH")) == 0) + { + std::string searched = user_input.substr(found_index); + Contact *result = phone_book.search(searched); + if (result == NULL) + std::cout << "Notfound: " << searched << std::endl; + else + std::cout << "Found: " << result->name + << " phone: " << result->phone_str() << std::endl; + + } + } + return 0; +} diff --git a/cpp00/ex02/.keep b/cpp00/ex02/.keep new file mode 100644 index 0000000..e69de29 -- cgit