From: Lukas Jiriste Date: Thu, 10 Oct 2024 10:08:36 +0000 (+0200) Subject: Add solution to ex01 without Makefile X-Git-Url: https://git.ljiriste.work/?a=commitdiff_plain;h=5fc2da08dd9fdaf78b843185fe3725ecde7eb543;p=42%2FCPP_Module_01 Add solution to ex01 without Makefile --- diff --git a/ex01/Zombie.cpp b/ex01/Zombie.cpp new file mode 100644 index 0000000..714287b --- /dev/null +++ b/ex01/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/ex01/Zombie.h b/ex01/Zombie.h new file mode 100644 index 0000000..243bd47 --- /dev/null +++ b/ex01/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"); + Zombie &operator=(const Zombie &zombie); + Zombie(const Zombie &zombie); + ~Zombie(); + + void announce(void); +}; + +#endif // ZOMBIE_H diff --git a/ex01/main.cpp b/ex01/main.cpp new file mode 100644 index 0000000..bd7ffb1 --- /dev/null +++ b/ex01/main.cpp @@ -0,0 +1,17 @@ +#include "Zombie.h" + + +Zombie *zombieHorde(int n, std::string name); + +int main(void) +{ + Zombie *zombie_arr; + size_t n; + + n = 10; + zombie_arr = zombieHorde(n, "Ed"); + for (size_t i(0); i < n; ++i) + zombie_arr[i].announce(); + delete[] zombie_arr; + return (0); +} diff --git a/ex01/zombieHorde.cpp b/ex01/zombieHorde.cpp new file mode 100644 index 0000000..96ce5d3 --- /dev/null +++ b/ex01/zombieHorde.cpp @@ -0,0 +1,15 @@ +#include "Zombie.h" +#include + +Zombie *zombieHorde(int n, std::string name) +{ + Zombie temp(name); + Zombie *array; + + array = new Zombie[n]; + if (array == NULL) + return (NULL); + for (int i(0); i < n; ++i) + array[i] = temp; + return (array); +}