From 064ec4a751c08e5172d71696d6f0b60fab6aa283 Mon Sep 17 00:00:00 2001 From: kinou-p Date: Thu, 21 Apr 2022 19:02:55 +0200 Subject: [PATCH] cpp0 ex0 et ex1 --- cpp00/ex00/Makefile | 34 +++++++++++++++ cpp00/ex00/megaphone | Bin 0 -> 17368 bytes cpp00/ex00/megaphone.cpp | 36 ++++++++++++++++ cpp00/ex01/Contact.cpp | 57 ++++++++++++++++++++++++ cpp00/ex01/Contact.hpp | 43 ++++++++++++++++++ cpp00/ex01/Makefile | 36 ++++++++++++++++ cpp00/ex01/PhoneBook.cpp | 91 +++++++++++++++++++++++++++++++++++++++ cpp00/ex01/PhoneBook.hpp | 33 ++++++++++++++ cpp00/ex01/main.cpp | 79 +++++++++++++++++++++++++++++++++ cpp00/ex02/Makefile | 34 +++++++++++++++ 10 files changed, 443 insertions(+) create mode 100644 cpp00/ex00/Makefile create mode 100644 cpp00/ex00/megaphone 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/Makefile diff --git a/cpp00/ex00/Makefile b/cpp00/ex00/Makefile new file mode 100644 index 0000000..eca33fe --- /dev/null +++ b/cpp00/ex00/Makefile @@ -0,0 +1,34 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: apommier +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2022/04/15 01:47:51 by apommier #+# #+# # +# Updated: 2022/04/15 05:00:14 by apommier ### ########.fr # +# # +# **************************************************************************** # + +NAME = megaphone +SRCS = megaphone.cpp + +OBJS = ${SRCS:.cpp=.o} +CC = c++ +CFLAGS = -Wall -Wextra -Werror +RM = rm -rf + +${NAME}: ${OBJS} + ${CC} ${LIB} ${OBJS} -o ${NAME} + +all: ${NAME} + +clean: + @${RM} ${OBJS} + +fclean: clean + @${RM} ${NAME} + +re: fclean all + +.PHONY: all clean fclean re \ No newline at end of file diff --git a/cpp00/ex00/megaphone b/cpp00/ex00/megaphone new file mode 100644 index 0000000000000000000000000000000000000000..ba0d0f21e3dd229155320f05336ec3d35a080501 GIT binary patch literal 17368 zcmeHPeQ;FO6~CJ$5EM4cR}EO$G&7vHFh^si6IEu+tB%<1}^37+SOtOB*Y&{hj;n*}Q$( zZPDqB)0sWY%enV=KJIKGVRRHsgdNCV+ zmx#q;I_lFTX36~)gVdte%JO-I!rkCxS4D*a{F4?em~#(_lU*_DR}C;1>ORP>oQzc6 z$=4{S%vqjmPa|WHCjaL6Yoq{TZnvY@^i@l-=v$x952(0|srzR;g2`@B*$pZ?=0e#q z=Xg^0>8e-$oLqy9NRxksaN2b$J11{a`pl^fqV^MJ>|*)taUYVO_AJiu45Rp9(G1aL& z3m55F_y3426Gn7A`bzJDM`tx!wW)u}>)ffZxB?Cf;m;P)f1(I}rU7+-){-Ms7u25r_4zB>Z@tY*9ybf*_((P zDKnHb4MP|$9UF~EG#T9)OPSGR$HvBgtJFvci(v+ReIXJkrw=ZZ~Ud!`-2z zVJ1T{Gu09f2DboP-4#m3!bT!xCZnO=mJXw%#t62rMT56(YB%d+iIf42XkAM@W;WFZ zcS$_alM1#qZ)s1o8$kf=W>2c+;{1m@;C+qJc2l@e1C3S#=yN!cHU%OQ=3s>TLq^Dq z_Qy8qCiyUwoY!4m?+(wg^!nAh z%J{?cEPSs6->dX1{Fa>cx&G1(7EaG5Ka+$Ux8bTQQt>q#ZePzvZ8*0<24glHHk>rpKr}c~J85=G?XO-Zv4W~9r zREj_;0;LF)B2bDzDFPpV1m3G${4agrRE563{PmSW=not=%d*GyfuB_zk)6w~`6A%) z?5FPpt6U;TzndiEC;ybqW`|{+zTk|Xd^K06FB0P?M{;%g0x^E_C%HO(aTq^&kn8Zi zUV3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m+5Zsaw5Mi!-p?>^qu_$5k5puP-v7pc(Jiw*?|Yc@z8xx(lsm49FQG(x zVz%e~5py0t?mz1>zYq4b$L2ckqnP_uOB`eFzkZ=~I@^B(61)AdW~nmQNoXTy`zIiyy(EW;_a~f(?u-}P zGd}~{N}E0Jr}tI^1hJk~o2)Z_9s-)X+&=HS`TrH*z|iwY#CF`T9|EIW%-O5o?FQAx zf}bC +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/04/15 01:47:56 by apommier #+# #+# */ +/* Updated: 2022/04/20 05:18:29 by apommier ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include + +int main(int ac, char **av) +{ + int i = 0; + int j = 0; + + if (ac != 1) + { + while (av[++i]) + { + j = -1; + while (av[i][++j]) + av[i][j] = toupper(av[i][j]); + } + i = 0; + while (av[++i]) + std::cout << av[i] << std::endl; + } + else + std::cout << "* LOUD AND UNBEARABLE FEEDBACK NOISE *" << std::endl; + return (0); +} \ No newline at end of file diff --git a/cpp00/ex01/Contact.cpp b/cpp00/ex01/Contact.cpp new file mode 100644 index 0000000..f7f7113 --- /dev/null +++ b/cpp00/ex01/Contact.cpp @@ -0,0 +1,57 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Contact.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/04/15 10:37:12 by apommier #+# #+# */ +/* Updated: 2022/04/21 18:32:43 by apommier ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "Contact.hpp" + +Contact::Contact(void) { + return ; +} + +Contact::~Contact(void) { + return ; +} + +void Contact::FillContact(std::string *info) { + this->_first_name = info[0]; + this->_last_name = info[1]; + this->_nickname = info[2]; + this->_phone_number = info[3]; + this->_darkest_secret = info[4]; +} + +std::string Contact::GetInfo(int index) +{ + std::string str; + + str = this->GetRealInfo(index); + if (str.size() > 10) + { + str.resize(10); + str[9] = '.'; + } + return (str); +} + +std::string Contact::GetRealInfo(int index) +{ + if (index == 0) + return (this->_first_name); + if (index == 1) + return (this->_last_name); + if (index == 2) + return (this->_nickname); + if (index == 3) + return (this->_phone_number); + if (index == 4) + return (this->_darkest_secret); + return (0); +} \ No newline at end of file diff --git a/cpp00/ex01/Contact.hpp b/cpp00/ex01/Contact.hpp new file mode 100644 index 0000000..419df3e --- /dev/null +++ b/cpp00/ex01/Contact.hpp @@ -0,0 +1,43 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Contact.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/04/15 10:37:15 by apommier #+# #+# */ +/* Updated: 2022/04/21 18:00:26 by apommier ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef CONTACT_HPP +# define CONTACT_HPP + +# include +# include +# include +# include +# include +# include + +class Contact { + + public: + + Contact(void); + ~Contact(void); + void FillContact(std::string *info); + std::string GetInfo(int index); + std::string GetRealInfo(int index); + + private: + + + std::string _first_name; + std::string _last_name; + std::string _nickname; + std::string _phone_number; + std::string _darkest_secret; +}; + +#endif \ No newline at end of file diff --git a/cpp00/ex01/Makefile b/cpp00/ex01/Makefile new file mode 100644 index 0000000..f454103 --- /dev/null +++ b/cpp00/ex01/Makefile @@ -0,0 +1,36 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: apommier +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2022/04/15 01:47:51 by apommier #+# #+# # +# Updated: 2022/04/20 05:40:02 by apommier ### ########.fr # +# # +# **************************************************************************** # + +NAME = a.out +SRCS = main.cpp\ + Contact.cpp\ + PhoneBook.cpp + +OBJS = ${SRCS:.cpp=.o} +CC = c++ +CFLAGS = -Wall -Wextra -Werror -g +RM = rm -rf + +${NAME}: ${OBJS} + ${CC} ${LIB} ${OBJS} -o ${NAME} + +all: ${NAME} + +clean: + @${RM} ${OBJS} + +fclean: clean + @${RM} ${NAME} + +re: fclean all + +.PHONY: all clean fclean re \ No newline at end of file diff --git a/cpp00/ex01/PhoneBook.cpp b/cpp00/ex01/PhoneBook.cpp new file mode 100644 index 0000000..b714057 --- /dev/null +++ b/cpp00/ex01/PhoneBook.cpp @@ -0,0 +1,91 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* PhoneBook.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/04/15 10:37:20 by apommier #+# #+# */ +/* Updated: 2022/04/21 18:32:32 by apommier ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "PhoneBook.hpp" + +PhoneBook::PhoneBook(void) +{ + int index = 0; + + this->_NbrContact = 0; + while (index < 8) + _Contact[index++] = 0; + return ; +} + +PhoneBook::~PhoneBook(void) +{ + return ; +} + +void PhoneBook::StoreContact(Contact *NewContact) +{ + _Contact[this->_NbrContact] = NewContact; + if (this->_NbrContact == 8) + this->_NbrContact = 0; + else + this->_NbrContact++; +} + +void PhoneBook::PrintContact(int index) +{ + if (!this->_Contact[index]) + { + std::cout << "There is no contact at this index" << std::endl; + return ; + } + std::cout << std::setw(10) << "First name: " << this->_Contact[index]->GetRealInfo(0) << std::endl; + std::cout << std::setw(10) << "Last name: " << this->_Contact[index]->GetRealInfo(1) << std::endl; + std::cout << std::setw(10) << "Nickname: " << this->_Contact[index]->GetRealInfo(2) << std::endl; + std::cout << std::setw(10) << "Phone number: " << this->_Contact[index]->GetRealInfo(3) << std::endl; + std::cout << std::setw(10) << "Darkest secret: " << this->_Contact[index]->GetRealInfo(4) << std::endl; +} + +void PhoneBook::PrintIndex() +{ + int index = 0; + std::string nbr; + + + while (index < 8 && this->_Contact[index]) + { + std::cout << std::setw(10) << index + 1 << "|"; + std::cout << std::setw(10) << this->_Contact[index]->GetInfo(0) << "|"; + std::cout << std::setw(10) << this->_Contact[index]->GetInfo(1) << "|"; + std::cout << std::setw(10) << this->_Contact[index]->GetInfo(2) << std::endl; + index++; + } + if (!index) + std::cout << "There is no contact\n"; + else + { + while (1) + { + std::cout << "Enter index of contact: "; + std::cin >> nbr; + if (nbr.size() != 1 || !isdigit(nbr[0])) + std::cout << "Bad entry" << std::endl; + else + { + index = nbr[0] - 48; + if (!index || index > 8) + std::cout << "Bad entry" << std::endl; + else + { + this->PrintContact(index - 1); + break; + } + } + } + } +} + diff --git a/cpp00/ex01/PhoneBook.hpp b/cpp00/ex01/PhoneBook.hpp new file mode 100644 index 0000000..8b7379d --- /dev/null +++ b/cpp00/ex01/PhoneBook.hpp @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* PhoneBook.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/04/15 10:37:24 by apommier #+# #+# */ +/* Updated: 2022/04/21 17:57:29 by apommier ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef PHONEBOOK_HPP +# define PHONEBOOK_HPP + +# include "Contact.hpp" + +class PhoneBook { + + public: + + PhoneBook(void); + ~PhoneBook(void); + void StoreContact(Contact *NewContact); + void PrintContact(int index); + void PrintIndex(); + private: + + int _NbrContact; + class Contact *_Contact[8]; +}; + +#endif \ No newline at end of file diff --git a/cpp00/ex01/main.cpp b/cpp00/ex01/main.cpp new file mode 100644 index 0000000..d4fe0b6 --- /dev/null +++ b/cpp00/ex01/main.cpp @@ -0,0 +1,79 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/04/17 15:55:40 by apommier #+# #+# */ +/* Updated: 2022/04/21 18:58:19 by apommier ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "Contact.hpp" +#include "PhoneBook.hpp" + +void PrintMessage(int index) +{ + if (index == 0) + std::cout << "Enter your fisrt name: "; + if (index == 1) + std::cout << "Enter your last name: "; + if (index == 2) + std::cout << "Enter your nickname: "; + if (index == 3) + std::cout << "Enter your phone number: "; + if (index == 4) + std::cout << "Enter your darkest secret: "; +} + +void search_contact(PhoneBook *Book, Contact *Contact) +{ + +} + +void add_contact(PhoneBook *Book, Contact *Contact) +{ + int index = 0; + std::string line; + std::string info[5]; + + while (index < 5) + { + PrintMessage(index); + std::getline(std::cin, line); + info[index] = line; + if (!line.empty()) + index++; + } + Contact->FillContact(info); + Book->StoreContact(Contact); +} + +int main(int ac, char **av) +{ + PhoneBook book; + Contact contact; + std::string line; + int NbrContact = 0; + + if (ac != 1) + { + std::cout << "too much arguments\n"; + return (0); + } + //line = "nothing"; + std::cout << "Enter a command : ADD | SEARCH | EXIT" << std::endl; + while (line != "EXIT") + { + std::getline(std::cin, line); + if (line == "ADD") + add_contact(&book, &contact); + else if (line == "SEARCH") + book.PrintIndex(); + else + std::cout << "Invalid command" << std::endl; + } + //std::cout << "exit\n"; + return (0); +} \ No newline at end of file diff --git a/cpp00/ex02/Makefile b/cpp00/ex02/Makefile new file mode 100644 index 0000000..eca33fe --- /dev/null +++ b/cpp00/ex02/Makefile @@ -0,0 +1,34 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: apommier +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2022/04/15 01:47:51 by apommier #+# #+# # +# Updated: 2022/04/15 05:00:14 by apommier ### ########.fr # +# # +# **************************************************************************** # + +NAME = megaphone +SRCS = megaphone.cpp + +OBJS = ${SRCS:.cpp=.o} +CC = c++ +CFLAGS = -Wall -Wextra -Werror +RM = rm -rf + +${NAME}: ${OBJS} + ${CC} ${LIB} ${OBJS} -o ${NAME} + +all: ${NAME} + +clean: + @${RM} ${OBJS} + +fclean: clean + @${RM} ${NAME} + +re: fclean all + +.PHONY: all clean fclean re \ No newline at end of file