aboutsummaryrefslogtreecommitdiff
path: root/cpp04/ex00
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2020-04-14 18:02:14 +0200
committerCharles <sircharlesaze@gmail.com>2020-04-14 18:02:14 +0200
commitefea8712aaf8169b1184cceb83705ca6b8783173 (patch)
tree3c682f6af9d5877ddfa1740f4bac10f5f5123ddc /cpp04/ex00
parent119f7f96e77a2d86d692e82645dde4c2dc054052 (diff)
downloadpiscine_cpp-efea8712aaf8169b1184cceb83705ca6b8783173.tar.gz
piscine_cpp-efea8712aaf8169b1184cceb83705ca6b8783173.tar.bz2
piscine_cpp-efea8712aaf8169b1184cceb83705ca6b8783173.zip
cpp04, ex03 not finished, require more sophisticated main
Diffstat (limited to 'cpp04/ex00')
-rw-r--r--cpp04/ex00/Peon.cpp39
-rw-r--r--cpp04/ex00/Peon.hpp34
-rw-r--r--cpp04/ex00/Sorcerer.cpp63
-rw-r--r--cpp04/ex00/Sorcerer.hpp41
-rw-r--r--cpp04/ex00/Victim.cpp54
-rw-r--r--cpp04/ex00/Victim.hpp39
-rw-r--r--cpp04/ex00/main.cpp30
7 files changed, 300 insertions, 0 deletions
diff --git a/cpp04/ex00/Peon.cpp b/cpp04/ex00/Peon.cpp
new file mode 100644
index 0000000..df55b4f
--- /dev/null
+++ b/cpp04/ex00/Peon.cpp
@@ -0,0 +1,39 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* Peon.cpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/13 20:53:16 by charles #+# #+# */
+/* Updated: 2020/04/13 21:00:23 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "Peon.hpp"
+
+Peon::Peon(std::string name):
+ Victim(name)
+{
+ std::cout << "Zog zog." << std::endl;
+}
+
+void Peon::operator=(Peon const& other)
+{
+ m_name = other.m_name;
+}
+
+Peon::Peon(Peon const& other)
+ : Victim(other)
+{
+}
+
+Peon::~Peon()
+{
+ std::cout << "Bleuark..." << std::endl;
+}
+
+void Peon::getPolymorphed() const
+{
+ std::cout << m_name << " has been turned into a pink pony!" << std::endl;
+}
diff --git a/cpp04/ex00/Peon.hpp b/cpp04/ex00/Peon.hpp
new file mode 100644
index 0000000..2d57a05
--- /dev/null
+++ b/cpp04/ex00/Peon.hpp
@@ -0,0 +1,34 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* Peon.hpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/13 20:50:54 by charles #+# #+# */
+/* Updated: 2020/04/13 20:57:37 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef PEON_HPP
+# define PEON_HPP
+
+# include <string>
+# include <iostream>
+# include "Victim.hpp"
+
+class Peon : public Victim
+{
+public:
+ Peon(std::string name);
+ void operator=(Peon const& other);
+ Peon(Peon const& other);
+ ~Peon();
+
+ virtual void getPolymorphed() const;
+
+private:
+ Peon();
+};
+
+#endif
diff --git a/cpp04/ex00/Sorcerer.cpp b/cpp04/ex00/Sorcerer.cpp
new file mode 100644
index 0000000..c6910ce
--- /dev/null
+++ b/cpp04/ex00/Sorcerer.cpp
@@ -0,0 +1,63 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* Sorcerer.cpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/13 20:29:19 by charles #+# #+# */
+/* Updated: 2020/04/13 20:49:48 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "Sorcerer.hpp"
+
+Sorcerer::Sorcerer(std::string name, std::string title):
+ m_name(name),
+ m_title(title)
+{
+ std::cout << name << ", " << title << ", is born!" << std::endl;
+}
+
+void Sorcerer::operator=(Sorcerer const& other)
+{
+ m_name = other.m_name;
+ m_title = other.m_title;
+}
+
+Sorcerer::Sorcerer(Sorcerer const& other)
+{
+ *this = other;
+}
+
+Sorcerer::~Sorcerer()
+{
+ std::cout << m_name << ", " << m_title
+ << ", is dead. Consequences will never be the same!" << std::endl;
+}
+
+std::string const& Sorcerer::getName() const
+{
+ return m_name;
+}
+
+std::string const& Sorcerer::getTitle() const
+{
+ return m_title;
+}
+
+void Sorcerer::polymorph(Victim const& v) const
+{
+ v.getPolymorphed();
+}
+
+Sorcerer::Sorcerer()
+{
+}
+
+std::ostream& operator<<(std::ostream& out, Sorcerer const& s)
+{
+ out << "I am " << s.getName() << ", " << s.getTitle()
+ << ", and I like ponies!" << std::endl;
+ return out;
+}
diff --git a/cpp04/ex00/Sorcerer.hpp b/cpp04/ex00/Sorcerer.hpp
new file mode 100644
index 0000000..ed261ae
--- /dev/null
+++ b/cpp04/ex00/Sorcerer.hpp
@@ -0,0 +1,41 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* Sorcerer.hpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/13 20:27:26 by charles #+# #+# */
+/* Updated: 2020/04/13 20:58:46 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef SORCERER_HPP
+# define SORCERER_HPP
+
+# include <string>
+# include <iostream>
+# include "Victim.hpp"
+
+class Sorcerer
+{
+public:
+ Sorcerer(std::string name, std::string title);
+ void operator=(Sorcerer const& other);
+ Sorcerer(Sorcerer const& other);
+ ~Sorcerer();
+
+ std::string const& getName() const;
+ std::string const& getTitle() const;
+ void polymorph(Victim const& v) const;
+
+private:
+ Sorcerer();
+
+ std::string m_name;
+ std::string m_title;
+};
+
+std::ostream& operator<<(std::ostream& out, Sorcerer const& s);
+
+#endif
diff --git a/cpp04/ex00/Victim.cpp b/cpp04/ex00/Victim.cpp
new file mode 100644
index 0000000..2f2f6ad
--- /dev/null
+++ b/cpp04/ex00/Victim.cpp
@@ -0,0 +1,54 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* Victim.cpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/13 20:42:22 by charles #+# #+# */
+/* Updated: 2020/04/13 20:59:51 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "Victim.hpp"
+
+Victim::Victim(std::string name) :
+ m_name(name)
+{
+ std::cout << "Some random victim called " << name << " just appeared!" << std::endl;
+}
+
+void Victim::operator=(Victim const& other)
+{
+ m_name = other.m_name;
+}
+
+Victim::Victim(Victim const& other)
+{
+ *this = other;
+}
+
+Victim::~Victim()
+{
+ std::cout << "Victim " << m_name << " just died for no apparent reason!" << std::endl;
+}
+
+std::string const& Victim::getName() const
+{
+ return m_name;
+}
+
+void Victim::getPolymorphed() const
+{
+ std::cout << m_name << " has been turned into a cute little sheep!" << std::endl;
+}
+
+Victim::Victim()
+{
+}
+
+std::ostream& operator<<(std::ostream& out, Victim const& v)
+{
+ out << "I'm " << v.getName() << " and I like otters!" << std::endl;
+ return out;
+}
diff --git a/cpp04/ex00/Victim.hpp b/cpp04/ex00/Victim.hpp
new file mode 100644
index 0000000..dafd8c6
--- /dev/null
+++ b/cpp04/ex00/Victim.hpp
@@ -0,0 +1,39 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* Victim.hpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/13 20:40:50 by charles #+# #+# */
+/* Updated: 2020/04/13 20:59:08 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef VICTIM_HPP
+# define VICTIM_HPP
+
+# include <string>
+# include <iostream>
+
+class Victim
+{
+public:
+ Victim(std::string name);
+ void operator=(Victim const& other);
+ Victim(Victim const& other);
+ ~Victim();
+
+ std::string const& getName() const;
+ virtual void getPolymorphed() const;
+
+protected:
+ std::string m_name;
+
+private:
+ Victim();
+};
+
+std::ostream& operator<<(std::ostream& out, Victim const& v);
+
+#endif
diff --git a/cpp04/ex00/main.cpp b/cpp04/ex00/main.cpp
new file mode 100644
index 0000000..9c17e99
--- /dev/null
+++ b/cpp04/ex00/main.cpp
@@ -0,0 +1,30 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* main.cpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/13 20:47:34 by charles #+# #+# */
+/* Updated: 2020/04/13 20:57:19 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "Sorcerer.hpp"
+#include "Victim.hpp"
+#include "Peon.hpp"
+
+int main()
+{
+ Sorcerer robert("Robert", "the Magnificent");
+
+ Victim jim("Jimmy");
+ Peon joe("Joe");
+
+ std::cout << robert << jim << joe;
+
+ robert.polymorph(jim);
+ robert.polymorph(joe);
+
+ return 0;
+}