aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rw-r--r--cpp01/ex04/ex04.cpp14
-rw-r--r--cpp01/ex05/Brain.cpp20
-rw-r--r--cpp01/ex05/Brain.hpp26
-rw-r--r--cpp01/ex05/Human.cpp23
-rw-r--r--cpp01/ex05/Human.hpp28
-rw-r--r--cpp01/ex05/main.cpp21
-rw-r--r--cpp01/ex06/HumanA.cpp24
-rw-r--r--cpp01/ex06/HumanA.hpp29
-rw-r--r--cpp01/ex06/HumanB.cpp28
-rw-r--r--cpp01/ex06/HumanB.hpp30
-rw-r--r--cpp01/ex06/Weapon.cpp28
-rw-r--r--cpp01/ex06/Weapon.hpp29
-rw-r--r--cpp01/ex06/main.cpp34
-rw-r--r--cpp01/ex07/Makefile35
-rw-r--r--cpp01/ex07/main.cpp56
-rwxr-xr-xcpp01/ex07/test.sh5
-rw-r--r--cpp01/ex07/test16
-rw-r--r--cpp01/ex07/test25
19 files changed, 442 insertions, 1 deletions
diff --git a/.gitignore b/.gitignore
index 51f5ada..a825d40 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,3 +2,5 @@
a.out
megaphone
crapyphonebook
+replace
+*.replace
diff --git a/cpp01/ex04/ex04.cpp b/cpp01/ex04/ex04.cpp
index 865cb1a..9c34b51 100644
--- a/cpp01/ex04/ex04.cpp
+++ b/cpp01/ex04/ex04.cpp
@@ -1,3 +1,15 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ex04.cpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/02 12:43:03 by cacharle #+# #+# */
+/* Updated: 2020/02/02 12:43:06 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
#include <iostream>
#include <string>
@@ -7,7 +19,7 @@ int main()
std::string &ref_s = s;
std::string *ptr_s = &s;
- std::cout << *ptr_s << std::endl;
std::cout << ref_s << std::endl;
+ std::cout << *ptr_s << std::endl;
return 0;
}
diff --git a/cpp01/ex05/Brain.cpp b/cpp01/ex05/Brain.cpp
new file mode 100644
index 0000000..7ebf969
--- /dev/null
+++ b/cpp01/ex05/Brain.cpp
@@ -0,0 +1,20 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* Brain.cpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/02 12:47:24 by cacharle #+# #+# */
+/* Updated: 2020/02/02 16:32:58 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "Brain.hpp"
+
+std::string Brain::identify() const
+{
+ std::stringstream ss;
+ ss << this;
+ return "0x" + ss.str();
+}
diff --git a/cpp01/ex05/Brain.hpp b/cpp01/ex05/Brain.hpp
new file mode 100644
index 0000000..6c1f28b
--- /dev/null
+++ b/cpp01/ex05/Brain.hpp
@@ -0,0 +1,26 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* Brain.hpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/02 12:47:22 by cacharle #+# #+# */
+/* Updated: 2020/02/02 16:28:27 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef BRAIN_HPP
+# define BRAIN_HPP
+
+# include <string>
+# include <sstream>
+# include <iostream>
+
+class Brain
+{
+ public:
+ std::string identify() const;
+};
+
+#endif
diff --git a/cpp01/ex05/Human.cpp b/cpp01/ex05/Human.cpp
new file mode 100644
index 0000000..4db0568
--- /dev/null
+++ b/cpp01/ex05/Human.cpp
@@ -0,0 +1,23 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* Human.cpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/02 12:52:38 by cacharle #+# #+# */
+/* Updated: 2020/02/02 13:08:39 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "Human.hpp"
+
+std::string Human::identify()
+{
+ return brain.identify();
+}
+
+const Brain& Human::getBrain()
+{
+ return brain;
+}
diff --git a/cpp01/ex05/Human.hpp b/cpp01/ex05/Human.hpp
new file mode 100644
index 0000000..6c38ee0
--- /dev/null
+++ b/cpp01/ex05/Human.hpp
@@ -0,0 +1,28 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* Human.hpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/02 12:52:39 by cacharle #+# #+# */
+/* Updated: 2020/02/02 13:08:46 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef HUMAN_HPP
+# define HUMAN_HPP
+
+# include "Brain.hpp"
+
+class Human
+{
+ private:
+ const Brain brain;
+
+ public:
+ std::string identify();
+ const Brain& getBrain() ;
+};
+
+#endif
diff --git a/cpp01/ex05/main.cpp b/cpp01/ex05/main.cpp
new file mode 100644
index 0000000..584320a
--- /dev/null
+++ b/cpp01/ex05/main.cpp
@@ -0,0 +1,21 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* main.cpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/02 12:57:25 by cacharle #+# #+# */
+/* Updated: 2020/02/02 16:27:47 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+# include "Brain.hpp"
+# include "Human.hpp"
+
+int main()
+{
+ Human bob;
+ std::cout << bob.identify() << std::endl;
+ std::cout << bob.getBrain().identify() << std::endl;
+}
diff --git a/cpp01/ex06/HumanA.cpp b/cpp01/ex06/HumanA.cpp
new file mode 100644
index 0000000..8d9b449
--- /dev/null
+++ b/cpp01/ex06/HumanA.cpp
@@ -0,0 +1,24 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* HumanA.cpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/02 16:44:03 by cacharle #+# #+# */
+/* Updated: 2020/02/02 16:54:07 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "HumanA.hpp"
+
+HumanA::HumanA(std::string name, Weapon weapon)
+{
+ this->name = name;
+ this->weapon = weapon;
+}
+
+void HumanA::attack()
+{
+ std::cout << name << " attack with his " << weapon.getType();
+}
diff --git a/cpp01/ex06/HumanA.hpp b/cpp01/ex06/HumanA.hpp
new file mode 100644
index 0000000..1c3ccf9
--- /dev/null
+++ b/cpp01/ex06/HumanA.hpp
@@ -0,0 +1,29 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* HumanA.hpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/02 16:37:23 by cacharle #+# #+# */
+/* Updated: 2020/02/02 16:54:48 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef HUMANA_HPP
+# define HUMANA_HPP
+
+# include <iostream>
+# include "Weapon.hpp"
+
+class HumanA
+{
+ private:
+ std::string name;
+ Weapon weapon;
+ public:
+ HumanA(std::string(name), Weapon(weapon));
+ void attack();
+};
+
+#endif
diff --git a/cpp01/ex06/HumanB.cpp b/cpp01/ex06/HumanB.cpp
new file mode 100644
index 0000000..e08363c
--- /dev/null
+++ b/cpp01/ex06/HumanB.cpp
@@ -0,0 +1,28 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* HumanB.cpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/02 16:46:02 by cacharle #+# #+# */
+/* Updated: 2020/02/02 16:54:33 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "HumanB.hpp"
+
+HumanB::HumanB(std::string name)
+{
+ this->name = name;
+}
+
+void HumanB::attack()
+{
+ std::cout << name << " attack with his " << weapon.getType();
+}
+
+void HumanB::setWeapon(Weapon weapon)
+{
+ this->weapon = weapon;
+}
diff --git a/cpp01/ex06/HumanB.hpp b/cpp01/ex06/HumanB.hpp
new file mode 100644
index 0000000..a01c881
--- /dev/null
+++ b/cpp01/ex06/HumanB.hpp
@@ -0,0 +1,30 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* HumanB.hpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/02 16:42:54 by cacharle #+# #+# */
+/* Updated: 2020/02/02 16:54:18 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef HUMANB_HPP
+# define HUMANB_HPP
+
+# include <iostream>
+# include "Weapon.hpp"
+
+class HumanB
+{
+ private:
+ std::string name;
+ Weapon weapon;
+ public:
+ HumanB(std::string name);
+ void attack();
+ void setWeapon(Weapon weapon);
+};
+
+#endif
diff --git a/cpp01/ex06/Weapon.cpp b/cpp01/ex06/Weapon.cpp
new file mode 100644
index 0000000..86738a8
--- /dev/null
+++ b/cpp01/ex06/Weapon.cpp
@@ -0,0 +1,28 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* Weapon.cpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/02 16:36:23 by cacharle #+# #+# */
+/* Updated: 2020/02/02 16:56:48 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "Weapon.hpp"
+
+Weapon::Weapon(std::string type)
+{
+ this->type = type;
+}
+
+const std::string& Weapon::getType()
+{
+ return &type;
+}
+
+void Weapon::setType(const std::string& type)
+{
+ this->type = type;
+}
diff --git a/cpp01/ex06/Weapon.hpp b/cpp01/ex06/Weapon.hpp
new file mode 100644
index 0000000..ea9b738
--- /dev/null
+++ b/cpp01/ex06/Weapon.hpp
@@ -0,0 +1,29 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* Weapon.hpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/02 16:34:31 by cacharle #+# #+# */
+/* Updated: 2020/02/02 16:56:40 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef WEAPON_HPP
+# define WEAPON_HPP
+
+# include <string>
+
+class Weapon
+{
+ private:
+ std::string type;
+
+ public:
+ Weapon(std::string type);
+ const std::string& getType();
+ void setType(const std::string& type);
+};
+
+#endif
diff --git a/cpp01/ex06/main.cpp b/cpp01/ex06/main.cpp
new file mode 100644
index 0000000..dfc03a0
--- /dev/null
+++ b/cpp01/ex06/main.cpp
@@ -0,0 +1,34 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* main.cpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/02 16:40:20 by cacharle #+# #+# */
+/* Updated: 2020/02/02 16:40:51 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "Weapon.hpp"
+#include "HumanA.hpp"
+#include "HumanB.hpp"
+
+int main()
+{
+ {
+ Weapon club = Weapon("crude spiked club");
+ HumanA bob("Bob", club);
+ bob.attack();
+ club.setType("some other type of club");
+ bob.attack();
+ }
+ {
+ Weapon club = Weapon("crude spiked club");
+ HumanB jim("Jim");
+ jim.setWeapon(club);
+ jim.attack();
+ club.setType("some other type of club");
+ jim.attack();
+ }
+}
diff --git a/cpp01/ex07/Makefile b/cpp01/ex07/Makefile
new file mode 100644
index 0000000..7a649fc
--- /dev/null
+++ b/cpp01/ex07/Makefile
@@ -0,0 +1,35 @@
+# **************************************************************************** #
+# #
+# ::: :::::::: #
+# Makefile :+: :+: :+: #
+# +:+ +:+ +:+ #
+# By: cacharle <marvin@42.fr> +#+ +:+ +#+ #
+# +#+#+#+#+#+ +#+ #
+# Created: 2020/02/02 17:05:31 by cacharle #+# #+# #
+# Updated: 2020/02/02 17:58:08 by cacharle ### ########.fr #
+# #
+# **************************************************************************** #
+
+CXX = clang++
+CXXFLAGS= -Wall -Wextra #-Werror
+
+SRC = $(shell find . -type f -name "*.cpp")
+OBJ = $(SRC:.cpp=.o)
+
+NAME = replace
+
+all: $(NAME)
+
+$(NAME): $(OBJ)
+ $(CXX) -o $@ $^
+
+%.o: %.cpp
+ $(CXX) $(CXXFLAGS) -c -o $@ $<
+
+clean:
+ $(RM) $(OBJ)
+
+fclean: clean
+ $(RM) $(NAME)
+
+re: fclean all
diff --git a/cpp01/ex07/main.cpp b/cpp01/ex07/main.cpp
new file mode 100644
index 0000000..fbef95f
--- /dev/null
+++ b/cpp01/ex07/main.cpp
@@ -0,0 +1,56 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* main.cpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/02 17:08:28 by cacharle #+# #+# */
+/* Updated: 2020/02/02 18:00:25 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+# include <iostream>
+# include <fstream>
+# include <string>
+
+int main(int argc, char **argv)
+{
+ if (argc != 4)
+ {
+ std::cerr << "Usage: " << argv[0] << " filename s1 s2";
+ return 1;
+ }
+ std::string filename(argv[1]);
+ std::string find_str(argv[2]);
+ std::string replace_str(argv[3]);
+
+ std::ifstream file(filename);
+ std::ofstream outfile(filename + ".replace");
+ if (!file)
+ {
+ std::cerr << "Could not open " << filename;
+ outfile.close();
+ return 1;
+ }
+ if (!outfile)
+ {
+ std::cerr << "Could not create " << filename << ".replace";
+ file.close();
+ return 1;
+ }
+ std::string line;
+ while (std::getline(file, line))
+ {
+ while (true)
+ {
+ size_t i = line.find(find_str);
+ if (i == std::string::npos)
+ break;
+ line.replace(i, find_str.length(), replace_str);
+ }
+ outfile << line << std::endl;
+ }
+ file.close();
+ outfile.close();
+}
diff --git a/cpp01/ex07/test.sh b/cpp01/ex07/test.sh
new file mode 100755
index 0000000..69cdc43
--- /dev/null
+++ b/cpp01/ex07/test.sh
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+make all
+./replace test1 bonjour aurevoir
+./replace test2 occ many
diff --git a/cpp01/ex07/test1 b/cpp01/ex07/test1
new file mode 100644
index 0000000..2851ba4
--- /dev/null
+++ b/cpp01/ex07/test1
@@ -0,0 +1,6 @@
+bonjour je suis un
+charles
+avec quelque bonjour
+dans ce fichier
+bonjour
+hi im bonj
diff --git a/cpp01/ex07/test2 b/cpp01/ex07/test2
new file mode 100644
index 0000000..227746e
--- /dev/null
+++ b/cpp01/ex07/test2
@@ -0,0 +1,5 @@
+occ occ occ hocket
+
+lalala occ asdfasdf occ
+
+occ occ occ occ