aboutsummaryrefslogtreecommitdiff
path: root/cpp00
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2019-12-03 14:57:21 +0100
committerCharles <sircharlesaze@gmail.com>2019-12-03 14:57:21 +0100
commit7080f89bb2800917bfd9a560046a1ab7505f819e (patch)
treea324f9789f5cf9c6cc273989aa46c9c515ccb67e /cpp00
downloadpiscine_cpp-7080f89bb2800917bfd9a560046a1ab7505f819e.tar.gz
piscine_cpp-7080f89bb2800917bfd9a560046a1ab7505f819e.tar.bz2
piscine_cpp-7080f89bb2800917bfd9a560046a1ab7505f819e.zip
Initial commit with cpp00 start
Diffstat (limited to 'cpp00')
-rw-r--r--cpp00/ex00/Makefile25
-rw-r--r--cpp00/ex00/megaphone.cpp29
-rw-r--r--cpp00/ex01/Contact.cpp16
-rw-r--r--cpp00/ex01/Contact.hpp25
-rw-r--r--cpp00/ex01/Makefile25
-rw-r--r--cpp00/ex01/PhoneBook.cpp25
-rw-r--r--cpp00/ex01/PhoneBook.hpp20
-rw-r--r--cpp00/ex01/main.cpp35
-rw-r--r--cpp00/ex02/.keep0
9 files changed, 200 insertions, 0 deletions
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 <iostream>
+#include <cctype>
+
+// 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 <string>
+#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 <string>
+
+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 <string>
+# 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 <iostream>
+#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
--- /dev/null
+++ b/cpp00/ex02/.keep