diff --git a/CPP00/ex00/Makefile b/CPP00/ex00/Makefile index c1de22d..458e89f 100644 --- a/CPP00/ex00/Makefile +++ b/CPP00/ex00/Makefile @@ -1,16 +1,21 @@ NAME = megaphone SRC = main.cpp +OBJ = main.o -CC = c++ -CFLAGS = -std=c++98 -Wall -Werror -Wextra +CXXFLAGS = -std=c++98 -Wall -Werror -Wextra RM = rm -rf -$(NAME): $(SRC) - $(CC) $(CFLAGS) $(SRC) -o $(NAME) +$(NAME): $(OBJ) + c++ $(OBJ) -o $(NAME) all: $(NAME) clean: + $(RM) $(OBJ) + +fclean: clean $(RM) $(NAME) -.PHONY: all re +re: fclean all + +.PHONY: all clean fclean re diff --git a/CPP00/ex00/main.cpp b/CPP00/ex00/main.cpp index 54d37c2..71b422c 100644 --- a/CPP00/ex00/main.cpp +++ b/CPP00/ex00/main.cpp @@ -11,7 +11,6 @@ /* ************************************************************************** */ # include -# include int main(int argc, char **argv) { @@ -30,5 +29,4 @@ int main(int argc, char **argv) } } std::cout << std::endl; - return (EXIT_SUCCESS); } diff --git a/CPP00/ex00/megaphone b/CPP00/ex00/megaphone deleted file mode 100755 index 2f79b4d..0000000 Binary files a/CPP00/ex00/megaphone and /dev/null differ diff --git a/CPP00/ex01/Contact.cpp b/CPP00/ex01/Contact.cpp index 5f82dd0..cd9ffee 100644 --- a/CPP00/ex01/Contact.cpp +++ b/CPP00/ex01/Contact.cpp @@ -15,41 +15,45 @@ Contact::Contact(){} void Contact::set(int id) { - this->id = id; + _id = id; std::cout << "Enter new contact first name:\n"; - std::cin >> this->datas[FIRST]; + while (_datas[FIRST] == "") + std::cin >> _datas[FIRST]; std::cout << "Enter new contact last name:\n"; - std::cin >> this->datas[LAST]; + while (_datas[LAST] == "") + std::cin >> _datas[LAST]; std::cout << "Enter new contact nickname:\n"; - std::cin >> this->datas[NICK]; + while (_datas[NICK] == "") + std::cin >> _datas[NICK]; std::cout << "Enter new contact number:\n"; - std::cin >> this->datas[NUMBER]; + while (_datas[NUMBER] == "") + std::cin >> _datas[NUMBER]; std::cout << "Enter new contact secret:\n"; - std::cin >> this->datas[SECRET]; - std::cout << std::endl; + while (_datas[SECRET] == "") + std::cin >> _datas[SECRET]; } void Contact::summary() { std::cout << "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n"; std::cout << "|"; - std::cout << std::setw(2) << this->id; + std::cout << std::setw(2) << _id; std::cout << "|"; for (int i = 0; i <= SECRET; i++) { - if (this->datas[i].length() < 10) - std::cout << std::setw(10) << this->datas[i] << "|"; + if (_datas[i].length() < 10) + std::cout << std::setw(10) << _datas[i] << "|"; else - std::cout << this->datas[i].substr(0, 9) << "." << "|"; + std::cout << _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; + std::cout <<"First name : " << _datas[FIRST] << std::endl; + std::cout <<"Last name : " << _datas[LAST] << std::endl; + std::cout <<"Nick name : " << _datas[NICK] << std::endl; + std::cout <<"Phone nb : " << _datas[NUMBER] << std::endl; + std::cout <<"Dark secret : " << _datas[SECRET] << std::endl; } diff --git a/CPP00/ex01/Contact.hpp b/CPP00/ex01/Contact.hpp index 5d7665c..35f1526 100644 --- a/CPP00/ex01/Contact.hpp +++ b/CPP00/ex01/Contact.hpp @@ -9,12 +9,10 @@ /* Updated: 2022/06/13 16:35:43 by narnaud ### ########.fr */ /* */ /* ************************************************************************** */ -#ifndef CONTACT_HPP -# define CONTACT_HPP - -# include -# include -# include +#pragma once +#include +#include +#include enum e_datas { @@ -33,7 +31,6 @@ class Contact void summary(); void get(); private: - int id; - std::string datas[5]; + int _id; + std::string _datas[5]; }; -#endif diff --git a/CPP00/ex01/Makefile b/CPP00/ex01/Makefile new file mode 100644 index 0000000..8fc3237 --- /dev/null +++ b/CPP00/ex01/Makefile @@ -0,0 +1,20 @@ +NAME = phonebook +SRCS = main.cpp PhoneBook.cpp Contact.cpp +OBJS = $(SRCS:.cpp=.o) + +CXXFLAGS = -std=c++98 -Werror -Wextra -Wall + +$(NAME): $(OBJS) + c++ $(OBJS) -o $(NAME) + +all: $(NAME) + +clean: + rm -rf $(OBJS) + +fclean: clean + rm -rf $(NAME) + +re: fclean all + +.PHONY: all clean fclean re diff --git a/CPP00/ex01/PhoneBook.cpp b/CPP00/ex01/PhoneBook.cpp index f2e798d..6871ab3 100644 --- a/CPP00/ex01/PhoneBook.cpp +++ b/CPP00/ex01/PhoneBook.cpp @@ -12,15 +12,13 @@ #include "PhoneBook.hpp" -PhoneBook::PhoneBook() -{ - this->id = 0; +PhoneBook::PhoneBook() { + _id = 0; } -void PhoneBook::add() -{ - int id = this->id % CONTACTS_AMOUNT; - if (this->id > 7) +void PhoneBook::add() { + int id = _id % CONTACTS_AMOUNT; + if (_id > CONTACTS_AMOUNT - 1) { std::cout << "You gonna remove the contact n." << id; std::cout << "\nTo continue, type 'y': "; @@ -28,45 +26,37 @@ void PhoneBook::add() std::cin >> confirm; if (confirm != "y") { - std::cout << "\nAbort.\n"; + std::cout << std::endl << "Abort." << std::endl; return ; } std::cout << std::endl; } - this->contacts[id].set(id); - this->id++; + _contacts[id].set(id); + _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]; - } +void PhoneBook::search() { + for (int id = 0; id < _id % CONTACTS_AMOUNT; id++) + _contacts[id].summary(); 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(); + _contacts[(int)std::strtod(sid.c_str(), 0)].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); +void PhoneBook::run() { + std::string cmd; + while (cmd != "EXIT" && cmd != "3") + { + std::cout << "=== PHONEBOOK ===" << std::endl; + std::cout << "Commands available : 1-ADD, 2-SEARCH, 3-EXIT.\n"; + std::cout << "What do you want? "; + std::cin >> cmd; + if (cmd == "ADD" || cmd == "1") + this->add(); + else if (cmd == "SEARCH" || cmd == "2") + this->search(); + else if (cmd != "EXIT" && cmd != "3") + std::cout << "Unknown command." << std::endl; + } } diff --git a/CPP00/ex01/PhoneBook.hpp b/CPP00/ex01/PhoneBook.hpp index 88ce766..85d3030 100644 --- a/CPP00/ex01/PhoneBook.hpp +++ b/CPP00/ex01/PhoneBook.hpp @@ -9,21 +9,19 @@ /* Updated: 2022/06/13 15:35:30 by narnaud ### ########.fr */ /* */ /* ************************************************************************** */ -#ifndef PHONEBOOK_HPP -# define PHONEBOOK_HPP -# include "Contact.hpp" -# define CONTACTS_AMOUNT 8 +#pragma once +#include "Contact.hpp" +#include +#define CONTACTS_AMOUNT 8 class PhoneBook { public: PhoneBook(); - int run(); + void run(); private: - Contact contacts[CONTACTS_AMOUNT]; - std::string cmd; - int id; + Contact _contacts[CONTACTS_AMOUNT]; + int _id; void add(); void search(); }; -#endif diff --git a/CPP00/ex01/main.cpp b/CPP00/ex01/main.cpp index f7a6382..762764a 100644 --- a/CPP00/ex01/main.cpp +++ b/CPP00/ex01/main.cpp @@ -14,9 +14,7 @@ int main(void) { - PhoneBook pb; + PhoneBook phone; - while (pb.run() == EXIT_SUCCESS) - ; - return (EXIT_SUCCESS); + phone.run(); } diff --git a/CPP01/ex00/Zombie.cpp b/CPP01/ex00/Zombie.cpp index fbe34f7..a29d168 100644 --- a/CPP01/ex00/Zombie.cpp +++ b/CPP01/ex00/Zombie.cpp @@ -12,17 +12,14 @@ #include "Zombie.hpp" -Zombie::Zombie(string name):_name(name) -{ +Zombie::Zombie(string name):_name(name) { cout << "*" << name << " died.*\n"; } -Zombie::~Zombie(void) -{ - cout << "*" << this->_name << " really died.*\n"; +Zombie::~Zombie(void) { + cout << "*Zombie " << _name << " really died.*\n"; } -void Zombie::announce(void) const -{ - cout << this->_name << ": BraiiiiiiinnnzzzZ...\n"; +void Zombie::announce(void) const { + cout << _name << ": BraiiiiiiinnnzzzZ...\n"; } diff --git a/CPP01/ex00/Zombie.hpp b/CPP01/ex00/Zombie.hpp index c57e189..e4e2b5e 100644 --- a/CPP01/ex00/Zombie.hpp +++ b/CPP01/ex00/Zombie.hpp @@ -17,6 +17,7 @@ # endif #include +#include using std::cin; using std::cout; using std::string; diff --git a/CPP01/ex00/main.cpp b/CPP01/ex00/main.cpp index 14ddbb6..1066874 100644 --- a/CPP01/ex00/main.cpp +++ b/CPP01/ex00/main.cpp @@ -20,5 +20,4 @@ int main(void) randomChump("Aurel"); if (DEBUG) system("leaks apocalypse"); - return (EXIT_SUCCESS); } diff --git a/CPP01/ex01/Makefile b/CPP01/ex01/Makefile index 27da46f..0c31381 100644 --- a/CPP01/ex01/Makefile +++ b/CPP01/ex01/Makefile @@ -1,7 +1,7 @@ NAME = apocalypse SRCS = main.cpp Zombie.cpp zombieHorde.cpp OBJS = $(SRCS:.cpp=.o) -CXXFLAGS = -g -std=c++98 -Werror -Wextra -Wall +CXXFLAGS = -std=c++98 -Werror -Wextra -Wall $(NAME): $(OBJS) c++ $(OBJS) -o $(NAME) diff --git a/CPP01/ex01/Zombie.cpp b/CPP01/ex01/Zombie.cpp index 7cc1cf8..d4716d2 100644 --- a/CPP01/ex01/Zombie.cpp +++ b/CPP01/ex01/Zombie.cpp @@ -21,7 +21,7 @@ Zombie::Zombie(string name):_name(name) Zombie::~Zombie(void) { - cout << "*" << _name << " really died.*\n"; + cout << "*Zombie " << _name << " really died.*\n"; } void Zombie::announce(void) const @@ -31,5 +31,6 @@ void Zombie::announce(void) const void Zombie::setName(string name) { + cout << "*" << name << " died.*\n"; _name = name; } diff --git a/CPP01/ex01/Zombie.hpp b/CPP01/ex01/Zombie.hpp index d115ed5..bb48858 100644 --- a/CPP01/ex01/Zombie.hpp +++ b/CPP01/ex01/Zombie.hpp @@ -18,6 +18,8 @@ # define ZB_AMOUNT 8 #include +#include +#include using std::cin; using std::cout; using std::string; diff --git a/CPP01/ex01/apocalypse b/CPP01/ex01/apocalypse deleted file mode 100755 index cc578a7..0000000 Binary files a/CPP01/ex01/apocalypse and /dev/null differ diff --git a/CPP01/ex01/main.cpp b/CPP01/ex01/main.cpp index 43bcb50..c9af313 100644 --- a/CPP01/ex01/main.cpp +++ b/CPP01/ex01/main.cpp @@ -15,10 +15,9 @@ int main(void) { Zombie *zombs = zombieHorde(ZB_AMOUNT, "Zombie"); - int i = 0; - while (i < ZB_AMOUNT) - zombs[i++].announce(); + for (int i = 0; i < ZB_AMOUNT; i++) + zombs[i].announce(); delete [] zombs; if (DEBUG) system("leaks apocalypse"); diff --git a/CPP01/ex01/zombieHorde.cpp b/CPP01/ex01/zombieHorde.cpp index 18c7511..c2fd183 100644 --- a/CPP01/ex01/zombieHorde.cpp +++ b/CPP01/ex01/zombieHorde.cpp @@ -18,7 +18,7 @@ Zombie *zombieHorde(int N, string name) int n = 0; while (n < N) { - ret[n].setName(name + std::to_string(n)); + ret[n].setName(n); n++; } return (ret); diff --git a/CPP06/.main.cpp.swp b/CPP06/.main.cpp.swp deleted file mode 100644 index d52c657..0000000 Binary files a/CPP06/.main.cpp.swp and /dev/null differ diff --git a/CPP06/ex00/Converter.cpp b/CPP06/ex00/Converter.cpp index 254d4c3..3ce027d 100644 --- a/CPP06/ex00/Converter.cpp +++ b/CPP06/ex00/Converter.cpp @@ -16,9 +16,33 @@ Converter::Converter (void) { cout << "Converter default constructor called " << endl; } -Converter::Converter (string str):_input(str){ - startConv(); - cout << "Converter parameter constructor called" << endl; +Converter::Converter (string str){ + if (str[0] == '\'' || str[0] == '"') + { + _c = str[1]; + cout << "Char: " << _c << endl; + _d = static_cast(_c); + } + else + { + cout << "Char: "; + _d = std::strtod(str.c_str(), 0); + _c = static_cast(_d); + if (_d < 0 || _d > 255) + cout << "Invalid" << endl; + else if (std::isprint(_c)) + cout << "Not Printable" << endl; + else + cout << _c << endl; + } + cout << "Double: " << _d << endl; + cout << "Integer: "; + _i = static_cast(_d); + if (_d < std::numeric_limits::min() || _d > std::numeric_limits::max()) + cout << "Off limits -> "; + cout << _i << endl; + _f = static_cast(_d); + cout << "Float: " << _f << "f"<< endl; } Converter::Converter (Converter const & src) { @@ -36,27 +60,3 @@ Converter::~Converter (void) { cout << "Converter default destructor called" << endl; } - - -void Converter::startConv(void) { - if (_input[0] == '\'' || _input[0] == '"') - { - _c = _input[1]; - _d = static_cast(_c); - } - else - { - _d = std::strtod(_input.c_str(), 0); - _c = static_cast(_d); - } - _i = static_cast(_d); - _f = static_cast(_d); -} - -void Converter::display(void) { - cout << "Input: " << _input << endl; - cout << "Char: " << _c << endl; - cout << "Double: " << _d << endl; - cout << "Float: " << _f << endl; - cout << "Integer: " << _i << endl; -} diff --git a/CPP06/ex00/Converter.hpp b/CPP06/ex00/Converter.hpp index 3898296..b13ad66 100644 --- a/CPP06/ex00/Converter.hpp +++ b/CPP06/ex00/Converter.hpp @@ -15,6 +15,9 @@ #include #include #include +#include +#include +#include using std::cout; using std::endl; using std::string; @@ -33,6 +36,4 @@ class Converter{ Converter(Converter const & src); virtual ~Converter(void); Converter & operator= (Converter const & src); - void startConv(void); - void display(void); }; diff --git a/CPP06/ex00/Converter.o b/CPP06/ex00/Converter.o deleted file mode 100644 index ea72cfe..0000000 Binary files a/CPP06/ex00/Converter.o and /dev/null differ diff --git a/CPP06/ex00/convert b/CPP06/ex00/convert deleted file mode 100755 index da02f22..0000000 Binary files a/CPP06/ex00/convert and /dev/null differ diff --git a/CPP06/ex00/main.cpp b/CPP06/ex00/main.cpp index 7de8477..91b5a6f 100644 --- a/CPP06/ex00/main.cpp +++ b/CPP06/ex00/main.cpp @@ -23,6 +23,4 @@ int main(int ac, char **av) { return (EXIT_FAILURE); string input = av[1]; Converter raw(input); - raw.display(); - } diff --git a/CPP06/ex00/main.o b/CPP06/ex00/main.o deleted file mode 100644 index 2505a0b..0000000 Binary files a/CPP06/ex00/main.o and /dev/null differ