better
This commit is contained in:
parent
e857218775
commit
0700c0e42b
@ -6,7 +6,7 @@
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* 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 );
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* 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);
|
||||
}
|
||||
@ -6,13 +6,13 @@
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* 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);
|
||||
|
||||
@ -6,13 +6,13 @@
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* 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();
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* 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 );
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* 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();
|
||||
|
||||
@ -6,13 +6,13 @@
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* 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++)
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* 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,7 +17,7 @@ class HumanA
|
||||
{
|
||||
private:
|
||||
std::string name;
|
||||
Weapon *weapon;
|
||||
Weapon &weapon;
|
||||
HumanA();
|
||||
|
||||
public:
|
||||
|
||||
@ -6,26 +6,19 @@
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* 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 <string>
|
||||
#include <iostream>
|
||||
#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()
|
||||
{
|
||||
std::cout << name << " attacks with " << (*weapon).getType() << std::endl;
|
||||
std::cout << name << " attacks with " << (weapon).getType() << std::endl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* 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;
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* 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 */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -24,18 +24,27 @@ int main(int argc, char *argv[])
|
||||
std::string line;
|
||||
|
||||
if (argc != 4)
|
||||
{
|
||||
std::cout << "Usage: ./Replacer <filename> <old string> <new string>" << 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]);
|
||||
|
||||
while (std::getline(inFile, line))
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* 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 */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -15,12 +15,13 @@
|
||||
class Harl
|
||||
{
|
||||
private:
|
||||
std::string levels[4];
|
||||
void (Harl::*levelFunc[4])();
|
||||
static std::string levels[4];
|
||||
static void (Harl::*levelFunc[4])();
|
||||
void info();
|
||||
void debug();
|
||||
void warning();
|
||||
void error();
|
||||
|
||||
public:
|
||||
Harl();
|
||||
~Harl();
|
||||
|
||||
@ -6,46 +6,41 @@
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* 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)
|
||||
@ -58,5 +53,5 @@ void Harl::complain(std::string level)
|
||||
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;
|
||||
}
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* 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 */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* 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 */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -15,14 +15,18 @@
|
||||
class Harl
|
||||
{
|
||||
private:
|
||||
std::string levels[4];
|
||||
void (Harl::*levelFunc[4])();
|
||||
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);
|
||||
|
||||
};
|
||||
@ -6,46 +6,45 @@
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* 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 <iostream>
|
||||
|
||||
|
||||
|
||||
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)
|
||||
@ -60,3 +59,10 @@ 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]);
|
||||
}
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* 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);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user