commit 859690063bf721958eaf245e831b417da0e0c842 Author: Angel Ortigosa Perez Date: Sun Sep 7 10:03:17 2025 +0200 cpp01... diff --git a/ex00/Makefile b/ex00/Makefile new file mode 100644 index 0000000..38ba1e9 --- /dev/null +++ b/ex00/Makefile @@ -0,0 +1,26 @@ +NAME=zombie + +SRCS=main.cpp Zombie/Zombie.cpp Zombie/newZombie.cpp Zombie/randomChump.cpp + +OBJS=$(SRCS:.cpp=.o) + +CC=g++ +CFLAGS=-Wall -Wextra -Werror -std=c++98 + +all: $(NAME) + +$(NAME): $(OBJS) + $(CC) $(CFLAGS) $(OBJS) -o $(NAME) + +%.o: %.cpp + $(CC) $(CFLAGS) -c $< -o $@ + +clean: + rm -f $(OBJS) + +fclean: clean + rm -f $(NAME) + +re: fclean all + +.PHONY: all clean fclean re diff --git a/ex00/Zombie/Zombie.cpp b/ex00/Zombie/Zombie.cpp new file mode 100644 index 0000000..7c22b5c --- /dev/null +++ b/ex00/Zombie/Zombie.cpp @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Zombie.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos name = "NULL"; +} + +Zombie::~Zombie() +{ + std::cout << this->name << " has died.... again..." << std::endl; +} + +Zombie::Zombie(std::string str) +{ + this->name = str; +} + +void Zombie::announce( void ) +{ + std::cout << this->name << ": BraiiiiiiinnnzzzZ..." << std::endl; +} \ No newline at end of file diff --git a/ex00/Zombie/Zombie.hpp b/ex00/Zombie/Zombie.hpp new file mode 100644 index 0000000..c6c9300 --- /dev/null +++ b/ex00/Zombie/Zombie.hpp @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Zombie.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos + +class Zombie +{ + private: + std::string name; + + public: + Zombie(); + ~Zombie(); + Zombie(std::string str); + void announce( void ); +}; + +Zombie* newZombie( std::string name ); +void randomChump( std::string name ); + +#endif \ No newline at end of file diff --git a/ex00/Zombie/newZombie.cpp b/ex00/Zombie/newZombie.cpp new file mode 100644 index 0000000..ed4f3df --- /dev/null +++ b/ex00/Zombie/newZombie.cpp @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* newZombie.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos announce(); + +} \ No newline at end of file diff --git a/ex00/main.cpp b/ex00/main.cpp new file mode 100644 index 0000000..263ab14 --- /dev/null +++ b/ex00/main.cpp @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos announce(); + + randomChump("Estudiante42"); + + delete(z); + + return (0); +} \ No newline at end of file diff --git a/ex01/Makefile b/ex01/Makefile new file mode 100644 index 0000000..3aadb07 --- /dev/null +++ b/ex01/Makefile @@ -0,0 +1,26 @@ +NAME=zombie + +SRCS=main.cpp Zombie/Zombie.cpp Zombie/zombieHorde.cpp + +OBJS=$(SRCS:.cpp=.o) + +CC=g++ +CFLAGS=-Wall -Wextra -Werror -std=c++98 + +all: $(NAME) + +$(NAME): $(OBJS) + $(CC) $(CFLAGS) $(OBJS) -o $(NAME) + +%.o: %.cpp + $(CC) $(CFLAGS) -c $< -o $@ + +clean: + rm -f $(OBJS) + +fclean: clean + rm -f $(NAME) + +re: fclean all + +.PHONY: all clean fclean re diff --git a/ex01/Zombie/Zombie.cpp b/ex01/Zombie/Zombie.cpp new file mode 100644 index 0000000..34dcebc --- /dev/null +++ b/ex01/Zombie/Zombie.cpp @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Zombie.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos name = "NULL"; +} + +Zombie::~Zombie() +{ + std::cout << this->name << " has died.... again..." << std::endl; +} + +void Zombie::setName(std::string str) +{ + this->name = str; +} + +void Zombie::announce( void ) +{ + std::cout << this->name << ": BraiiiiiiinnnzzzZ..." << std::endl; +} \ No newline at end of file diff --git a/ex01/Zombie/Zombie.hpp b/ex01/Zombie/Zombie.hpp new file mode 100644 index 0000000..55c8d56 --- /dev/null +++ b/ex01/Zombie/Zombie.hpp @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Zombie.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos + +class Zombie +{ + private: + std::string name; + + public: + Zombie(); + ~Zombie(); + void setName( std::string str ); + void announce( void ); +}; + +Zombie* zombieHorde( int N, std::string name ); + +#endif \ No newline at end of file diff --git a/ex01/Zombie/zombieHorde.cpp b/ex01/Zombie/zombieHorde.cpp new file mode 100644 index 0000000..fd6e476 --- /dev/null +++ b/ex01/Zombie/zombieHorde.cpp @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* zombieHorde.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos + +int main() +{ + std::string str = "Hola"; + std::string *ptr = &str; + std::string &ref = str; + + std::cout << "Imprimiendo direcciones de memoria..."; + std::cout << std::endl << std::endl; + + // Imprimimos las direcciones de memoria + std::cout << &str << std::endl; + std::cout << ptr << std::endl; + std::cout << &ref << std::endl; + + std::cout << std::endl << std::endl; + + + + // Imprimimos los valores + + std::cout << "Imprimiendo los valores de las variables..."; + std::cout << std::endl << std::endl; + + std::cout << str << std::endl; + std::cout << *ptr << std::endl; + std::cout << ref << std::endl; + + return (0); +} \ No newline at end of file diff --git a/ex03/HumanA/HumanA.cpp b/ex03/HumanA/HumanA.cpp new file mode 100644 index 0000000..083a2d7 --- /dev/null +++ b/ex03/HumanA/HumanA.cpp @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* HumanA.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos name << " attacks with their " + << this->weapon.getType() + << std::endl; +} \ No newline at end of file diff --git a/ex03/HumanA/HumanA.hpp b/ex03/HumanA/HumanA.hpp new file mode 100644 index 0000000..1cfdad7 --- /dev/null +++ b/ex03/HumanA/HumanA.hpp @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* HumanA.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos +# include "../Weapon/Weapon.hpp" + +class HumanA +{ + private: + std::string name; + Weapon &weapon; + + public: + HumanA(const std::string &name, Weapon &weapon); + void attack() const; +}; + +#endif diff --git a/ex03/HumanB/HumanB.cpp b/ex03/HumanB/HumanB.cpp new file mode 100644 index 0000000..9d88913 --- /dev/null +++ b/ex03/HumanB/HumanB.cpp @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* HumanB.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos name << " attacks with their " + << this->weapon->getType() + << std::endl; + } else { + std::cout << this->name << " has no weapon" + << std::endl; + } +} + +void HumanB::setWeapon(Weapon &w) +{ + this->weapon = &w; +} \ No newline at end of file diff --git a/ex03/HumanB/HumanB.hpp b/ex03/HumanB/HumanB.hpp new file mode 100644 index 0000000..1d18016 --- /dev/null +++ b/ex03/HumanB/HumanB.hpp @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* HumanB.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos +# include "../Weapon/Weapon.hpp" + +class HumanB +{ + private: + std::string name; + Weapon *weapon; + + public: + HumanB(const std::string &name); + void setWeapon(Weapon &weapon); + void attack() const; +}; + +#endif diff --git a/ex03/Makefile b/ex03/Makefile new file mode 100644 index 0000000..8f8115d --- /dev/null +++ b/ex03/Makefile @@ -0,0 +1,26 @@ +NAME=violence + +SRCS=main.cpp Weapon/Weapon.cpp HumanA/HumanA.cpp HumanB/HumanB.cpp + +OBJS=$(SRCS:.cpp=.o) + +CC=g++ +CFLAGS=-Wall -Wextra -Werror -std=c++98 + +all: $(NAME) + +$(NAME): $(OBJS) + $(CC) $(CFLAGS) $(OBJS) -o $(NAME) + +%.o: %.cpp + $(CC) $(CFLAGS) -c $< -o $@ + +clean: + rm -f $(OBJS) + +fclean: clean + rm -f $(NAME) + +re: fclean all + +.PHONY: all clean fclean re diff --git a/ex03/Weapon/Weapon.cpp b/ex03/Weapon/Weapon.cpp new file mode 100644 index 0000000..e1c1152 --- /dev/null +++ b/ex03/Weapon/Weapon.cpp @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Weapon.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos type); +} + +void Weapon::setType(const std::string &str) +{ + this->type = str; +} + diff --git a/ex03/Weapon/Weapon.hpp b/ex03/Weapon/Weapon.hpp new file mode 100644 index 0000000..5dbd442 --- /dev/null +++ b/ex03/Weapon/Weapon.hpp @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Weapon.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos + +class Weapon +{ + private: + std::string type; + + public: + Weapon(const std::string &type); + const std::string& getType() const; + void setType(const std::string &str); + +}; + +#endif diff --git a/ex03/main.cpp b/ex03/main.cpp new file mode 100644 index 0000000..9112fce --- /dev/null +++ b/ex03/main.cpp @@ -0,0 +1,37 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos +#include + +int main(int argc, char **argv) +{ + std::string filename; + std::string s1; + std::string s2; + std::string line; + + if (argc == 4) + { + filename = argv[1]; + s1 = argv[2]; + s2 = argv[3]; + line = ""; + std::ifstream infile(filename.c_str(), std::ifstream::in); + std::ofstream outfile((filename + ".replace").c_str()); + + if (!infile.is_open() || !outfile.is_open()) + { + std::cout << "Ha ocurrido un error en los archivos" << std::endl; + return (1); + } + + while (std::getline(infile, line)) { + size_t pos = 0; + + while ((pos = line.find(s1, pos)) != std::string::npos) + { + line.erase(pos, s1.length()); + line.insert(pos, s2); + pos += s2.length(); + } + outfile << line << std::endl; + } + + infile.close(); + outfile.close(); + + } else { + std::cout << "Uso: ./sed " << std::endl; + } + + return (0); +} \ No newline at end of file diff --git a/ex05/Harl/Harl.cpp b/ex05/Harl/Harl.cpp new file mode 100644 index 0000000..7c1e681 --- /dev/null +++ b/ex05/Harl/Harl.cpp @@ -0,0 +1,58 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Harl.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos *funcs[i])(); + break ; + } + i++; + } + +} \ No newline at end of file diff --git a/ex05/Harl/Harl.hpp b/ex05/Harl/Harl.hpp new file mode 100644 index 0000000..4d0fe41 --- /dev/null +++ b/ex05/Harl/Harl.hpp @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Harl.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos + +class Harl +{ + private: + void debug( void ); + void info( void ); + void warning( void ); + void error( void ); + + public: + void complain( std::string level ); + +}; + +#endif diff --git a/ex05/Harl/Harl.o b/ex05/Harl/Harl.o new file mode 100644 index 0000000..bb5bb91 Binary files /dev/null and b/ex05/Harl/Harl.o differ diff --git a/ex05/Makefile b/ex05/Makefile new file mode 100644 index 0000000..c944c19 --- /dev/null +++ b/ex05/Makefile @@ -0,0 +1,26 @@ +NAME=harl + +SRCS=main.cpp Harl/Harl.cpp + +OBJS=$(SRCS:.cpp=.o) + +CC=g++ +CFLAGS=-Wall -Wextra -Werror -std=c++98 + +all: $(NAME) + +$(NAME): $(OBJS) + $(CC) $(CFLAGS) $(OBJS) -o $(NAME) + +%.o: %.cpp + $(CC) $(CFLAGS) -c $< -o $@ + +clean: + rm -f $(OBJS) + +fclean: clean + rm -f $(NAME) + +re: fclean all + +.PHONY: all clean fclean re diff --git a/ex05/harl b/ex05/harl new file mode 100755 index 0000000..8b404fd Binary files /dev/null and b/ex05/harl differ diff --git a/ex05/main.cpp b/ex05/main.cpp new file mode 100644 index 0000000..40433d5 --- /dev/null +++ b/ex05/main.cpp @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos