diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..2f50595 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,48 @@ +{ + "files.associations": { + "array": "cpp", + "atomic": "cpp", + "bit": "cpp", + "cctype": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "compare": "cpp", + "concepts": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "deque": "cpp", + "string": "cpp", + "unordered_map": "cpp", + "vector": "cpp", + "exception": "cpp", + "algorithm": "cpp", + "functional": "cpp", + "iterator": "cpp", + "memory": "cpp", + "memory_resource": "cpp", + "numeric": "cpp", + "random": "cpp", + "string_view": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "utility": "cpp", + "fstream": "cpp", + "initializer_list": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "limits": "cpp", + "new": "cpp", + "numbers": "cpp", + "ostream": "cpp", + "stdexcept": "cpp", + "streambuf": "cpp", + "typeinfo": "cpp" + } +} diff --git a/ex01/Main.cpp b/ex01/Main.cpp index 0bf1292..538f51f 100644 --- a/ex01/Main.cpp +++ b/ex01/Main.cpp @@ -88,13 +88,13 @@ int main(void) std::cout << "\033[34m" << std::endl << "Test signatures de formulaires" << "\033[0m" << std::endl; Form formulaire_id("FORMULAIRE IDENTITE", 100, 90); - Bureaucrat mr_lent; + Bureaucrat mr_bad; Bureaucrat mr_identite("MR_IDENTITE", 100); std::cout << formulaire_id; - - mr_lent.signForm(formulaire_id); + std::cout << std::endl << "Mr_bad try" << std::endl; + mr_bad.signForm(formulaire_id); std::cout << formulaire_id; - + std::cout << std::endl << "MR_IDENTITE try" << std::endl; mr_identite.signForm(formulaire_id); std::cout << formulaire_id; diff --git a/ex02/AForm.hpp b/ex02/AForm.hpp index 851172b..1458b7b 100644 --- a/ex02/AForm.hpp +++ b/ex02/AForm.hpp @@ -21,7 +21,7 @@ class AForm AForm(); AForm(const std::string name, const int grade_si, const int grade_ex); AForm(const AForm &other); - ~AForm(); + virtual ~AForm(); AForm &operator=(const AForm &other); //mem diff --git a/ex02/Hello_shrubbery b/ex02/Hello_shrubbery new file mode 100644 index 0000000..082d0cc --- /dev/null +++ b/ex02/Hello_shrubbery @@ -0,0 +1,9 @@ + _-_ + /~~ ~~\ + /~~ ~~\ +{ } + \ _- -_ / + ~ \\ // ~ +_- - | | _- _ + _ - | | -_ + // \\ diff --git a/ex02/Main.cpp b/ex02/Main.cpp index ce95e9f..fa0f42d 100644 --- a/ex02/Main.cpp +++ b/ex02/Main.cpp @@ -23,7 +23,9 @@ int main(void) RobotomyRequestForm Robo_form("I am a robo form"); Bureaucrat Mr_Robo("Mr_Robo", 45); + Mr_Robo.executeForm(Robo_form); + Mr_Robo.signForm(Robo_form); Mr_Robo.executeForm(Robo_form); Mr_Robo.executeForm(Robo_form); diff --git a/ex03/AForm.hpp b/ex03/AForm.hpp index 851172b..856bbe0 100644 --- a/ex03/AForm.hpp +++ b/ex03/AForm.hpp @@ -21,7 +21,7 @@ class AForm AForm(); AForm(const std::string name, const int grade_si, const int grade_ex); AForm(const AForm &other); - ~AForm(); + virtual ~AForm(); AForm &operator=(const AForm &other); //mem diff --git a/ex03/Hello_shrubbery b/ex03/Hello_shrubbery new file mode 100644 index 0000000..082d0cc --- /dev/null +++ b/ex03/Hello_shrubbery @@ -0,0 +1,9 @@ + _-_ + /~~ ~~\ + /~~ ~~\ +{ } + \ _- -_ / + ~ \\ // ~ +_- - | | _- _ + _ - | | -_ + // \\ diff --git a/ex03/Main.cpp b/ex03/Main.cpp index ce95e9f..6df2063 100644 --- a/ex03/Main.cpp +++ b/ex03/Main.cpp @@ -3,6 +3,7 @@ #include "PresidentialPardonForm.hpp" #include "RobotomyRequestForm.hpp" #include "ShrubberyCreationForm.hpp" +#include "intern.hpp" int main(void) { @@ -40,5 +41,15 @@ int main(void) Mr_President.signForm(President_form); Mr_President.executeForm(President_form); + std::cout << "\033[33m" << std::endl << "Test ex03 Intern" << "\033[0m" << std::endl; + + Intern intern; + AForm *roboto; + + roboto = intern.makeForm("DoYouKnowMe", "Hmmmm"); + roboto = intern.makeForm("RobotomyRequestForm", "World"); + + std::cout << roboto->getName() << std::endl; + delete roboto; return (0); } diff --git a/ex03/Makefile b/ex03/Makefile index cede060..dd77921 100644 --- a/ex03/Makefile +++ b/ex03/Makefile @@ -1,9 +1,9 @@ CXX = c++ CXXFLAGS = -Wall -Wextra -Werror -std=c++98 OBJDIR = obj -SOURCES = Main.cpp Bureaucrat.cpp AForm.cpp PresidentialPardonForm.cpp RobotomyRequestForm.cpp ShrubberyCreationForm.cpp +SOURCES = Main.cpp Bureaucrat.cpp AForm.cpp PresidentialPardonForm.cpp RobotomyRequestForm.cpp ShrubberyCreationForm.cpp intern.cpp OBJECTS = $(addprefix $(OBJDIR)/, $(SOURCES:.cpp=.o)) -NAME = AForm +NAME = intern all: $(NAME) diff --git a/ex03/intern.cpp b/ex03/intern.cpp new file mode 100644 index 0000000..88dab33 --- /dev/null +++ b/ex03/intern.cpp @@ -0,0 +1,49 @@ +#include "intern.hpp" +#include "AForm.hpp" +#include "PresidentialPardonForm.hpp" +#include "RobotomyRequestForm.hpp" +#include "ShrubberyCreationForm.hpp" + +// Constructors +Intern::Intern() +{ +} + +Intern::Intern(const Intern &other) +{ + (void)other; +} + +Intern &Intern::operator=(const Intern &other) +{ + (void)other; + return (*this); +} + +Intern::~Intern() +{ +} + +AForm *Intern::makeForm(const std::string form_name, const std::string form_target) +{ + int i = 0; + std::string available_forms[] = {"ShrubberyCreationForm", "RobotomyRequestForm", "PresidentialPardonForm"}; + + while (i < 3 && form_name != available_forms[i]) + i++; + + switch (i) { + case 0: + std::cout << "Intern creates " << form_name << std::endl; + return (new ShrubberyCreationForm(form_target)); + case 1: + std::cout << "Intern creates " << form_name << std::endl; + return (new RobotomyRequestForm(form_name)); + case 2: + std::cout << "Intern creates " << form_name << std::endl; + return (new PresidentialPardonForm(form_target)); + default: + std::cout << "Form is not existing" << std::endl; + return NULL; + } +} diff --git a/ex03/intern.hpp b/ex03/intern.hpp new file mode 100644 index 0000000..b367ed7 --- /dev/null +++ b/ex03/intern.hpp @@ -0,0 +1,22 @@ +#ifndef INTERN_HPP +#define INTERN_HPP + +#include "AForm.hpp" +#include +#include +#include + +class AForm; + +class Intern +{ + public: + Intern(); + Intern(const Intern &other); + Intern &operator=(const Intern &other); + ~Intern(); + + AForm *makeForm(const std::string form_name, const std::string form_target); +}; + +#endif