From 061ee93d2934a8aed216aa9cc3faeaa1b3ff319f Mon Sep 17 00:00:00 2001 From: Fatih Cil Date: Mon, 12 Sep 2022 15:17:55 +0300 Subject: [PATCH] finished ex01 --- CPP/cpp-module-05/ex00/Bureaucrat.hpp | 6 +-- CPP/cpp-module-05/ex01/Bureaucrat.cpp | 4 +- CPP/cpp-module-05/ex01/Bureaucrat.hpp | 4 +- CPP/cpp-module-05/ex01/Form.hpp | 4 +- CPP/cpp-module-05/ex01/main.cpp | 72 ++++++++++++--------------- 5 files changed, 42 insertions(+), 48 deletions(-) diff --git a/CPP/cpp-module-05/ex00/Bureaucrat.hpp b/CPP/cpp-module-05/ex00/Bureaucrat.hpp index 542ad32..5681cff 100644 --- a/CPP/cpp-module-05/ex00/Bureaucrat.hpp +++ b/CPP/cpp-module-05/ex00/Bureaucrat.hpp @@ -6,7 +6,7 @@ /* By: fcil +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/09/11 21:39:02 by fcil #+# #+# */ -/* Updated: 2022/09/12 12:44:58 by fcil ### ########.fr */ +/* Updated: 2022/09/12 13:59:01 by fcil ### ########.fr */ /* */ /* ************************************************************************** */ @@ -39,7 +39,7 @@ class Bureaucrat class GradeTooHighException : public std::exception { public: - const char* what() const throw() + virtual const char* what() const throw() { return ("Grade is too High."); } @@ -48,7 +48,7 @@ class Bureaucrat class GradeTooLowException : public std::exception { public: - const char* what() const throw() + virtual const char* what() const throw() { return ("Grade is too Low."); } diff --git a/CPP/cpp-module-05/ex01/Bureaucrat.cpp b/CPP/cpp-module-05/ex01/Bureaucrat.cpp index 3b09bdd..ab99517 100644 --- a/CPP/cpp-module-05/ex01/Bureaucrat.cpp +++ b/CPP/cpp-module-05/ex01/Bureaucrat.cpp @@ -6,7 +6,7 @@ /* By: fcil +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/09/12 12:00:32 by fcil #+# #+# */ -/* Updated: 2022/09/12 14:59:31 by fcil ### ########.fr */ +/* Updated: 2022/09/12 15:15:06 by fcil ### ########.fr */ /* */ /* ************************************************************************** */ @@ -70,7 +70,7 @@ void Bureaucrat::signForm(Form &form) if (form.getSignGrade() >= this->getGrade()) { form.setSignedResult(true); - std::cout << "<" << this->getName() << "> signs <" << + std::cout << "<" << this->getName() << "> signed <" << form.getName() << ">" << std::endl; } else diff --git a/CPP/cpp-module-05/ex01/Bureaucrat.hpp b/CPP/cpp-module-05/ex01/Bureaucrat.hpp index 3e2b009..12cb9ee 100644 --- a/CPP/cpp-module-05/ex01/Bureaucrat.hpp +++ b/CPP/cpp-module-05/ex01/Bureaucrat.hpp @@ -6,7 +6,7 @@ /* By: fcil +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/09/11 21:39:02 by fcil #+# #+# */ -/* Updated: 2022/09/12 14:55:03 by fcil ### ########.fr */ +/* Updated: 2022/09/12 15:02:49 by fcil ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,6 +19,8 @@ #define LOWEST 150 #define HIGHEST 1 +class Form; + class Bureaucrat { private: diff --git a/CPP/cpp-module-05/ex01/Form.hpp b/CPP/cpp-module-05/ex01/Form.hpp index 4640dd8..6304d7d 100644 --- a/CPP/cpp-module-05/ex01/Form.hpp +++ b/CPP/cpp-module-05/ex01/Form.hpp @@ -6,7 +6,7 @@ /* By: fcil +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/09/12 13:46:52 by fcil #+# #+# */ -/* Updated: 2022/09/12 14:56:35 by fcil ### ########.fr */ +/* Updated: 2022/09/12 15:02:31 by fcil ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,6 +14,8 @@ #include "Bureaucrat.hpp" +class Bureaucrat; + class Form { private: diff --git a/CPP/cpp-module-05/ex01/main.cpp b/CPP/cpp-module-05/ex01/main.cpp index a835d53..7782378 100644 --- a/CPP/cpp-module-05/ex01/main.cpp +++ b/CPP/cpp-module-05/ex01/main.cpp @@ -6,7 +6,7 @@ /* By: fcil +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/09/12 11:42:20 by fcil #+# #+# */ -/* Updated: 2022/09/12 13:06:26 by fcil ### ########.fr */ +/* Updated: 2022/09/12 15:16:00 by fcil ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,50 +14,40 @@ int main(void) { - try - { - Bureaucrat f("fatih", 4); - std::cout << f << std::endl; - } - catch(const Bureaucrat::GradeTooHighException &e) - { - std::cerr << e.what() << std::endl; - } - try - { - Bureaucrat a("abyerk", 200); - } - catch(const std::exception& e) - { - std::cerr << e.what() << std::endl; - } try - { - Bureaucrat bureaucrat1("uwu", 1); - bureaucrat1.incrementGrade(); - std::cout << bureaucrat1 << std::endl; + { + Form form1("Player Contract", 150, 150); + Bureaucrat bCrat1("Richarlison", 1); + form1.beSigned(bCrat1); + std::cout << "Welcome to the Club" << std::endl; + bCrat1.incrementGrade(); } - catch (Bureaucrat::GradeTooHighException &e) - { - std::cerr << e.what() << std::endl; + catch (std::exception &e) + { + std::cout << "About to print the exception" << std::endl; + std::cout << e.what() << std::endl; } - catch (Bureaucrat::GradeTooLowException &e) - { - std::cerr << e.what() << std::endl; - } - + + std::cout << "<<<<<<<<<<<<>>>>>>>>>>>" << std::endl; try - { - Bureaucrat bureaucrat2("blabla", 150); - bureaucrat2.decrementGrade(); - std::cout << bureaucrat2 << std::endl; - } - catch (Bureaucrat::GradeTooHighException &e) - { - std::cerr << e.what() << std::endl; + { + Form form1("Drivers License", 1, 1); + std::cout << form1; + Bureaucrat bCrat1("Caitlyn Jenner", 150); + form1.beSigned(bCrat1); } - catch (Bureaucrat::GradeTooLowException &e) - { - std::cerr << e.what() << std::endl; + catch (std::exception &e) + { + std::cout << "About to print the exception" << std::endl; + std::cout << e.what() << std::endl; } + std::cout << "<<<<<<<<<<<<<>>>>>>>>>>>>>" << std::endl; + Form form1("uwu", 60, 60); + std::cout << form1; + Bureaucrat bCrat1("aa", 50); + Bureaucrat bCrat2("bb", 120); + bCrat1.signForm(form1); + std::cout << form1; + bCrat2.signForm(form1); + std::cout << "<<<<<<<<<<<<<>>>>>>>>>>>>>" << std::endl; } \ No newline at end of file