From 0700c0e42bccc8c97582d781dce31c0e8956a382 Mon Sep 17 00:00:00 2001 From: whaffman Date: Wed, 2 Apr 2025 12:30:39 +0200 Subject: [PATCH] better --- ex00/inc/Zombie.hpp | 7 +++---- ex00/src/main.cpp | 6 +++--- ex00/src/newZombie.cpp | 4 ++-- ex00/src/randomChump.cpp | 4 ++-- ex01/inc/Zombie.hpp | 6 ++++-- ex01/src/main.cpp | 4 ++-- ex01/src/zombieHorde.cpp | 4 ++-- ex03/inc/HumanA.hpp | 6 +++--- ex03/inc/HumanB.hpp | 6 +++--- ex03/inc/Weapon.hpp | 2 +- ex03/src/HumanA.cpp | 15 ++++----------- ex03/src/main.cpp | 10 +++++----- ex04/src/main.cpp | 25 +++++++++++++++++-------- ex05/inc/Harl.hpp | 29 +++++++++++++++-------------- ex05/src/Harl.cpp | 25 ++++++++++--------------- ex05/src/main.cpp | 2 +- ex06/inc/Harl.hpp | 30 +++++++++++++++++------------- ex06/src/Harl.cpp | 32 +++++++++++++++++++------------- ex06/src/main.cpp | 19 +++++++++---------- 19 files changed, 122 insertions(+), 114 deletions(-) diff --git a/ex00/inc/Zombie.hpp b/ex00/inc/Zombie.hpp index eab643f..92698eb 100644 --- a/ex00/inc/Zombie.hpp +++ b/ex00/inc/Zombie.hpp @@ -6,7 +6,7 @@ /* By: whaffman +#+ */ /* +#+ */ /* Created: 2025/03/21 15:19:56 by whaffman #+# #+# */ -/* Updated: 2025/03/21 15:30:14 by whaffman ######## odam.nl */ +/* Updated: 2025/04/02 10:43:54 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ @@ -25,7 +25,6 @@ public: ~Zombie(); void announce(); void setName(std::string name); + static Zombie *newZombie(std::string name); + static void randomChump(std::string name); }; - -Zombie* newZombie( std::string name ); -void randomChump( std::string name ); diff --git a/ex00/src/main.cpp b/ex00/src/main.cpp index e361938..ea2590b 100644 --- a/ex00/src/main.cpp +++ b/ex00/src/main.cpp @@ -6,7 +6,7 @@ /* By: whaffman +#+ */ /* +#+ */ /* Created: 2025/03/21 15:31:11 by whaffman #+# #+# */ -/* Updated: 2025/03/21 15:33:25 by whaffman ######## odam.nl */ +/* Updated: 2025/04/02 10:45:10 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ @@ -14,9 +14,9 @@ int main() { - Zombie* zombie = newZombie("Alice"); + Zombie* zombie = Zombie::newZombie("Alice"); zombie->announce(); - randomChump("Bob"); + Zombie::randomChump("Bob"); delete zombie; return (0); } \ No newline at end of file diff --git a/ex00/src/newZombie.cpp b/ex00/src/newZombie.cpp index 5ac2bd1..4bd4187 100644 --- a/ex00/src/newZombie.cpp +++ b/ex00/src/newZombie.cpp @@ -6,13 +6,13 @@ /* By: whaffman +#+ */ /* +#+ */ /* Created: 2025/03/21 15:30:53 by whaffman #+# #+# */ -/* Updated: 2025/03/21 15:31:04 by whaffman ######## odam.nl */ +/* Updated: 2025/04/02 10:44:28 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ #include "Zombie.hpp" -Zombie* newZombie(std::string name) +Zombie* Zombie::newZombie(std::string name) { Zombie* zombie = new Zombie(name); return (zombie); diff --git a/ex00/src/randomChump.cpp b/ex00/src/randomChump.cpp index b012c21..124870d 100644 --- a/ex00/src/randomChump.cpp +++ b/ex00/src/randomChump.cpp @@ -6,13 +6,13 @@ /* By: whaffman +#+ */ /* +#+ */ /* Created: 2025/03/21 15:30:21 by whaffman #+# #+# */ -/* Updated: 2025/03/21 15:30:49 by whaffman ######## odam.nl */ +/* Updated: 2025/04/02 10:44:34 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ #include "Zombie.hpp" -void randomChump(std::string name) +void Zombie::randomChump(std::string name) { Zombie zombie(name); zombie.announce(); diff --git a/ex01/inc/Zombie.hpp b/ex01/inc/Zombie.hpp index 52c5cc2..cfe21f5 100644 --- a/ex01/inc/Zombie.hpp +++ b/ex01/inc/Zombie.hpp @@ -6,7 +6,7 @@ /* By: whaffman +#+ */ /* +#+ */ /* Created: 2025/03/21 15:19:56 by whaffman #+# #+# */ -/* Updated: 2025/03/21 15:59:48 by whaffman ######## odam.nl */ +/* Updated: 2025/04/02 10:48:04 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ @@ -25,6 +25,8 @@ public: ~Zombie(); void announce() const; void setName(std::string name); + + static Zombie *zombieHorde(int N, std::string name); + }; -Zombie* zombieHorde( int N, std::string name ); diff --git a/ex01/src/main.cpp b/ex01/src/main.cpp index 12b9397..399f57f 100644 --- a/ex01/src/main.cpp +++ b/ex01/src/main.cpp @@ -6,7 +6,7 @@ /* By: whaffman +#+ */ /* +#+ */ /* Created: 2025/03/21 15:31:11 by whaffman #+# #+# */ -/* Updated: 2025/03/21 16:05:08 by whaffman ######## odam.nl */ +/* Updated: 2025/04/02 10:48:25 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ @@ -15,7 +15,7 @@ int main() { - Zombie *horde = zombieHorde(5, "One of the horde"); + Zombie *horde = Zombie::zombieHorde(5, "One of the horde"); for (int i = 0; i < 5; i++) { horde[i].announce(); diff --git a/ex01/src/zombieHorde.cpp b/ex01/src/zombieHorde.cpp index 5d873b1..9ef9838 100644 --- a/ex01/src/zombieHorde.cpp +++ b/ex01/src/zombieHorde.cpp @@ -6,13 +6,13 @@ /* By: whaffman +#+ */ /* +#+ */ /* Created: 2025/03/21 15:59:16 by whaffman #+# #+# */ -/* Updated: 2025/03/21 16:02:56 by whaffman ######## odam.nl */ +/* Updated: 2025/04/02 10:48:14 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ #include "Zombie.hpp" -Zombie* zombieHorde( int N, std::string name ) +Zombie* Zombie::zombieHorde( int N, std::string name ) { Zombie* horde = new Zombie[N]; for (int i = 0; i < N; i++) diff --git a/ex03/inc/HumanA.hpp b/ex03/inc/HumanA.hpp index 1f55cfa..f7accfc 100644 --- a/ex03/inc/HumanA.hpp +++ b/ex03/inc/HumanA.hpp @@ -6,7 +6,7 @@ /* By: whaffman +#+ */ /* +#+ */ /* Created: 2025/03/21 16:28:57 by whaffman #+# #+# */ -/* Updated: 2025/03/21 16:57:56 by whaffman ######## odam.nl */ +/* Updated: 2025/04/02 10:56:49 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ @@ -17,10 +17,10 @@ class HumanA { private: std::string name; - Weapon *weapon; + Weapon &weapon; HumanA(); public: HumanA(std::string p_name, Weapon &p_weapon); - void attack(); + void attack(); }; \ No newline at end of file diff --git a/ex03/inc/HumanB.hpp b/ex03/inc/HumanB.hpp index e48de70..cc15f8e 100644 --- a/ex03/inc/HumanB.hpp +++ b/ex03/inc/HumanB.hpp @@ -6,11 +6,11 @@ class HumanB { private: std::string name; - Weapon *weapon; + Weapon *weapon; HumanB(); public: HumanB(std::string p_name); - void attack(); - void setWeapon(Weapon &p_weapon); + void attack(); + void setWeapon(Weapon &p_weapon); }; \ No newline at end of file diff --git a/ex03/inc/Weapon.hpp b/ex03/inc/Weapon.hpp index a53c633..894ca7e 100644 --- a/ex03/inc/Weapon.hpp +++ b/ex03/inc/Weapon.hpp @@ -20,7 +20,7 @@ public: Weapon(); Weapon(std::string p_type); ~Weapon(); - const std::string & getType(); + const std::string &getType(); void setType(std::string p_type); private: diff --git a/ex03/src/HumanA.cpp b/ex03/src/HumanA.cpp index e6eba99..8667508 100644 --- a/ex03/src/HumanA.cpp +++ b/ex03/src/HumanA.cpp @@ -6,26 +6,19 @@ /* By: whaffman +#+ */ /* +#+ */ /* Created: 2025/03/21 16:48:35 by whaffman #+# #+# */ -/* Updated: 2025/03/21 16:58:14 by whaffman ######## odam.nl */ +/* Updated: 2025/04/02 10:57:31 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ - #include #include #include "Weapon.hpp" #include "HumanA.hpp" - -HumanA::HumanA(std::string p_name, Weapon &p_weapon) +HumanA::HumanA(std::string p_name, Weapon &p_weapon) : name(p_name), weapon(p_weapon) { - name = p_name; - weapon = &p_weapon; } -void HumanA::attack() +void HumanA::attack() { - std::cout << name << " attacks with " << (*weapon).getType() << std::endl; + std::cout << name << " attacks with " << (weapon).getType() << std::endl; } - - - diff --git a/ex03/src/main.cpp b/ex03/src/main.cpp index ff832b2..f789d72 100644 --- a/ex03/src/main.cpp +++ b/ex03/src/main.cpp @@ -6,7 +6,7 @@ /* By: whaffman +#+ */ /* +#+ */ /* Created: 2025/03/21 16:21:48 by whaffman #+# #+# */ -/* Updated: 2025/03/21 16:29:32 by whaffman ######## odam.nl */ +/* Updated: 2025/04/02 11:14:23 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ @@ -17,18 +17,18 @@ int main() { { - Weapon club = Weapon("crude spiked club"); + Weapon club = Weapon("a banana"); HumanA bob("Bob", club); bob.attack(); - club.setType("some other type of club"); + club.setType("two pears on a string"); bob.attack(); } { - Weapon club = Weapon("crude spiked club"); + Weapon club = Weapon("a poisended apple"); HumanB jim("Jim"); jim.setWeapon(club); jim.attack(); - club.setType("some other type of club"); + club.setType("slippery jelly"); jim.attack(); } return 0; diff --git a/ex04/src/main.cpp b/ex04/src/main.cpp index 0deda4a..36dd0e9 100644 --- a/ex04/src/main.cpp +++ b/ex04/src/main.cpp @@ -6,7 +6,7 @@ /* By: whaffman +#+ */ /* +#+ */ /* Created: 2025/03/23 13:59:46 by whaffman #+# #+# */ -/* Updated: 2025/03/23 14:28:19 by whaffman ######## odam.nl */ +/* Updated: 2025/04/02 11:20:09 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ @@ -22,26 +22,35 @@ int main(int argc, char *argv[]) std::fstream outFile; std::string outFileName; std::string line; - + if (argc != 4) + { std::cout << "Usage: ./Replacer " << std::endl; - + return 1; + } + inFile.open(argv[1], std::ios::in); if (!inFile.is_open()) + { std::cout << "Can't open In file" << std::endl; - + return 1; + } + outFileName = argv[1]; outFileName += ".replace"; outFile.open(outFileName, std::ios::out); if (!outFile.is_open()) + { std::cout << "Can't open OUT file" << std::endl; + inFile.close(); + return 1; + } + Replacer replacer(argv[2], argv[3]); - Replacer replacer(argv[2], argv[3]); - - while(std::getline(inFile, line)) + while (std::getline(inFile, line)) { outFile << replacer.process(line); if (!inFile.eof()) outFile << std::endl; - } + } } \ No newline at end of file diff --git a/ex05/inc/Harl.hpp b/ex05/inc/Harl.hpp index 25329eb..70ce8c7 100644 --- a/ex05/inc/Harl.hpp +++ b/ex05/inc/Harl.hpp @@ -6,23 +6,24 @@ /* By: whaffman +#+ */ /* +#+ */ /* Created: 2025/03/23 15:06:27 by whaffman #+# #+# */ -/* Updated: 2025/03/23 15:35:07 by whaffman ######## odam.nl */ +/* Updated: 2025/04/02 11:26:20 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ #include -class Harl +class Harl { - private: - std::string levels[4]; - void (Harl::*levelFunc[4])(); - void info(); - void debug(); - void warning(); - void error(); - public: - Harl(); - ~Harl(); - void complain(std::string level); - }; \ No newline at end of file +private: + static std::string levels[4]; + static void (Harl::*levelFunc[4])(); + void info(); + void debug(); + void warning(); + void error(); + +public: + Harl(); + ~Harl(); + void complain(std::string level); +}; \ No newline at end of file diff --git a/ex05/src/Harl.cpp b/ex05/src/Harl.cpp index c40456b..9f01cbe 100644 --- a/ex05/src/Harl.cpp +++ b/ex05/src/Harl.cpp @@ -6,46 +6,41 @@ /* By: whaffman +#+ */ /* +#+ */ /* Created: 2025/03/23 15:09:28 by whaffman #+# #+# */ -/* Updated: 2025/03/23 15:44:03 by whaffman ######## odam.nl */ +/* Updated: 2025/04/02 12:27:45 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ #include "Harl.hpp" +std::string Harl::levels[4] = {"DEBUG", "INFO", "WARNING", "ERROR"}; +void (Harl::*Harl::levelFunc[4])() = {&Harl::debug, &Harl::info, &Harl::warning, &Harl::error}; + Harl::Harl() { - levels[0] = "DEBUG"; - levels[1] = "INFO"; - levels[2] = "WARNING"; - levels[3] = "ERROR"; - levelFunc[0] = &Harl::debug; - levelFunc[1] = &Harl::info; - levelFunc[2] = &Harl::warning; - levelFunc[3] = &Harl::error; } Harl::~Harl() {} void Harl::debug() { std::cout << "[DEBUG]" << std::endl; - std::cout << "I love having extra bacon for my 7XL-double-cheese-triple-pickle-special-ketchup burger. I really do!" << std::endl; + std::cout << "I put butter in the pan, to fry an egg." << std::endl; } void Harl::info() { std::cout << "[INFO]" << std::endl; - std::cout << "I cannot believe adding extra bacon costs more money. You didn’t put enough bacon in my burger! If you did, I wouldn’t be asking for more!" << std::endl; + std::cout << "Tiny bubbles are appearing, the butter is Hot" << std::endl; } void Harl::warning() { std::cout << "[WARNING]" << std::endl; - std::cout << "I think I deserve to have some extra bacon for free. I’ve been coming for years, whereas you started working here just last month." << std::endl; + std::cout << "The butter turns brown, It's really time to put in the eggs" << std::endl; } void Harl::error() { std::cout << "[ERROR]" << std::endl; - std::cout << "This is unacceptable! I want to speak to the manager now." << std::endl; + std::cout << "Too late, your house is on fire!" << std::endl; } void Harl::complain(std::string level) @@ -55,8 +50,8 @@ void Harl::complain(std::string level) if (level == levels[i]) { (this->*levelFunc[i])(); - return ; + return; } } - std::cout << "I don't know anymorre what to complain about" << std::endl; + std::cout << "I don't know anymore what to complain about" << std::endl; } \ No newline at end of file diff --git a/ex05/src/main.cpp b/ex05/src/main.cpp index 63bbb77..a9ab77d 100644 --- a/ex05/src/main.cpp +++ b/ex05/src/main.cpp @@ -6,7 +6,7 @@ /* By: whaffman +#+ */ /* +#+ */ /* Created: 2025/03/23 15:38:32 by whaffman #+# #+# */ -/* Updated: 2025/03/23 15:44:11 by whaffman ######## odam.nl */ +/* Updated: 2025/04/02 12:29:34 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ diff --git a/ex06/inc/Harl.hpp b/ex06/inc/Harl.hpp index a857e4b..e3064e4 100644 --- a/ex06/inc/Harl.hpp +++ b/ex06/inc/Harl.hpp @@ -6,7 +6,7 @@ /* By: whaffman +#+ */ /* +#+ */ /* Created: 2025/03/23 15:06:27 by whaffman #+# #+# */ -/* Updated: 2025/03/24 14:29:54 by whaffman ######## odam.nl */ +/* Updated: 2025/04/02 12:20:49 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ @@ -14,15 +14,19 @@ class Harl { - private: - std::string levels[4]; - void (Harl::*levelFunc[4])(); - void info(); - void debug(); - void warning(); - void error(); - public: - Harl(); - ~Harl(); - void complain(std::string level); - }; \ No newline at end of file +private: + static std::string levels[4]; + static void (Harl::*levelFunc[4])(); + void info(); + void debug(); + void warning(); + void error(); + + +public: + Harl(); + ~Harl(); + void complain(std::string level); + std::string getLevel(int i); + +}; \ No newline at end of file diff --git a/ex06/src/Harl.cpp b/ex06/src/Harl.cpp index c40456b..3c32719 100644 --- a/ex06/src/Harl.cpp +++ b/ex06/src/Harl.cpp @@ -6,46 +6,45 @@ /* By: whaffman +#+ */ /* +#+ */ /* Created: 2025/03/23 15:09:28 by whaffman #+# #+# */ -/* Updated: 2025/03/23 15:44:03 by whaffman ######## odam.nl */ +/* Updated: 2025/04/02 12:26:34 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ #include "Harl.hpp" +#include + + + +std::string Harl::levels[4] = {"DEBUG", "INFO", "WARNING", "ERROR"}; +void (Harl::*Harl::levelFunc[4])() = {&Harl::debug, &Harl::info, &Harl::warning, &Harl::error}; + Harl::Harl() { - levels[0] = "DEBUG"; - levels[1] = "INFO"; - levels[2] = "WARNING"; - levels[3] = "ERROR"; - levelFunc[0] = &Harl::debug; - levelFunc[1] = &Harl::info; - levelFunc[2] = &Harl::warning; - levelFunc[3] = &Harl::error; } Harl::~Harl() {} void Harl::debug() { std::cout << "[DEBUG]" << std::endl; - std::cout << "I love having extra bacon for my 7XL-double-cheese-triple-pickle-special-ketchup burger. I really do!" << std::endl; + std::cout << "I put butter in the pan, to fry an egg." << std::endl; } void Harl::info() { std::cout << "[INFO]" << std::endl; - std::cout << "I cannot believe adding extra bacon costs more money. You didn’t put enough bacon in my burger! If you did, I wouldn’t be asking for more!" << std::endl; + std::cout << "Tiny bubbles are appearing, the butter is Hot" << std::endl; } void Harl::warning() { std::cout << "[WARNING]" << std::endl; - std::cout << "I think I deserve to have some extra bacon for free. I’ve been coming for years, whereas you started working here just last month." << std::endl; + std::cout << "The butter turns brown, It's really time to put in the eggs" << std::endl; } void Harl::error() { std::cout << "[ERROR]" << std::endl; - std::cout << "This is unacceptable! I want to speak to the manager now." << std::endl; + std::cout << "Too late, your house is on fire!" << std::endl; } void Harl::complain(std::string level) @@ -59,4 +58,11 @@ void Harl::complain(std::string level) } } std::cout << "I don't know anymorre what to complain about" << std::endl; +} + +std::string Harl::getLevel(int i) +{ + if (i < 0 || i > 3) + return (""); + return (levels[i]); } \ No newline at end of file diff --git a/ex06/src/main.cpp b/ex06/src/main.cpp index 43ee75a..0eab284 100644 --- a/ex06/src/main.cpp +++ b/ex06/src/main.cpp @@ -6,7 +6,7 @@ /* By: whaffman +#+ */ /* +#+ */ /* Created: 2025/03/24 14:30:26 by whaffman #+# #+# */ -/* Updated: 2025/03/24 14:40:35 by whaffman ######## odam.nl */ +/* Updated: 2025/04/02 12:24:34 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ @@ -14,7 +14,6 @@ int main(int argc, char **argv) { - const std::string levels[4] = {"DEBUG", "INFO", "WARNING", "ERROR"}; Harl harl; int i; @@ -26,7 +25,7 @@ int main(int argc, char **argv) for (i = 0; i < 4; i++) { - if (argv[1] == levels[i]) + if (argv[1] == harl.getLevel(i)) { break; } @@ -34,17 +33,17 @@ int main(int argc, char **argv) switch (i) { - case 3: - harl.complain("ERROR"); - case 2: - harl.complain("WARNING"); - case 1: - harl.complain("INFO"); case 0: harl.complain("DEBUG"); + case 1: + harl.complain("INFO"); + case 2: + harl.complain("WARNING"); + case 3: + harl.complain("ERROR"); break; default: - std::cout << "[Probably complaining about insignificant problem]" << std::endl; + std::cout << "[Please only complain for real problems!]" << std::endl; break; } return (0);