This commit is contained in:
Angel Ortigosa Perez
2025-09-07 10:03:17 +02:00
commit 859690063b
30 changed files with 846 additions and 0 deletions

26
ex00/Makefile Normal file
View File

@@ -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

33
ex00/Zombie/Zombie.cpp Normal file
View File

@@ -0,0 +1,33 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Zombie.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/09/05 16:46:34 by aortigos #+# #+# */
/* Updated: 2025/09/06 01:23:34 by aortigos ### ########.fr */
/* */
/* ************************************************************************** */
#include "Zombie.hpp"
Zombie::Zombie()
{
this->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;
}

34
ex00/Zombie/Zombie.hpp Normal file
View File

@@ -0,0 +1,34 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Zombie.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/09/05 16:44:08 by aortigos #+# #+# */
/* Updated: 2025/09/06 01:22:58 by aortigos ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef ZOMBIE_HPP
# define ZOMBIE_HPP
# include <iostream>
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

22
ex00/Zombie/newZombie.cpp Normal file
View File

@@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* newZombie.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/09/05 17:04:19 by aortigos #+# #+# */
/* Updated: 2025/09/06 01:19:33 by aortigos ### ########.fr */
/* */
/* ************************************************************************** */
#include "Zombie.hpp"
Zombie* newZombie( std::string name )
{
Zombie *z;
z = new Zombie(name);
return (z);
}

View File

@@ -0,0 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* randomChump.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/09/05 17:04:38 by aortigos #+# #+# */
/* Updated: 2025/09/06 01:22:01 by aortigos ### ########.fr */
/* */
/* ************************************************************************** */
#include "Zombie.hpp"
void randomChump( std::string name )
{
Zombie *z;
z = new Zombie(name);
z->announce();
}

28
ex00/main.cpp Normal file
View File

@@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/09/05 16:42:21 by aortigos #+# #+# */
/* Updated: 2025/09/06 01:59:00 by aortigos ### ########.fr */
/* */
/* ************************************************************************** */
#include "Zombie/Zombie.hpp"
int main()
{
Zombie *z;
z = newZombie("Angel");
z->announce();
randomChump("Estudiante42");
delete(z);
return (0);
}

26
ex01/Makefile Normal file
View File

@@ -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

33
ex01/Zombie/Zombie.cpp Normal file
View File

@@ -0,0 +1,33 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Zombie.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/09/05 16:46:34 by aortigos #+# #+# */
/* Updated: 2025/09/06 01:36:29 by aortigos ### ########.fr */
/* */
/* ************************************************************************** */
#include "Zombie.hpp"
Zombie::Zombie()
{
this->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;
}

33
ex01/Zombie/Zombie.hpp Normal file
View File

@@ -0,0 +1,33 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Zombie.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/09/05 16:44:08 by aortigos #+# #+# */
/* Updated: 2025/09/06 01:36:21 by aortigos ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef ZOMBIE_HPP
# define ZOMBIE_HPP
# include <iostream>
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

View File

@@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* zombieHorde.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/09/05 17:04:19 by aortigos #+# #+# */
/* Updated: 2025/09/06 01:47:44 by aortigos ### ########.fr */
/* */
/* ************************************************************************** */
#include "Zombie.hpp"
Zombie* zombieHorde( int N, std::string name )
{
Zombie *z = new Zombie[N];
int i;
i = 0;
while (i < N)
z[i++].setName(name);
return (z);
}

30
ex01/main.cpp Normal file
View File

@@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/09/05 16:42:21 by aortigos #+# #+# */
/* Updated: 2025/09/06 01:48:21 by aortigos ### ########.fr */
/* */
/* ************************************************************************** */
#include "Zombie/Zombie.hpp"
int main()
{
int i;
int N;
Zombie *z;
i = 0;
N = 2;
z = zombieHorde(N, "");
while (i < N)
z[i++].announce();
delete[](z);
return (0);
}

26
ex02/Makefile Normal file
View File

@@ -0,0 +1,26 @@
NAME=memory
SRCS=main.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

43
ex02/main.cpp Normal file
View File

@@ -0,0 +1,43 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/09/06 01:58:01 by aortigos #+# #+# */
/* Updated: 2025/09/06 02:18:56 by aortigos ### ########.fr */
/* */
/* ************************************************************************** */
#include <iostream>
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);
}

23
ex03/HumanA/HumanA.cpp Normal file
View File

@@ -0,0 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* HumanA.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/09/06 02:27:27 by aortigos #+# #+# */
/* Updated: 2025/09/06 02:28:09 by aortigos ### ########.fr */
/* */
/* ************************************************************************** */
#include "HumanA.hpp"
HumanA::HumanA(const std::string &name, Weapon &weapon)
: name(name), weapon(weapon) {}
void HumanA::attack() const
{
std::cout << this->name << " attacks with their "
<< this->weapon.getType()
<< std::endl;
}

31
ex03/HumanA/HumanA.hpp Normal file
View File

