ex00 done

This commit is contained in:
2026-03-21 15:52:07 +01:00
commit f05f057399
3 changed files with 118 additions and 0 deletions

42
ex00/Makefile Normal file
View File

@@ -0,0 +1,42 @@
NAME = swap
SRC = main.cpp \
OBJ = $(SRC:.cpp=.o)
CC = c++
CFLAGS = -Wall -Wextra -Werror -std=c++98
GREEN = \033[0;32m
RED = \033[0;31m
RESET = \033[0m
TOTAL := $(words $(SRC))
COUNT = 0
all: $(NAME)
$(NAME): $(OBJ)
@rm -f .build_start
@$(CC) $(CFLAGS) $(OBJ) -o $(NAME)
@printf "\n$(GREEN)✔ Listo (100%%)\n$(RESET)"
%.o: %.cpp
@if [ ! -f .build_start ]; then printf "$(GREEN)Compilando archivos...\n$(RESET)"; touch .build_start; fi
@$(eval COUNT = $(shell echo $$(($(COUNT)+1))))
@PERCENT=$$(($(COUNT)*100/$(TOTAL))); \
BAR=$$(printf "%0.s#" $$(seq 1 $$((PERCENT/5)))); \
SPACE=$$(printf "%0.s " $$(seq 1 $$((20-PERCENT/5)))); \
printf "\r [$$BAR$$SPACE] %3d%% (%d/%d) $< " $$PERCENT $(COUNT) $(TOTAL)
@$(CC) $(CFLAGS) -c $< -o $@
clean:
@printf "$(RED)Eliminando...\n$(RESET)"
@rm -f $(OBJ)
fclean: clean
@rm -f $(NAME)
re: fclean all
.PHONY: all clean fclean re

31
ex00/main.cpp Normal file
View File

@@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/03/21 15:51:20 by aortigos #+# #+# */
/* Updated: 2026/03/21 15:51:47 by aortigos ### ########.fr */
/* */
/* ************************************************************************** */
#include "whatever.hpp"
int main( void ) {
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);
}

45
ex00/whatever.hpp Normal file
View File

@@ -0,0 +1,45 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* whatever.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/03/21 15:44:59 by aortigos #+# #+# */
/* Updated: 2026/03/21 15:48:28 by aortigos ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef SWAP_HPP
# define SWAP_HPP
# include <iostream>
template <typename T>
void swap(T &a, T &b)
{
T tmp;
tmp = a;
a = b;
b = tmp;
}
template <typename T>
T min(T const &a, T const &b)
{
if (a < b)
return (a);
return (b);
}
template <typename T>
T max(T const &a, T const &b)
{
if (a > b)
return (a);
return (b);
}
#endif