diff options
| author | Charles <sircharlesaze@gmail.com> | 2020-01-12 20:20:12 +0100 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2020-01-12 20:20:12 +0100 |
| commit | 7d6a4c877de8048ec5fbea4a563b3d09c8976105 (patch) | |
| tree | a62206e21b3b678d0da6350978e2f6db7cc31fbe /cpp01/ex00 | |
| parent | 7080f89bb2800917bfd9a560046a1ab7505f819e (diff) | |
| download | piscine_cpp-7d6a4c877de8048ec5fbea4a563b3d09c8976105.tar.gz piscine_cpp-7d6a4c877de8048ec5fbea4a563b3d09c8976105.tar.bz2 piscine_cpp-7d6a4c877de8048ec5fbea4a563b3d09c8976105.zip | |
cpp01 00 -> 04
Diffstat (limited to 'cpp01/ex00')
| -rw-r--r-- | cpp01/ex00/Pony.cpp | 20 | ||||
| -rw-r--r-- | cpp01/ex00/Pony.hpp | 15 | ||||
| -rw-r--r-- | cpp01/ex00/main.cpp | 24 |
3 files changed, 59 insertions, 0 deletions
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 <iostream> +#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 <iostream> +#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; +} |