@@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* HumanA.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/09/06 02:27:27 by aortigos #+# #+# */
/* Updated: 2025/09/06 02:28:09 by aortigos ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef HUMANA_HPP
# define HUMANA_HPP
# include <iostream>
# include "../Weapon/Weapon.hpp"
class HumanA
{
private:
std::string name;
Weapon &weapon;
public:
HumanA(const std::string &name, Weapon &weapon);
void attack() const;
};
#endif

34
ex03/HumanB/HumanB.cpp Normal file
View File

@@ -0,0 +1,34 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* HumanB.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/09/06 02:27:27 by aortigos #+# #+# */
/* Updated: 2025/09/06 02:28:09 by aortigos ### ########.fr */
/* */
/* ************************************************************************** */
#include "HumanB.hpp"
HumanB::HumanB(const std::string &name)
: name(name), weapon(NULL) {}
void HumanB::attack() const
{
if (weapon)
{
std::cout << this->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;
}

32
ex03/HumanB/HumanB.hpp Normal file
View File

@@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* HumanB.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/09/06 02:27:27 by aortigos #+# #+# */
/* Updated: 2025/09/06 02:28:09 by aortigos ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef HUMANB_HPP
# define HUMANB_HPP
# include <iostream>
# 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

26
ex03/Makefile Normal file
View File

@@ -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

26
ex03/Weapon/Weapon.cpp Normal file
View File

@@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Weapon.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/09/06 02:27:27 by aortigos #+# #+# */
/* Updated: 2025/09/06 02:28:09 by aortigos ### ########.fr */
/* */
/* ************************************************************************** */
#include "Weapon.hpp"
Weapon::Weapon(const std::string &type) : type(type) {}
const std::string& Weapon::getType() const
{
return (this->type);
}
void Weapon::setType(const std::string &str)
{
this->type = str;
}

31
ex03/Weapon/Weapon.hpp Normal file
View File

@@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Weapon.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/09/06 02:27:27 by aortigos #+# #+# */
/* Updated: 2025/09/06 02:28:09 by aortigos ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef WEAPON_HPP
# define WEAPON_HPP
# include <iostream>
class Weapon
{
private:
std::string type;
public:
Weapon(const std::string &type);
const std::string& getType() const;
void setType(const std::string &str);
};
#endif

37
ex03/main.cpp Normal file
View File

@@ -0,0 +1,37 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/09/06 02:18:16 by aortigos #+# #+# */
/* Updated: 2025/09/06 14:29:53 by aortigos ### ########.fr */
/* */
/* ************************************************************************** */
#include "Weapon/Weapon.hpp"
#include "HumanA/HumanA.hpp"
#include "HumanB/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.attack();
jim.setWeapon(club);
jim.attack();
}
return (0);
}

26
ex04/Makefile Normal file
View File

@@ -0,0 +1,26 @@
NAME=sed
SRCS=main.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

58
ex04/main.cpp Normal file
View File

@@ -0,0 +1,58 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/09/06 14:44:18 by aortigos #+# #+# */
/* Updated: 2025/09/06 15:18:39 by aortigos ### ########.fr */
/* */
/* ************************************************************************** */
#include <iostream>
#include <fstream>
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 <filename> <s1> <s2>" << std::endl;
}
return (0);
}

58
ex05/Harl/Harl.cpp Normal file
View File

@@ -0,0 +1,58 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Harl.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/09/06 02:27:27 by aortigos #+# #+# */
/* Updated: 2025/09/06 02:28:09 by aortigos ### ########.fr */
/* */
/* ************************************************************************** */
#include "Harl.hpp"
void Harl::debug( void )
{
std::cout << "I love having extra bacon for my 7XL-double-cheese-triple-pickle-specialketchup burger. I really do!";
std::cout << std::endl;
}
void Harl::info( void )
{
std::cout << "I cannot believe adding extra bacon costs more money. You didnt put enough bacon in my burger! If you did, I wouldnt be asking for more!";
std::cout << std::endl;
}
void Harl::warning( void )
{
std::cout << "I think I deserve to have some extra bacon for free. Ive been coming for years, whereas you started working here just last month.";
std::cout << std::endl;
}
void Harl::error( void )
{
std::cout << "This is unacceptable! I want to speak to the manager now.";
std::cout << std::endl;
}
void Harl::complain( std::string level )
{
int i;
typedef void (Harl::*HarlFunc)();
i = 0;
std::string levels[]= {"DEBUG", "INFO", "WARNING", "ERROR"};
HarlFunc funcs[] = { &Harl::debug, &Harl::info, &Harl::warning, &Harl::error};
while (i < 4)
{
if (level == levels[i])
{
(this->*funcs[i])();
break ;
}
i++;
}
}

32
ex05/Harl/Harl.hpp Normal file
View File

@@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Harl.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/09/06 02:27:27 by aortigos #+# #+# */
/* Updated: 2025/09/06 02:28:09 by aortigos ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef HARL_HPP
# define HARL_HPP
# include <iostream>
class Harl
{
private:
void debug( void );
void info( void );
void warning( void );
void error( void );
public:
void complain( std::string level );
};
#endif

BIN
ex05/Harl/Harl.o Normal file

Binary file not shown.

26
ex05/Makefile Normal file
View File

@@ -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

BIN
ex05/harl Executable file

Binary file not shown.

24
ex05/main.cpp Normal file
View File

@@ -0,0 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/09/06 15:23:33 by aortigos #+# #+# */
/* Updated: 2025/09/06 15:48:52 by aortigos ### ########.fr */
/* */
/* ************************************************************************** */
#include "Harl/Harl.hpp"
int main(int argc, char **argv)
{
Harl h;
if (argc == 2)
h.complain(argv[1]);
else
std::cout << "Uso: ./harl {DEBUG | INFO | WARNING | ERROR}" << std::endl;
return (0);
}

BIN
ex05/main.o Normal file

Binary file not shown.