aboutsummaryrefslogtreecommitdiff
path: root/cpp01/ex00
diff options
context:
space:
mode:
authorCharles Cabergs <me@cacharle.xyz>2020-11-09 11:26:50 +0100
committerCharles Cabergs <me@cacharle.xyz>2020-11-09 11:26:50 +0100
commitb799c007a1b6911fcbe5141429ea541e1277ebdd (patch)
treed70ad0826ad2fc2d635adf9afecf89af0838d20b /cpp01/ex00
parent1e9d90bdf9ef5fc05093d3449d883597c7f896de (diff)
downloadpiscine_cpp-b799c007a1b6911fcbe5141429ea541e1277ebdd.tar.gz
piscine_cpp-b799c007a1b6911fcbe5141429ea541e1277ebdd.tar.bz2
piscine_cpp-b799c007a1b6911fcbe5141429ea541e1277ebdd.zip
Fixing some edge cases in cpp00 and cpp01, Updated formatting
Diffstat (limited to 'cpp01/ex00')
-rw-r--r--cpp01/ex00/Pony.cpp22
-rw-r--r--cpp01/ex00/Pony.hpp10
-rw-r--r--cpp01/ex00/main.cpp9
3 files changed, 28 insertions, 13 deletions
diff --git a/cpp01/ex00/Pony.cpp b/cpp01/ex00/Pony.cpp
index b45f0e1..1b8df61 100644
--- a/cpp01/ex00/Pony.cpp
+++ b/cpp01/ex00/Pony.cpp
@@ -6,28 +6,34 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/13 09:06:06 by charles #+# #+# */
-/* Updated: 2020/04/13 09:33:59 by charles ### ########.fr */
+/* Updated: 2020/11/09 09:57:26 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
-#include <iostream>
#include "Pony.hpp"
-Pony::Pony(int weight, int maxSpeed)
- : m_weight(weight), m_maxSpeed(maxSpeed)
+Pony::Pony(std::string const& name, int weight, int maxSpeed)
+ : m_name(name), m_weight(weight), m_maxSpeed(maxSpeed)
{
+ std::cout << "Hey there, my name is " << m_name << " and you?" << std::endl;
+}
+
+Pony::~Pony()
+{
+ std::cout << "Oh no, I'M DYING! They called me " << m_name << "." << std::endl;
}
void Pony::sayHello()
{
- std::cout << "Hi, I'm a pony, I weight " << m_weight
- << " and my speed limit is " << m_maxSpeed
+ std::cout << "Hi, I'm " << m_name
+ << ", I weight " << m_weight
+ << " and my speed limit is " << m_maxSpeed
<< std::endl;
}
void Pony::run()
{
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;
+ std::cout << m_name << " is running really fast at " << i
+ << ", look at him!" << std::endl;
}
diff --git a/cpp01/ex00/Pony.hpp b/cpp01/ex00/Pony.hpp
index 571414c..5c42a60 100644
--- a/cpp01/ex00/Pony.hpp
+++ b/cpp01/ex00/Pony.hpp
@@ -6,20 +6,26 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/13 09:26:16 by charles #+# #+# */
-/* Updated: 2020/04/13 09:27:49 by charles ### ########.fr */
+/* Updated: 2020/11/09 09:54:25 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef PONY_HPP
# define PONY_HPP
+# include <iostream>
+# include <string>
+
class Pony
{
public:
- Pony(int weight, int maxSpeed);
+ Pony(std::string const& name, int weight, int maxSpeed);
+ ~Pony();
void sayHello();
void run();
+
private:
+ std::string m_name;
int m_weight;
int m_maxSpeed;
};
diff --git a/cpp01/ex00/main.cpp b/cpp01/ex00/main.cpp
index 689f7f1..62a9e67 100644
--- a/cpp01/ex00/main.cpp
+++ b/cpp01/ex00/main.cpp
@@ -6,7 +6,7 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/13 09:26:11 by charles #+# #+# */
-/* Updated: 2020/04/13 09:29:58 by charles ### ########.fr */
+/* Updated: 2020/11/09 09:58:46 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -15,7 +15,8 @@
void ponyOnTheHeap()
{
- Pony *p = new Pony(200, 100);
+ std::cout << "=== ponyOnTheHeap ===" << std::endl;
+ Pony *p = new Pony("ChunkyBoy", 200, 100);
p->sayHello();
p->run();
delete p;
@@ -23,7 +24,8 @@ void ponyOnTheHeap()
void ponyOnTheStack()
{
- Pony p(200, 100);
+ std::cout << "=== ponyOnTheStack ===" << std::endl;
+ Pony p("Jean", 200, 100);
p.sayHello();
p.run();
}
@@ -31,6 +33,7 @@ void ponyOnTheStack()
int main()
{
ponyOnTheHeap();
+ std::cout << std::endl;
ponyOnTheStack();
return 0;
}