aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore3
-rw-r--r--cpp05/ex00/Bureaucrat.cpp106
-rw-r--r--cpp05/ex00/Bureaucrat.hpp61
-rw-r--r--cpp05/ex00/main.cpp48
-rw-r--r--cpp05/ex01/Bureaucrat.cpp106
-rw-r--r--cpp05/ex01/Bureaucrat.hpp62
-rw-r--r--cpp05/ex01/Form.cpp114
-rw-r--r--cpp05/ex01/Form.hpp63
-rw-r--r--cpp05/ex01/main.cpp48
-rw-r--r--cpp07/ex00/Makefile35
-rw-r--r--cpp07/ex00/whatever.cpp55
-rw-r--r--cpp07/ex01/Makefile35
-rw-r--r--cpp07/ex01/iter.cpp63
-rw-r--r--cpp07/ex02/Array.hpp72
-rw-r--r--cpp07/ex02/Makefile35
-rw-r--r--cpp07/ex02/main.cpp81
16 files changed, 987 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index a825d40..effcdeb 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,3 +4,6 @@ megaphone
crapyphonebook
replace
*.replace
+a_few_functions
+iter
+array
diff --git a/cpp05/ex00/Bureaucrat.cpp b/cpp05/ex00/Bureaucrat.cpp
new file mode 100644
index 0000000..69ca053
--- /dev/null
+++ b/cpp05/ex00/Bureaucrat.cpp
@@ -0,0 +1,106 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* Bureaucrat.cpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/14 18:08:13 by charles #+# #+# */
+/* Updated: 2020/04/14 18:44:49 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "Bureaucrat.hpp"
+
+Bureaucrat::Bureaucrat(Bureaucrat const& other)
+{
+ *this = other;
+}
+
+void Bureaucrat::operator=(Bureaucrat const& other)
+{
+ m_grade = other.m_grade;
+}
+
+Bureaucrat::~Bureaucrat()
+{}
+
+Bureaucrat::Bureaucrat(std::string const& name, int grade)
+ : m_name(name), m_grade(grade)
+{
+}
+
+std::string const& Bureaucrat::getName() const
+{
+ return m_name;
+}
+
+int Bureaucrat::getGrade() const
+{
+ return m_grade;
+}
+
+void Bureaucrat::incrementGrade()
+{
+ if (m_grade <= 1)
+ throw Bureaucrat::GradeTooHighException();
+ else
+ m_grade--;
+}
+
+void Bureaucrat::decrementGrade()
+{
+ if (m_grade >= 150)
+ throw Bureaucrat::GradeTooLowException();
+ else
+ m_grade++;
+}
+
+Bureaucrat::GradeTooHighException::GradeTooHighException() : std::exception()
+{}
+
+Bureaucrat::GradeTooHighException::GradeTooHighException(GradeTooHighException const& other)
+ : std::exception(other)
+{}
+
+void Bureaucrat::GradeTooHighException::operator=(GradeTooHighException const& other)
+{
+ std::exception::operator=(other);
+}
+
+Bureaucrat::GradeTooHighException::~GradeTooHighException()
+{}
+
+char const* Bureaucrat::GradeTooHighException::what() const throw()
+{
+ return "Grade is too high";
+}
+
+Bureaucrat::GradeTooLowException::GradeTooLowException() : std::exception()
+{}
+
+Bureaucrat::GradeTooLowException::GradeTooLowException(GradeTooLowException const& other)
+ : std::exception(other)
+{}
+
+void Bureaucrat::GradeTooLowException::operator=(GradeTooLowException const& other)
+{
+ std::exception::operator=(other);
+}
+
+Bureaucrat::GradeTooLowException::~GradeTooLowException()
+{}
+
+char const* Bureaucrat::GradeTooLowException::what() const throw()
+{
+ return "Grade is too low";
+}
+
+Bureaucrat::Bureaucrat()
+{}
+
+std::ostream& operator<<(std::ostream& out, Bureaucrat const& b)
+{
+ std::cout << b.getName() << ", bureaucrat grade " << b.getGrade() << std::endl;
+ return out;
+}
diff --git a/cpp05/ex00/Bureaucrat.hpp b/cpp05/ex00/Bureaucrat.hpp
new file mode 100644
index 0000000..8cb328e
--- /dev/null
+++ b/cpp05/ex00/Bureaucrat.hpp
@@ -0,0 +1,61 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* Bureaucrat.hpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/14 18:04:32 by charles #+# #+# */
+/* Updated: 2020/04/14 18:42:13 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef BUREAUCRAT_HPP
+# define BUREAUCRAT_HPP
+
+# include <iostream>
+# include <exception>
+
+class Bureaucrat
+{
+public:
+ Bureaucrat(Bureaucrat const& other);
+ void operator=(Bureaucrat const& other);
+ ~Bureaucrat();
+
+ Bureaucrat(std::string const& name, int grade);
+ std::string const& getName() const;
+ int getGrade() const;
+ void incrementGrade();
+ void decrementGrade();
+
+ class GradeTooHighException : public std::exception
+ {
+ public:
+ GradeTooHighException();
+ GradeTooHighException(GradeTooHighException const& other);
+ void operator=(GradeTooHighException const& other);
+ ~GradeTooHighException();
+ virtual char const* what() const throw();
+ };
+
+ class GradeTooLowException : public std::exception
+ {
+ public:
+ GradeTooLowException();
+ GradeTooLowException(GradeTooLowException const& other);
+ void operator=(GradeTooLowException const& other);
+ ~GradeTooLowException();
+ virtual char const* what() const throw();
+ };
+
+private:
+ Bureaucrat();
+
+ std::string const m_name;
+ int m_grade;
+};
+
+std::ostream& operator<<(std::ostream& out, Bureaucrat const& b);
+
+#endif
diff --git a/cpp05/ex00/main.cpp b/cpp05/ex00/main.cpp
new file mode 100644
index 0000000..ebfed5a
--- /dev/null
+++ b/cpp05/ex00/main.cpp
@@ -0,0 +1,48 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* main.cpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/14 18:13:05 by charles #+# #+# */
+/* Updated: 2020/04/14 18:43:15 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "Bureaucrat.hpp"
+
+int main()
+{
+ Bureaucrat a("jean", 140);
+ Bureaucrat b("didier", 10);
+
+ while (true)
+ {
+ try
+ {
+ a.decrementGrade();
+ std::cout << a;
+ }
+ catch (std::exception& e)
+ {
+ std::cout << e.what() << std::endl;
+ break;
+ }
+ }
+
+ while (true)
+ {
+ try
+ {
+ b.incrementGrade();
+ std::cout << b;
+ }
+ catch (std::exception& e)
+ {
+ std::cout << e.what() << std::endl;
+ break;
+ }
+ }
+ return 0;
+}
diff --git a/cpp05/ex01/Bureaucrat.cpp b/cpp05/ex01/Bureaucrat.cpp
new file mode 100644
index 0000000..69ca053
--- /dev/null
+++ b/cpp05/ex01/Bureaucrat.cpp
@@ -0,0 +1,106 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* Bureaucrat.cpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/14 18:08:13 by charles #+# #+# */
+/* Updated: 2020/04/14 18:44:49 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "Bureaucrat.hpp"
+
+Bureaucrat::Bureaucrat(Bureaucrat const& other)
+{
+ *this = other;
+}
+
+void Bureaucrat::operator=(Bureaucrat const& other)
+{
+ m_grade = other.m_grade;
+}
+
+Bureaucrat::~Bureaucrat()
+{}
+
+Bureaucrat::Bureaucrat(std::string const& name, int grade)
+ : m_name(name), m_grade(grade)
+{
+}
+
+std::string const& Bureaucrat::getName() const
+{
+ return m_name;
+}
+
+int Bureaucrat::getGrade() const
+{
+ return m_grade;
+}
+
+void Bureaucrat::incrementGrade()
+{
+ if (m_grade <= 1)
+ throw Bureaucrat::GradeTooHighException();
+ else
+ m_grade--;
+}
+
+void Bureaucrat::decrementGrade()
+{
+ if (m_grade >= 150)
+ throw Bureaucrat::GradeTooLowException();
+ else
+ m_grade++;
+}
+
+Bureaucrat::GradeTooHighException::GradeTooHighException() : std::exception()
+{}
+
+Bureaucrat::GradeTooHighException::GradeTooHighException(GradeTooHighException const& other)
+ : std::exception(other)
+{}
+
+void Bureaucrat::GradeTooHighException::operator=(GradeTooHighException const& other)
+{
+ std::exception::operator=(other);
+}
+
+Bureaucrat::GradeTooHighException::~GradeTooHighException()
+{}
+
+char const* Bureaucrat::GradeTooHighException::what() const throw()
+{
+ return "Grade is too high";
+}
+
+Bureaucrat::GradeTooLowException::GradeTooLowException() : std::exception()
+{}
+
+Bureaucrat::GradeTooLowException::GradeTooLowException(GradeTooLowException const& other)
+ : std::exception(other)
+{}
+
+void Bureaucrat::GradeTooLowException::operator=(GradeTooLowException const& other)
+{
+ std::exception::operator=(other);
+}
+
+Bureaucrat::GradeTooLowException::~GradeTooLowException()
+{}
+
+char const* Bureaucrat::GradeTooLowException::what() const throw()
+{
+ return "Grade is too low";
+}
+
+Bureaucrat::Bureaucrat()
+{}
+
+std::ostream& operator<<(std::ostream& out, Bureaucrat const& b)
+{
+ std::cout << b.getName() << ", bureaucrat grade " << b.getGrade() << std::endl;
+ return out;
+}
diff --git a/cpp05/ex01/Bureaucrat.hpp b/cpp05/ex01/Bureaucrat.hpp
new file mode 100644
index 0000000..ff8bb2e
--- /dev/null
+++ b/cpp05/ex01/Bureaucrat.hpp
@@ -0,0 +1,62 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* Bureaucrat.hpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/14 18:04:32 by charles #+# #+# */
+/* Updated: 2020/04/14 19:37:05 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef BUREAUCRAT_HPP
+# define BUREAUCRAT_HPP
+
+# include <iostream>
+# include <exception>
+
+class Bureaucrat
+{
+public:
+ Bureaucrat(Bureaucrat const& other);
+ void operator=(Bureaucrat const& other);
+ ~Bureaucrat();
+
+ Bureaucrat(std::string const& name, int grade);
+ std::string const& getName() const;
+ int getGrade() const;
+ void incrementGrade();
+ void decrementGrade();
+ // signForm();
+
+ class GradeTooHighException : public std::exception
+ {
+ public:
+ GradeTooHighException();
+ GradeTooHighException(GradeTooHighException const& other);
+ void operator=(GradeTooHighException const& other);
+ ~GradeTooHighException();
+ virtual char const* what() const throw();
+ };
+
+ class GradeTooLowException : public std::exception
+ {
+ public:
+ GradeTooLowException();
+ GradeTooLowException(GradeTooLowException const& other);
+ void operator=(GradeTooLowException const& other);
+ ~GradeTooLowException();
+ virtual char const* what() const throw();
+ };
+
+private:
+ Bureaucrat();
+
+ std::string const m_name;
+ int m_grade;
+};
+
+std::ostream& operator<<(std::ostream& out, Bureaucrat const& b);
+
+#endif
diff --git a/cpp05/ex01/Form.cpp b/cpp05/ex01/Form.cpp
new file mode 100644
index 0000000..8aafc94
--- /dev/null
+++ b/cpp05/ex01/Form.cpp
@@ -0,0 +1,114 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* Form.cpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/14 19:26:39 by charles #+# #+# */
+/* Updated: 2020/04/14 19:39:21 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "Form.hpp"
+
+Form::Form(Form const& other)
+ : m_name(other.m_name),
+ m_gradeSign(other.m_gradeSign),
+ m_gradeExecute(other.m_gradeExecute)
+{
+ *this = other;
+}
+
+void Form::operator=(Form const& other)
+{
+ m_signed = other.m_signed;
+}
+
+Form::~Form()
+{}
+
+Form::Form(std::string const& name)
+ : m_name(name), m_signed(false), m_gradeSign(1), m_gradeExecute(1)
+{}
+
+std::string const& Form::getName() const
+{
+ return m_name;
+}
+
+bool Form::getSigned() const
+{
+ return m_signed;
+}
+
+int Form::getGradeSign() const
+{
+ return m_gradeSign;
+}
+
+int Form::getGradeExecute() const
+{
+ return m_gradeExecute;
+}
+
+void Form::beSigned(Bureaucrat const& b)
+{
+ if (b.getGrade() >= m_gradeSign)
+ m_signed = true;
+}
+
+Form::GradeTooHighException::GradeTooHighException() : std::exception()
+{}
+
+Form::GradeTooHighException::GradeTooHighException(GradeTooHighException const& other)
+ : std::exception(other)
+{}
+
+void Form::GradeTooHighException::operator=(GradeTooHighException const& other)
+{
+ std::exception::operator=(other);
+}
+
+Form::GradeTooHighException::~GradeTooHighException()
+{}
+
+char const* Form::GradeTooHighException::what() const throw()
+{
+ return "Grade is too high for form";
+}
+
+Form::GradeTooLowException::GradeTooLowException() : std::exception()
+{}
+
+Form::GradeTooLowException::GradeTooLowException(GradeTooLowException const& other)
+ : std::exception(other)
+{}
+
+void Form::GradeTooLowException::operator=(GradeTooLowException const& other)
+{
+ std::exception::operator=(other);
+}
+
+Form::GradeTooLowException::~GradeTooLowException()
+{}
+
+char const* Form::GradeTooLowException::what() const throw()
+{
+ return "Grade is too low for form";
+}
+
+std::ostream& operator<<(std::ostream& out, Form const& f)
+{
+ out << f.getName() << " is "
+ << (f.getSigned() ? "" : "not") << "signed and needs at least"
+ << f.getGradeSign() << " to be signed and "
+ << f.getGradeExecute() << " to be executed" << std::endl;
+ return out;
+}
+
+Form::Form()
+ : m_name(""),
+ m_gradeSign(1),
+ m_gradeExecute(1)
+{}
diff --git a/cpp05/ex01/Form.hpp b/cpp05/ex01/Form.hpp
new file mode 100644
index 0000000..a2421bd
--- /dev/null
+++ b/cpp05/ex01/Form.hpp
@@ -0,0 +1,63 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* Form.hpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/14 19:19:45 by charles #+# #+# */
+/* Updated: 2020/04/14 19:37:21 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef FORM_HPP
+# define FORM_HPP
+
+# include "Bureaucrat.hpp"
+
+class Form
+{
+public:
+ Form(Form const& other);
+ void operator=(Form const& other);
+ ~Form();
+
+ Form(std::string const& name);
+ std::string const& getName() const;
+ bool getSigned() const;
+ int getGradeSign() const;
+ int getGradeExecute() const;
+ void beSigned(Bureaucrat const& b);
+
+ class GradeTooHighException : public std::exception
+ {
+ public:
+ GradeTooHighException();
+ GradeTooHighException(GradeTooHighException const& other);
+ void operator=(GradeTooHighException const& other);
+ ~GradeTooHighException();
+ virtual char const* what() const throw();
+ };
+
+ class GradeTooLowException : public std::exception
+ {
+ public:
+ GradeTooLowException();
+ GradeTooLowException(GradeTooLowException const& other);
+ void operator=(GradeTooLowException const& other);
+ ~GradeTooLowException();
+ virtual char const* what() const throw();
+ };
+
+private:
+ Form();
+
+ std::string const m_name;
+ bool m_signed;
+ int const m_gradeSign;
+ int const m_gradeExecute;
+};
+
+std::ostream& operator<<(std::ostream& out, Form const& f);
+
+#endif
diff --git a/cpp05/ex01/main.cpp b/cpp05/ex01/main.cpp
new file mode 100644
index 0000000..ebfed5a
--- /dev/null
+++ b/cpp05/ex01/main.cpp
@@ -0,0 +1,48 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* main.cpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/14 18:13:05 by charles #+# #+# */
+/* Updated: 2020/04/14 18:43:15 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "Bureaucrat.hpp"
+
+int main()
+{
+ Bureaucrat a("jean", 140);
+ Bureaucrat b("didier", 10);
+
+ while (true)
+ {
+ try
+ {
+ a.decrementGrade();
+ std::cout << a;
+ }
+ catch (std::exception& e)
+ {
+ std::cout << e.what() << std::endl;
+ break;
+ }
+ }
+
+ while (true)
+ {
+ try
+ {
+ b.incrementGrade();
+ std::cout << b;
+ }
+ catch (std::exception& e)
+ {
+ std::cout << e.what() << std::endl;
+ break;
+ }
+ }
+ return 0;
+}
diff --git a/cpp07/ex00/Makefile b/cpp07/ex00/Makefile
new file mode 100644
index 0000000..660a45b
--- /dev/null
+++ b/cpp07/ex00/Makefile
@@ -0,0 +1,35 @@
+# **************************************************************************** #
+# #
+# ::: :::::::: #
+# Makefile :+: :+: :+: #
+# +:+ +:+ +:+ #
+# By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ #
+# +#+#+#+#+#+ +#+ #
+# Created: 2020/04/14 19:48:34 by charles #+# #+# #
+# Updated: 2020/04/14 19:58:14 by charles ### ########.fr #
+# #
+# **************************************************************************** #
+
+NAME = a_few_functions
+
+CXX = clang++
+CXXFLAGS = -std=c++98 -Wall -Wextra -Werror
+
+SRC = whatever.cpp
+OBJ = $(SRC:.cpp=.o)
+
+all: $(NAME)
+
+$(NAME): $(OBJ)
+ $(CXX) -o $@ $<
+
+%.o: %.cpp
+ $(CXX) $(CXXFLAGS) -c -o $@ $^
+
+clean:
+ rm -rf $(OBJ)
+
+fclean: clean
+ rm -rf $(NAME)
+
+re: fclean all
diff --git a/cpp07/ex00/whatever.cpp b/cpp07/ex00/whatever.cpp
new file mode 100644
index 0000000..ebebf8c
--- /dev/null
+++ b/cpp07/ex00/whatever.cpp
@@ -0,0 +1,55 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* whatever.cpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/14 19:46:56 by charles #+# #+# */
+/* Updated: 2020/04/14 20:01:41 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include <iostream>
+#include <string>
+
+template<typename T>
+void swap(T& a, T& b)
+{
+ T tmp = a;
+ a = b;
+ b = tmp;
+}
+
+template<typename T>
+T& min(T& a, T& b)
+{
+ return a < b ? a : b;
+}
+
+template<typename T>
+T& max(T& a, T& b)
+{
+ return a > b ? a : b;
+}
+
+int main()
+{
+ int a = 2;
+ int b = 3;
+
+ ::swap(a, b);
+ std::cout << "a = " << a << ", b = " << b << std::endl;
+ std::cout << "min( a, b ) = " << ::min( a, b ) << std::endl;
+ std::cout << "max( a, b ) = " << ::max( a, b ) << std::endl;
+
+ std::string c = "chaine1";
+ std::string d = "chaine2";
+
+ ::swap(c, d);
+ std::cout << "c = " << c << ", d = " << d << std::endl;
+ std::cout << "min( c, d ) = " << ::min( c, d ) << std::endl;
+ std::cout << "max( c, d ) = " << ::max( c, d ) << std::endl;
+
+ return 0;
+}
diff --git a/cpp07/ex01/Makefile b/cpp07/ex01/Makefile
new file mode 100644
index 0000000..45180bc
--- /dev/null
+++ b/cpp07/ex01/Makefile
@@ -0,0 +1,35 @@
+# **************************************************************************** #
+# #
+# ::: :::::::: #
+# Makefile :+: :+: :+: #
+# +:+ +:+ +:+ #
+# By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ #
+# +#+#+#+#+#+ +#+ #
+# Created: 2020/04/14 19:48:34 by charles #+# #+# #
+# Updated: 2020/04/14 20:02:14 by charles ### ########.fr #
+# #
+# **************************************************************************** #
+
+NAME = iter
+
+CXX = clang++
+CXXFLAGS = -std=c++98 -Wall -Wextra -Werror
+
+SRC = iter.cpp
+OBJ = $(SRC:.cpp=.o)
+
+all: $(NAME)
+
+$(NAME): $(OBJ)
+ $(CXX) -o $@ $<
+
+%.o: %.cpp
+ $(CXX) $(CXXFLAGS) -c -o $@ $^
+
+clean:
+ rm -rf $(OBJ)
+
+fclean: clean
+ rm -rf $(NAME)
+
+re: fclean all
diff --git a/cpp07/ex01/iter.cpp b/cpp07/ex01/iter.cpp
new file mode 100644
index 0000000..80b29d3
--- /dev/null
+++ b/cpp07/ex01/iter.cpp
@@ -0,0 +1,63 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* iter.cpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/14 20:02:19 by charles #+# #+# */
+/* Updated: 2020/04/14 20:12:17 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include <iostream>
+
+template<typename T>
+void iter(T* ptr, size_t len, void (*f)(T* x))
+{
+ for (size_t i = 0; i < len; i++)
+ f(ptr + i);
+}
+
+template<typename T>
+void timeTwo(T* x)
+{
+ *x *= 2;
+}
+
+int main()
+{
+ int intArray[] = {1, 2, 3, 4, 10, 20, 30, -1, -2};
+ size_t intArraySize = sizeof(intArray) / sizeof(int);
+ for (size_t i = 0; i < intArraySize; i++)
+ std::cout << intArray[i] << ", ";
+ std::cout << std::endl;
+ iter(intArray, intArraySize, timeTwo<int>);
+ for (size_t i = 0; i < intArraySize; i++)
+ std::cout << intArray[i] << ", ";
+ std::cout << std::endl;
+ std::cout << "--------------------------------------" << std::endl;
+
+ float floatArray[] = {1.1, 2.2, 3.3, 4.3, 10.001, 20.9, 30.3, -1.2, -2.4};
+ size_t floatArraySize = sizeof(floatArray) / sizeof(float);
+ for (size_t i = 0; i < floatArraySize; i++)
+ std::cout << floatArray[i] << ", ";
+ std::cout << std::endl;
+ iter(floatArray, floatArraySize, timeTwo<float>);
+ for (size_t i = 0; i < floatArraySize; i++)
+ std::cout << floatArray[i] << ", ";
+ std::cout << std::endl;
+ std::cout << "--------------------------------------" << std::endl;
+
+ unsigned int uintArray[] = {1, 2, 3, 4, 10, 20, 30, 100, 2000};
+ size_t uintArraySize = sizeof(uintArray) / sizeof(unsigned int);
+ for (size_t i = 0; i < uintArraySize; i++)
+ std::cout << uintArray[i] << ", ";
+ std::cout << std::endl;
+ iter(uintArray, uintArraySize, timeTwo<unsigned int>);
+ for (size_t i = 0; i < uintArraySize; i++)
+ std::cout << uintArray[i] << ", ";
+ std::cout << std::endl;
+
+ return 0;
+}
diff --git a/cpp07/ex02/Array.hpp b/cpp07/ex02/Array.hpp
new file mode 100644
index 0000000..fec8698
--- /dev/null
+++ b/cpp07/ex02/Array.hpp
@@ -0,0 +1,72 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* Array.hpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/14 20:14:07 by charles #+# #+# */
+/* Updated: 2020/04/14 20:41:25 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef ARRAP_HPP
+# define ARRAP_HPP
+
+#include <exception>
+
+template<typename T>
+class Array
+{
+public:
+ Array() : m_under(new T[0]), m_size(0)
+ {}
+
+ Array(unsigned int n) : m_under(new T[n]()), m_size(n)
+ {}
+
+ Array(Array const& other) : m_under(new T[other.m_size]), m_size(other.m_size)
+ {
+ for (unsigned int i = 0; i < m_size; i++)
+ m_under[i] = other.m_under[i];
+ }
+
+ void operator=(Array const& other)
+ {
+ delete [] m_under;
+ m_size = other.m_size;
+ m_under = new T[m_size];
+ for (unsigned int i = 0; i < m_size; i++)
+ m_under[i] = other.m_under[i];
+ }
+
+ ~Array()
+ {
+ delete [] m_under;
+ }
+
+ T& operator[](unsigned int n)
+ {
+ if (n >= m_size)
+ throw std::exception();
+ return m_under[n];
+ }
+
+ T const& operator[](unsigned int n) const
+ {
+ if (n >= m_size)
+ throw std::exception();
+ return m_under[n];
+ }
+
+ unsigned int size() const
+ {
+ return m_size;
+ }
+
+private:
+ T* m_under;
+ unsigned int m_size;
+};
+
+#endif
diff --git a/cpp07/ex02/Makefile b/cpp07/ex02/Makefile
new file mode 100644
index 0000000..239a977
--- /dev/null
+++ b/cpp07/ex02/Makefile
@@ -0,0 +1,35 @@
+# **************************************************************************** #
+# #
+# ::: :::::::: #
+# Makefile :+: :+: :+: #
+# +:+ +:+ +:+ #
+# By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ #
+# +#+#+#+#+#+ +#+ #
+# Created: 2020/04/14 19:48:34 by charles #+# #+# #
+# Updated: 2020/04/14 20:39:03 by charles ### ########.fr #
+# #
+# **************************************************************************** #
+
+NAME = array
+
+CXX = clang++
+CXXFLAGS = -std=c++98 -Wall -Wextra -Werror
+
+SRC = main.cpp
+OBJ = $(SRC:.cpp=.o)
+
+all: $(NAME)
+
+$(NAME): $(OBJ)
+ $(CXX) -o $@ $^
+
+%.o: %.cpp Array.hpp
+ $(CXX) $(CXXFLAGS) -c -o $@ $<
+
+clean:
+ rm -rf $(OBJ)
+
+fclean: clean
+ rm -rf $(NAME)
+
+re: fclean all
diff --git a/cpp07/ex02/main.cpp b/cpp07/ex02/main.cpp
new file mode 100644
index 0000000..251d697
--- /dev/null
+++ b/cpp07/ex02/main.cpp
@@ -