From 7d6a4c877de8048ec5fbea4a563b3d09c8976105 Mon Sep 17 00:00:00 2001 From: Charles Date: Sun, 12 Jan 2020 20:20:12 +0100 Subject: cpp01 00 -> 04 --- cpp01/ex00/Pony.cpp | 20 ++++++++++++++++++++ cpp01/ex00/Pony.hpp | 15 +++++++++++++++ cpp01/ex00/main.cpp | 24 ++++++++++++++++++++++++ cpp01/ex01/ex01.cpp | 8 ++++++++ cpp01/ex02/Zombie.cpp | 14 ++++++++++++++ cpp01/ex02/Zombie.hpp | 17 +++++++++++++++++ cpp01/ex02/ZombieEvent.cpp | 29 +++++++++++++++++++++++++++++ cpp01/ex02/ZombieEvent.hpp | 18 ++++++++++++++++++ cpp01/ex02/main.cpp | 20 ++++++++++++++++++++ cpp01/ex03/Zombie.cpp | 14 ++++++++++++++ cpp01/ex03/Zombie.hpp | 17 +++++++++++++++++ cpp01/ex03/ZombieHorde.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ cpp01/ex03/ZombieHorde.hpp | 18 ++++++++++++++++++ cpp01/ex03/main.cpp | 15 +++++++++++++++ cpp01/ex04/ex04.cpp | 13 +++++++++++++ subjects/cpp00.en.pdf | Bin 0 -> 1378557 bytes subjects/cpp00.pdf | Bin 1378557 -> 0 bytes subjects/cpp01.en.pdf | Bin 0 -> 1407857 bytes 18 files changed, 283 insertions(+) create mode 100644 cpp01/ex00/Pony.cpp create mode 100644 cpp01/ex00/Pony.hpp create mode 100644 cpp01/ex00/main.cpp create mode 100644 cpp01/ex01/ex01.cpp create mode 100644 cpp01/ex02/Zombie.cpp create mode 100644 cpp01/ex02/Zombie.hpp create mode 100644 cpp01/ex02/ZombieEvent.cpp create mode 100644 cpp01/ex02/ZombieEvent.hpp create mode 100644 cpp01/ex02/main.cpp create mode 100644 cpp01/ex03/Zombie.cpp create mode 100644 cpp01/ex03/Zombie.hpp create mode 100644 cpp01/ex03/ZombieHorde.cpp create mode 100644 cpp01/ex03/ZombieHorde.hpp create mode 100644 cpp01/ex03/main.cpp create mode 100644 cpp01/ex04/ex04.cpp create mode 100644 subjects/cpp00.en.pdf delete mode 100644 subjects/cpp00.pdf create mode 100644 subjects/cpp01.en.pdf diff --git a/cpp01/ex00/Pony.cpp b/cpp01/ex00/Pony.cpp new file mode 100644 index 0000000..f521d4b --- /dev/null +++ b/cpp01/ex00/Pony.cpp @@ -0,0 +1,20 @@ +#include +#include "Pony.hpp" + +Pony::Pony(int w, int s) +{ + weight = w; + max_speed = s; +} + +void Pony::say_hello() +{ + std::cout << "Hi, I'm a pony, I weight " << weight + << " and my speed limit is " << max_speed << std::endl; +} + +void Pony::run() +{ + for (int i = 0; i < max_speed; i++) + std::cout << "I'm running really fast at " << i << ", look at me!" << std::endl; +} diff --git a/cpp01/ex00/Pony.hpp b/cpp01/ex00/Pony.hpp new file mode 100644 index 0000000..31a69f4 --- /dev/null +++ b/cpp01/ex00/Pony.hpp @@ -0,0 +1,15 @@ +#ifndef PONY_HPP +# define PONY_HPP + +class Pony +{ + public: + Pony(int w, int s); + void say_hello(); + void run(); + private: + int weight; + int max_speed; +}; + +#endif diff --git a/cpp01/ex00/main.cpp b/cpp01/ex00/main.cpp new file mode 100644 index 0000000..c8aa0b8 --- /dev/null +++ b/cpp01/ex00/main.cpp @@ -0,0 +1,24 @@ +#include +#include "Pony.hpp" + +void ponyOnTheHeap() +{ + Pony *p = new Pony(200, 100); + p->say_hello(); + p->run(); + delete p; +} + +void ponyOnTheStack() +{ + Pony p(200, 100); + p.say_hello(); + p.run(); +} + +int main() +{ + ponyOnTheHeap(); + ponyOnTheStack(); + return 0; +} diff --git a/cpp01/ex01/ex01.cpp b/cpp01/ex01/ex01.cpp new file mode 100644 index 0000000..c08e1d2 --- /dev/null +++ b/cpp01/ex01/ex01.cpp @@ -0,0 +1,8 @@ +#include + +void memoryLeak() +{ + std::string* panthere = new std::string("String panthere"); + std::cout << *panthere << std::endl; + delete panthere; +} diff --git a/cpp01/ex02/Zombie.cpp b/cpp01/ex02/Zombie.cpp new file mode 100644 index 0000000..2ea23b6 --- /dev/null +++ b/cpp01/ex02/Zombie.cpp @@ -0,0 +1,14 @@ +#include +#include "Zombie.hpp" + +Zombie::Zombie(std::string n, std::string t) +{ + name = n; + type = t; + announce(); +} + +void Zombie::announce() +{ + std::cout << "<" << name << " (" << type << ")> Braiiiiiiinnnssss..." << std::endl; +} diff --git a/cpp01/ex02/Zombie.hpp b/cpp01/ex02/Zombie.hpp new file mode 100644 index 0000000..980ea49 --- /dev/null +++ b/cpp01/ex02/Zombie.hpp @@ -0,0 +1,17 @@ +#ifndef ZOMBIE_HPP +# define ZOMBIE_HPP + +#include + +class Zombie +{ + public: + Zombie(std::string n, std::string t); + void announce(); + + private: + std::string name; + std::string type; +}; + +#endif diff --git a/cpp01/ex02/ZombieEvent.cpp b/cpp01/ex02/ZombieEvent.cpp new file mode 100644 index 0000000..6775138 --- /dev/null +++ b/cpp01/ex02/ZombieEvent.cpp @@ -0,0 +1,29 @@ +#include +#include "ZombieEvent.hpp" + +void ZombieEvent::setZombieType(std::string type) +{ + stored_type = type; +} + +Zombie *ZombieEvent::newZombie(std::string name) +{ + return new Zombie(name, stored_type); +} + +Zombie *ZombieEvent::randomChump() +{ + std::string pool[10] = { + "Jordan", + "Mr.poopybutthole", + "Jean-Denis", + "Table", + "Charle", + "Abe", + "James", + "Homer", + "yo", + "rideaux" + }; + return new Zombie(pool[rand() % 10], stored_type); +} diff --git a/cpp01/ex02/ZombieEvent.hpp b/cpp01/ex02/ZombieEvent.hpp new file mode 100644 index 0000000..869207e --- /dev/null +++ b/cpp01/ex02/ZombieEvent.hpp @@ -0,0 +1,18 @@ +#ifndef ZOMBIE_EVENT_HPP +# define ZOMBIE_EVENT_HPP + +#include +#include "Zombie.hpp" + +class ZombieEvent +{ + public: + void setZombieType(std::string type); + Zombie *newZombie(std::string name); + Zombie *randomChump(); + + private: + std::string stored_type; +}; + +#endif diff --git a/cpp01/ex02/main.cpp b/cpp01/ex02/main.cpp new file mode 100644 index 0000000..1df20d2 --- /dev/null +++ b/cpp01/ex02/main.cpp @@ -0,0 +1,20 @@ +#include +#include "Zombie.hpp" +#include "ZombieEvent.hpp" + +int main() +{ + Zombie *z; + ZombieEvent zevent; + + srand(time(NULL)); + zevent.setZombieType("standard"); + z = zevent.newZombie("jean"); + delete z; + for (int i = 0; i < 5; i++) + { + z = zevent.randomChump(); + delete z; + } + return 0; +} diff --git a/cpp01/ex03/Zombie.cpp b/cpp01/ex03/Zombie.cpp new file mode 100644 index 0000000..2ea23b6 --- /dev/null +++ b/cpp01/ex03/Zombie.cpp @@ -0,0 +1,14 @@ +#include +#include "Zombie.hpp" + +Zombie::Zombie(std::string n, std::string t) +{ + name = n; + type = t; + announce(); +} + +void Zombie::announce() +{ + std::cout << "<" << name << " (" << type << ")> Braiiiiiiinnnssss..." << std::endl; +} diff --git a/cpp01/ex03/Zombie.hpp b/cpp01/ex03/Zombie.hpp new file mode 100644 index 0000000..980ea49 --- /dev/null +++ b/cpp01/ex03/Zombie.hpp @@ -0,0 +1,17 @@ +#ifndef ZOMBIE_HPP +# define ZOMBIE_HPP + +#include + +class Zombie +{ + public: + Zombie(std::string n, std::string t); + void announce(); + + private: + std::string name; + std::string type; +}; + +#endif diff --git a/cpp01/ex03/ZombieHorde.cpp b/cpp01/ex03/ZombieHorde.cpp new file mode 100644 index 0000000..e8218b4 --- /dev/null +++ b/cpp01/ex03/ZombieHorde.cpp @@ -0,0 +1,41 @@ +#include +#include "ZombieHorde.hpp" + +ZombieHorde::ZombieHorde(int size) +{ + std::string name_pool[10] = { + "Jordan", + "Mr.poopybutthole", + "Jean-Denis", + "Table", + "Charle", + "Abe", + "James", + "Homer", + "yo", + "rideaux" + }; + std::string type_pool[4] = { + "fire", + "water", + "earth", + "wind" + }; + horde = new Zombie*[size]; + horde_size = size; + for (int i = 0; i < size; i++) + horde[i] = new Zombie(name_pool[rand() % 10], type_pool[rand() % 4]); +} + +ZombieHorde::~ZombieHorde() +{ + for (int i = 0; i < horde_size; i++) + delete horde[i]; + delete [] horde; +} + +void ZombieHorde::announce() +{ + for (int i = 0; i < horde_size; i++) + horde[i]->announce(); +} diff --git a/cpp01/ex03/ZombieHorde.hpp b/cpp01/ex03/ZombieHorde.hpp new file mode 100644 index 0000000..772bcc0 --- /dev/null +++ b/cpp01/ex03/ZombieHorde.hpp @@ -0,0 +1,18 @@ +#ifndef ZOMBIE_HORDE_HPP +# define ZOMBIE_HORDE_HPP + +# include "Zombie.hpp" + +class ZombieHorde +{ + public: + ZombieHorde(int size); + void announce(); + ~ZombieHorde(); + + private: + int horde_size; + Zombie **horde; +}; + +#endif diff --git a/cpp01/ex03/main.cpp b/cpp01/ex03/main.cpp new file mode 100644 index 0000000..896b05e --- /dev/null +++ b/cpp01/ex03/main.cpp @@ -0,0 +1,15 @@ +#include +#include "Zombie.hpp" +#include "ZombieHorde.hpp" + +int main() +{ + srand(time(NULL)); + + ZombieHorde horde = ZombieHorde(10); + horde.announce(); + + ZombieHorde *heap_horde = new ZombieHorde(10); + heap_horde->announce(); + delete heap_horde; +} diff --git a/cpp01/ex04/ex04.cpp b/cpp01/ex04/ex04.cpp new file mode 100644 index 0000000..865cb1a --- /dev/null +++ b/cpp01/ex04/ex04.cpp @@ -0,0 +1,13 @@ +#include +#include + +int main() +{ + std::string s = "HI THIS IS BRAIN"; + std::string &ref_s = s; + std::string *ptr_s = &s; + + std::cout << *ptr_s << std::endl; + std::cout << ref_s << std::endl; + return 0; +} diff --git a/subjects/cpp00.en.pdf b/subjects/cpp00.en.pdf new file mode 100644 index 0000000..d92d557 Binary files /dev/null and b/subjects/cpp00.en.pdf differ diff --git a/subjects/cpp00.pdf b/subjects/cpp00.pdf deleted file mode 100644 index d92d557..0000000 Binary files a/subjects/cpp00.pdf and /dev/null differ diff --git a/subjects/cpp01.en.pdf b/subjects/cpp01.en.pdf new file mode 100644 index 0000000..14ca9bd Binary files /dev/null and b/subjects/cpp01.en.pdf differ -- cgit