From: Lukas Jiriste Date: Thu, 10 Oct 2024 09:16:32 +0000 (+0200) Subject: Add solution to ex00 (except the Makefile) X-Git-Url: https://git.ljiriste.work/?a=commitdiff_plain;h=64c1a716cc17c525755a98175be3cd04e0013659;p=42%2FCPP_Module_01 Add solution to ex00 (except the Makefile) The Makefile will be added later, because I'm too lazy to write it again, when there is a one for the CPP Module 00 already. It is just on another PC, from which I had not pushed yet. --- 64c1a716cc17c525755a98175be3cd04e0013659 diff --git a/ex00/Zombie.cpp b/ex00/Zombie.cpp new file mode 100644 index 0000000..714287b --- /dev/null +++ b/ex00/Zombie.cpp @@ -0,0 +1,28 @@ +#include "Zombie.h" +#include +#include + +Zombie::Zombie(std::string name): m_name(name) +{ +} + +Zombie &Zombie::operator=(const Zombie &zombie) +{ + m_name = zombie.m_name; + return (*this); +} + +Zombie::Zombie(const Zombie &zombie) +{ + *this = zombie; +} + +Zombie::~Zombie(void) +{ + std::cout << m_name << " is being deconstructed\n"; +} + +void Zombie::announce(void) +{ + std::cout << m_name << ": BraiiiiiiinnnzzzZ...\n"; +} diff --git a/ex00/Zombie.h b/ex00/Zombie.h new file mode 100644 index 0000000..99a0b6e --- /dev/null +++ b/ex00/Zombie.h @@ -0,0 +1,20 @@ +#ifndef ZOMBIE_H +# define ZOMBIE_H + +# include + +class Zombie +{ + private: + std::string m_name; + + public: + Zombie(std::string name); + Zombie &operator=(const Zombie &zombie); + Zombie(const Zombie &zombie); + ~Zombie(); + + void announce(void); +}; + +#endif // ZOMBIE_H diff --git a/ex00/main.cpp b/ex00/main.cpp new file mode 100644 index 0000000..51f2d40 --- /dev/null +++ b/ex00/main.cpp @@ -0,0 +1,18 @@ +#include "Zombie.h" + + +Zombie *newZombie(std::string name); +void randomChump(std::string name); + +int main(void) +{ + Zombie zombie("Edd"); + Zombie *zombie_p; + + zombie_p = newZombie("Ed"); + zombie_p->announce(); + zombie.announce(); + randomChump("Eddy"); + delete zombie_p; + return (0); +} diff --git a/ex00/newZombie.cpp b/ex00/newZombie.cpp new file mode 100644 index 0000000..df75a88 --- /dev/null +++ b/ex00/newZombie.cpp @@ -0,0 +1,8 @@ +#include "Zombie.h" +#include + +Zombie *newZombie(std::string name) +{ + return (new Zombie(name)); +} + diff --git a/ex00/randomChump.cpp b/ex00/randomChump.cpp new file mode 100644 index 0000000..1038be2 --- /dev/null +++ b/ex00/randomChump.cpp @@ -0,0 +1,9 @@ +#include "Zombie.h" +#include + +void randomChump(std::string name) +{ + Zombie chump(name); + + chump.announce(); +}