diff --git a/CPP00/ex00/Makefile b/CPP00/ex00/Makefile new file mode 100644 index 0000000..c1de22d --- /dev/null +++ b/CPP00/ex00/Makefile @@ -0,0 +1,16 @@ +NAME = megaphone +SRC = main.cpp + +CC = c++ +CFLAGS = -std=c++98 -Wall -Werror -Wextra +RM = rm -rf + +$(NAME): $(SRC) + $(CC) $(CFLAGS) $(SRC) -o $(NAME) + +all: $(NAME) + +clean: + $(RM) $(NAME) + +.PHONY: all re diff --git a/CPP00/ex00/main.cpp b/CPP00/ex00/main.cpp new file mode 100644 index 0000000..54d37c2 --- /dev/null +++ b/CPP00/ex00/main.cpp @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: narnaud +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/06/13 08:20:39 by narnaud #+# #+# */ +/* Updated: 2022/06/13 08:44:34 by narnaud ### ########.fr */ +/* */ +/* ************************************************************************** */ + +# include +# include + +int main(int argc, char **argv) +{ + if (argc < 2) + std::cout << "* LOUD AND UNBEARABLE FEEDBACK NOISE *"; + else + { + int i = 1; + char *ret; + while (i < argc) + { + ret = argv[i]; + while (*ret) + std::cout << (char)toupper(*(ret++)); + i++; + } + } + std::cout << std::endl; + return (EXIT_SUCCESS); +} diff --git a/CPP00/ex00/megaphone b/CPP00/ex00/megaphone new file mode 100755 index 0000000..2f79b4d Binary files /dev/null and b/CPP00/ex00/megaphone differ diff --git a/CPP00/ex01/Contact.cpp b/CPP00/ex01/Contact.cpp new file mode 100644 index 0000000..5f82dd0 --- /dev/null +++ b/CPP00/ex01/Contact.cpp @@ -0,0 +1,55 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Contact.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: narnaud +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/06/13 13:29:20 by narnaud #+# #+# */ +/* Updated: 2022/06/13 16:48:13 by narnaud ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "Contact.hpp" +Contact::Contact(){} + +void Contact::set(int id) +{ + this->id = id; + std::cout << "Enter new contact first name:\n"; + std::cin >> this->datas[FIRST]; + std::cout << "Enter new contact last name:\n"; + std::cin >> this->datas[LAST]; + std::cout << "Enter new contact nickname:\n"; + std::cin >> this->datas[NICK]; + std::cout << "Enter new contact number:\n"; + std::cin >> this->datas[NUMBER]; + std::cout << "Enter new contact secret:\n"; + std::cin >> this->datas[SECRET]; + std::cout << std::endl; +} + +void Contact::summary() +{ + std::cout << "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n"; + std::cout << "|"; + std::cout << std::setw(2) << this->id; + std::cout << "|"; + for (int i = 0; i <= SECRET; i++) + { + if (this->datas[i].length() < 10) + std::cout << std::setw(10) << this->datas[i] << "|"; + else + std::cout << this->datas[i].substr(0, 9) << "." << "|"; + } + std::cout << "\nvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv\n"; +} + +void Contact::get() +{ + std::cout <<"First name : " << this->datas[FIRST] << std::endl; + std::cout <<"Last name : " << this->datas[LAST] << std::endl; + std::cout <<"Nick name : " << this->datas[NICK] << std::endl; + std::cout <<"Phone nb : " << this->datas[NUMBER] << std::endl; + std::cout <<"Dark secret : " << this->datas[SECRET] << std::endl; +} diff --git a/CPP00/ex01/Contact.hpp b/CPP00/ex01/Contact.hpp new file mode 100644 index 0000000..5d7665c --- /dev/null +++ b/CPP00/ex01/Contact.hpp @@ -0,0 +1,39 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Contact.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: narnaud +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/06/13 13:02:55 by narnaud #+# #+# */ +/* Updated: 2022/06/13 16:35:43 by narnaud ### ########.fr */ +/* */ +/* ************************************************************************** */ +#ifndef CONTACT_HPP +# define CONTACT_HPP + +# include +# include +# include + +enum e_datas +{ + FIRST, + LAST, + NICK, + NUMBER, + SECRET, +}; + +class Contact +{ + public: + Contact(); + void set(int id); + void summary(); + void get(); + private: + int id; + std::string datas[5]; +}; +#endif diff --git a/CPP00/ex01/PhoneBook.cpp b/CPP00/ex01/PhoneBook.cpp new file mode 100644 index 0000000..f2e798d --- /dev/null +++ b/CPP00/ex01/PhoneBook.cpp @@ -0,0 +1,72 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* PhoneBook.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: narnaud +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/06/13 10:14:16 by narnaud #+# #+# */ +/* Updated: 2022/06/13 16:00:30 by narnaud ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "PhoneBook.hpp" + +PhoneBook::PhoneBook() +{ + this->id = 0; +} + +void PhoneBook::add() +{ + int id = this->id % CONTACTS_AMOUNT; + if (this->id > 7) + { + std::cout << "You gonna remove the contact n." << id; + std::cout << "\nTo continue, type 'y': "; + std::string confirm = 0; + std::cin >> confirm; + if (confirm != "y") + { + std::cout << "\nAbort.\n"; + return ; + } + std::cout << std::endl; + } + this->contacts[id].set(id); + this->id++; +} +void PhoneBook::search() +{ + int id = 0; + Contact ctct; + + ctct = this->contacts[0]; + while (id++ < this->id % CONTACTS_AMOUNT) + { + ctct.summary(); + ctct = this->contacts[id]; + } + std::string sid; + std::cout << "Which contact do you wanna see [id?]:"; + std::cin >> sid; + id = std::stoi(sid); + ctct = this->contacts[id]; + ctct.get(); +} + +int PhoneBook::run() +{ + std::cout << "PhoneBook.\n" << "Commands available : ADD, SEARCH, EXIT.\n"; + std::cout << "What do you want?\n"; + std::cin >> this->cmd; + if (cmd == "EXIT") + return (EXIT_FAILURE); + if (cmd == "SEARCH") + this->search(); + else if (cmd == "ADD") + this->add(); + else + std::cout << "Unknown command.\n"; + return (EXIT_SUCCESS); +} diff --git a/CPP00/ex01/PhoneBook.hpp b/CPP00/ex01/PhoneBook.hpp new file mode 100644 index 0000000..88ce766 --- /dev/null +++ b/CPP00/ex01/PhoneBook.hpp @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* PhoneBook.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: narnaud +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/06/13 09:31:44 by narnaud #+# #+# */ +/* Updated: 2022/06/13 15:35:30 by narnaud ### ########.fr */ +/* */ +/* ************************************************************************** */ +#ifndef PHONEBOOK_HPP +# define PHONEBOOK_HPP +# include "Contact.hpp" +# define CONTACTS_AMOUNT 8 + +class PhoneBook +{ + public: + PhoneBook(); + int run(); + private: + Contact contacts[CONTACTS_AMOUNT]; + std::string cmd; + int id; + void add(); + void search(); +}; +#endif diff --git a/CPP00/ex01/a.out b/CPP00/ex01/a.out new file mode 100755 index 0000000..d05e75f Binary files /dev/null and b/CPP00/ex01/a.out differ diff --git a/CPP00/ex01/main.cpp b/CPP00/ex01/main.cpp new file mode 100644 index 0000000..f7a6382 --- /dev/null +++ b/CPP00/ex01/main.cpp @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: narnaud +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/06/13 09:31:46 by narnaud #+# #+# */ +/* Updated: 2022/06/13 15:16:37 by narnaud ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "PhoneBook.hpp" + +int main(void) +{ + PhoneBook pb; + + while (pb.run() == EXIT_SUCCESS) + ; + return (EXIT_SUCCESS); +} diff --git a/README.md b/README.md index 4db71f2..c2aa162 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,12 @@ # CPP +## Subjects : +- [CPP00](https://cdn.intra.42.fr/pdf/pdf/48426/fr.subject.pdf) + ress. +- [CPP01](https://cdn.intra.42.fr/pdf/pdf/50707/en.subject.pdf) +- [CPP02](https://cdn.intra.42.fr/pdf/pdf/48502/fr.subject.pdf) +- [CPP03](https://cdn.intra.42.fr/pdf/pdf/48500/fr.subject.pdf) +- [CPP04](https://cdn.intra.42.fr/pdf/pdf/48498/fr.subject.pdf) +- [CPP05](https://cdn.intra.42.fr/pdf/pdf/51045/fr.subject.pdf) +- [CPP06](https://cdn.intra.42.fr/pdf/pdf/48493/fr.subject.pdf) +- [CPP07](https://cdn.intra.42.fr/pdf/pdf/48487/fr.subject.pdf) + .cpp +- [CPP08](https://cdn.intra.42.fr/pdf/pdf/48485/fr.subject.pdf)