]> git.dkaiser.de - 42/cpp01.git/commitdiff
Implement Harl
authorDominik Kaiser <dkaiser@student.42heilbronn.de>
Wed, 12 Feb 2025 10:36:46 +0000 (11:36 +0100)
committerDominik Kaiser <dkaiser@student.42heilbronn.de>
Wed, 12 Feb 2025 10:36:46 +0000 (11:36 +0100)
ex05/Harl.cpp
ex05/Harl.hpp
ex05/main.cpp

index 91430f7118e958029533e2da2dacae4335dfc853..fcad030d19e60865cb1d8307c01a58191fbabf3b 100644 (file)
@@ -6,8 +6,50 @@
 /*   By: dkaiser <dkaiser@student.42heilbronn.de    +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2025/02/12 10:37:12 by dkaiser           #+#    #+#             */
-/*   Updated: 2025/02/12 10:37:22 by dkaiser          ###   ########.fr       */
+/*   Updated: 2025/02/12 11:29:15 by dkaiser          ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
 #include "Harl.hpp"
+#include <iostream>
+
+void Harl::complain(std::string level)
+{
+    std::string levels[4] = {"DEBUG", "INFO", "WARNING", "ERROR"};
+    void (Harl::*funcs[4])() = {&Harl::debug,
+                         &Harl::info,
+                         &Harl::warning,
+                         &Harl::error};
+    for (int i = 0; i < 4; i++)
+    {
+       if (level == levels[i])
+           (this->*funcs[i])();
+    }
+}
+
+void Harl::debug(void)
+{
+    std::cout << "I love having extra bacon for my ";
+    std::cout << "7XL-double-cheese-triple-pickle-special-ketchup burger. ";
+    std::cout << "I really do!" << std::endl;
+}
+
+void Harl::info(void)
+{
+    std::cout << "I cannot believe adding extra bacon costs more money. ";
+    std::cout << "You didn’t put enough bacon in my burger! ";
+    std::cout << "If you did, I wouldn’t be asking for more!" << std::endl;
+}
+
+void Harl::warning(void)
+{
+    std::cout << "I think I deserve to have some extra bacon for free. ";
+    std::cout << "I’ve been coming for years whereas you ";
+    std::cout << "started working here since last month." << std::endl;
+}
+
+void Harl::error(void)
+{
+    std::cout << "This is unacceptable! I want to speak to the manager now.";
+    std::cout << std::endl;
+}
index a0b1f30de87e798f0dbf52dfc529f9284d369b9f..ade7f9832e03ec69d8e1bda55e43440918ac8b43 100644 (file)
@@ -6,11 +6,23 @@
 /*   By: dkaiser <dkaiser@student.42heilbronn.de    +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2025/02/12 10:36:43 by dkaiser           #+#    #+#             */
-/*   Updated: 2025/02/12 10:37:00 by dkaiser          ###   ########.fr       */
+/*   Updated: 2025/02/12 11:36:33 by dkaiser          ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
 #ifndef HARL_H_
 #define HARL_H_
 
+#include <string>
+class Harl
+{
+    public:
+        void complain(std::string level);
+    private:
+        void debug(void);
+        void info(void);
+        void warning(void);
+        void error(void);
+};
+
 #endif
index 72a37527656c299ea371e83af154ae2d5aabe721..1180187233777658cf289b05ff8a435654767174 100644 (file)
@@ -6,9 +6,19 @@
 /*   By: dkaiser <dkaiser@student.42heilbronn.de    +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2025/02/12 10:35:53 by dkaiser           #+#    #+#             */
-/*   Updated: 2025/02/12 10:36:35 by dkaiser          ###   ########.fr       */
+/*   Updated: 2025/02/12 11:35:27 by dkaiser          ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
+#include "Harl.hpp"
+
 int main(void)
-{}
+{
+    Harl harl = Harl();
+
+    harl.complain("DEBUG");
+    harl.complain("INFO");
+    harl.complain("WARNING");
+    harl.complain("ERROR");
+    harl.complain("Invalid Input");
+}