Add solution to ex01 without Makefile
authorLukas Jiriste <ljiriste@student.42prague.com>
Thu, 10 Oct 2024 10:08:36 +0000 (12:08 +0200)
committerLukas Jiriste <ljiriste@student.42prague.com>
Thu, 10 Oct 2024 10:08:36 +0000 (12:08 +0200)
ex01/Zombie.cpp [new file with mode: 0644]
ex01/Zombie.h [new file with mode: 0644]
ex01/main.cpp [new file with mode: 0644]
ex01/zombieHorde.cpp [new file with mode: 0644]

diff --git a/ex01/Zombie.cpp b/ex01/Zombie.cpp
new file mode 100644 (file)
index 0000000..714287b
--- /dev/null
@@ -0,0 +1,28 @@
+#include "Zombie.h"
+#include <iostream>
+#include <string>
+
+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 (file)
index 0000000..243bd47
--- /dev/null
@@ -0,0 +1,20 @@
+#ifndef ZOMBIE_H
+# define ZOMBIE_H
+
+# include <string>
+
+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 (file)
index 0000000..bd7ffb1
--- /dev/null
@@ -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 (file)
index 0000000..96ce5d3
--- /dev/null
@@ -0,0 +1,15 @@
+#include "Zombie.h"
+#include <string>
+
+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);
+}