From 331c3596660fed6c8b04fdfd0a89435ccffaaf20 Mon Sep 17 00:00:00 2001 From: Charles Cabergs Date: Tue, 17 Nov 2020 13:52:48 +0100 Subject: Fixing cpp05/ex00-02 --- cpp05/ex01/main.cpp | 103 +++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 81 insertions(+), 22 deletions(-) (limited to 'cpp05/ex01/main.cpp') diff --git a/cpp05/ex01/main.cpp b/cpp05/ex01/main.cpp index ebfed5a..3200b0f 100644 --- a/cpp05/ex01/main.cpp +++ b/cpp05/ex01/main.cpp @@ -6,7 +6,7 @@ /* By: charles +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/14 18:13:05 by charles #+# #+# */ -/* Updated: 2020/04/14 18:43:15 by charles ### ########.fr */ +/* Updated: 2020/11/17 12:10:38 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,35 +14,94 @@ int main() { - Bureaucrat a("jean", 140); - Bureaucrat b("didier", 10); - - while (true) { - try + std::cout << "=============== BUREAUCRAT ===============" << std::endl; + std::cout << "############### CREATION" << std::endl; + try { Bureaucrat bu("YO", 0); } + catch (std::exception& e) { std::cout << e.what() << std::endl; } + try { Bureaucrat bu("YO2", 151); } + catch (std::exception& e) { std::cout << e.what() << std::endl; } + + Bureaucrat yep("YEP", 1); + Bureaucrat yep2(yep); + Bureaucrat yep3("SHOULD NOT BE PRINTED", 42); + yep3 = yep; + std::cout << yep; + std::cout << yep2; + std::cout << yep3; + + std::cout << "############### DECREMENT" << std::endl; + Bureaucrat a("jean", 140); + while (true) { - a.decrementGrade(); - std::cout << a; + try + { + a.decrementGrade(); + std::cout << a; + } + catch (std::exception& e) + { + std::cout << e.what() << std::endl; + break; + } } - catch (std::exception& e) + + std::cout << "############### INCREMENT" << std::endl; + Bureaucrat b("didier", 10); + while (true) { - std::cout << e.what() << std::endl; - break; + try + { + b.incrementGrade(); + std::cout << b; + } + catch (std::exception& e) + { + std::cout << e.what() << std::endl; + break; + } } + + Bureaucrat c("baraucrat", 10); + std::cout << "############### SIGN FORM" << std::endl; + Form f4("foo", 150, 1); c.signForm(f4); + Form f3("foo", 10, 1); c.signForm(f3); + Form f2("foo", 9, 1); c.signForm(f2); + Form f1("foo", 1, 1); c.signForm(f1); } - while (true) + std::cout << std::endl; + { - try - { - b.incrementGrade(); - std::cout << b; - } - catch (std::exception& e) - { - std::cout << e.what() << std::endl; - break; - } + std::cout << "=============== FORM ===============" << std::endl; + Form f("FormBonjour", 32, 42); + std::cout << f; + Form f2(f); + std::cout << f2; + Form f3("Const", 1, 2); + f3 = f; + std::cout << f3; + + try { Form f("YO", 0, 1); } + catch (std::exception& e) { std::cout << e.what() << std::endl; } + try { Form f("YO2", 151, 1); } + catch (std::exception& e) { std::cout << e.what() << std::endl; } + try { Form f("YO", 1, 0); } + catch (std::exception& e) { std::cout << e.what() << std::endl; } + try { Form f("YO2", 1, 151); } + catch (std::exception& e) { std::cout << e.what() << std::endl; } + + std::cout << "############### BE SIGNED" << std::endl; + try { f.beSigned(Bureaucrat("foo", 1)); std::cout << f; } + catch (std::exception& e) { std::cout << "SHOULD NO PRINT " << e.what() << std::endl; } + try { f.beSigned(Bureaucrat("foo", 32)); std::cout << f; } + catch (std::exception& e) { std::cout << "SHOULD NO PRINT " << e.what() << std::endl; } + + try { f.beSigned(Bureaucrat("foo", 33)); } + catch (std::exception& e) { std::cout << e.what() << std::endl; } + try { f.beSigned(Bureaucrat("foo", 150)); } + catch (std::exception& e) { std::cout << e.what() << std::endl; } } + return 0; } -- cgit