Add solution to ex00 (except the Makefile)
authorLukas Jiriste <ljiriste@student.42prague.com>
Thu, 10 Oct 2024 09:16:32 +0000 (11:16 +0200)
committerLukas Jiriste <ljiriste@student.42prague.com>
Thu, 10 Oct 2024 09:16:32 +0000 (11:16 +0200)
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.

ex00/Zombie.cpp [new file with mode: 0644]
ex00/Zombie.h [new file with mode: 0644]
ex00/main.cpp [new file with mode: 0644]
ex00/newZombie.cpp [new file with mode: 0644]
ex00/randomChump.cpp [new file with mode: 0644]

diff --git a/ex00/Zombie.cpp b/ex00/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/ex00/Zombie.h b/ex00/Zombie.h
new file mode 100644 (file)
index 0000000..99a0b6e
--- /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 &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 (file)
index 0000000..51f2d40
--- /dev/null
@@ -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 (file)
index 0000000..df75a88
--- /dev/null
@@ -0,0 +1,8 @@
+#include "Zombie.h"
+#include <string>
+
+Zombie *newZombie(std::string name)
+{
+       return (new Zombie(name));
+}
+
diff --git a/ex00/randomChump.cpp b/ex00/randomChump.cpp
new file mode 100644 (file)
index 0000000..1038be2
--- /dev/null
@@ -0,0 +1,9 @@
+#include "Zombie.h"
+#include <string>
+
+void   randomChump(std::string name)
+{
+       Zombie  chump(name);
+
+       chump.announce();
+}