From 0f3240844dbd5a874e1565a988ef355ededab6a5 Mon Sep 17 00:00:00 2001 From: Charles Date: Mon, 13 Apr 2020 10:33:05 +0200 Subject: Fixing cpp01 --- cpp01/ex00/Pony.cpp | 19 ++++++++++--------- cpp01/ex00/Pony.hpp | 26 +++++++++++++++++++------- cpp01/ex00/main.cpp | 16 ++++++++++++++-- 3 files changed, 43 insertions(+), 18 deletions(-) (limited to 'cpp01/ex00') diff --git a/cpp01/ex00/Pony.cpp b/cpp01/ex00/Pony.cpp index 61f3b47..b45f0e1 100644 --- a/cpp01/ex00/Pony.cpp +++ b/cpp01/ex00/Pony.cpp @@ -6,27 +6,28 @@ /* By: charles +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/13 09:06:06 by charles #+# #+# */ -/* Updated: 2020/04/13 09:06:11 by charles ### ########.fr */ +/* Updated: 2020/04/13 09:33:59 by charles ### ########.fr */ /* */ /* ************************************************************************** */ #include #include "Pony.hpp" -Pony::Pony(int w, int s) +Pony::Pony(int weight, int maxSpeed) + : m_weight(weight), m_maxSpeed(maxSpeed) { - weight = w; - max_speed = s; } -void Pony::say_hello() +void Pony::sayHello() { - std::cout << "Hi, I'm a pony, I weight " << weight - << " and my speed limit is " << max_speed << std::endl; + std::cout << "Hi, I'm a pony, I weight " << m_weight + << " and my speed limit is " << m_maxSpeed + << 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; + for (int i = 0; i <= m_maxSpeed; i += m_maxSpeed / 10) + 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 index 31a69f4..571414c 100644 --- a/cpp01/ex00/Pony.hpp +++ b/cpp01/ex00/Pony.hpp @@ -1,15 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Pony.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: charles +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/04/13 09:26:16 by charles #+# #+# */ +/* Updated: 2020/04/13 09:27:49 by charles ### ########.fr */ +/* */ +/* ************************************************************************** */ + #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; +public: + Pony(int weight, int maxSpeed); + void sayHello(); + void run(); +private: + int m_weight; + int m_maxSpeed; }; #endif diff --git a/cpp01/ex00/main.cpp b/cpp01/ex00/main.cpp index c8aa0b8..689f7f1 100644 --- a/cpp01/ex00/main.cpp +++ b/cpp01/ex00/main.cpp @@ -1,10 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: charles +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/04/13 09:26:11 by charles #+# #+# */ +/* Updated: 2020/04/13 09:29:58 by charles ### ########.fr */ +/* */ +/* ************************************************************************** */ + #include #include "Pony.hpp" void ponyOnTheHeap() { Pony *p = new Pony(200, 100); - p->say_hello(); + p->sayHello(); p->run(); delete p; } @@ -12,7 +24,7 @@ void ponyOnTheHeap() void ponyOnTheStack() { Pony p(200, 100); - p.say_hello(); + p.sayHello(); p.run(); } -- cgit