This commit is contained in:
2024-03-02 20:37:01 +01:00
parent c3a7af50b0
commit d36af81adb
13 changed files with 591 additions and 12 deletions

60
cpp07/ex00/Makefile Normal file
View File

@@ -0,0 +1,60 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2023/12/27 20:57:42 by fgras-ca #+# #+# #
# Updated: 2024/03/02 19:20:09 by fgras-ca ### ########.fr #
# #
# **************************************************************************** #
LOGO = @echo "🅻🅰🅳🅴🅱🅴🆉🅴";\
DEF_COLOR = \033[0m
GRAY = \033[0;90m
RED = \033[0;91m
GREEN = \033[0;92m
YELLOW = \033[0;93m
BLUE = \033[0;94m
MAGENTA = \033[0;95m
CYAN = \033[0;96m
WHITE = \033[0;97m
ORANGE = \033[38;5;214m
NAME = whatever
SRC = main.cpp \
CC = c++
CFLAGS = -Wall -Werror -Wextra -std=c++98
RM = rm -f
OBJS = ${SRC:.cpp=.o}
all : $(NAME)
%.o: %.cpp
$(CC) $(CFLAGS) -c $< -o $@
$(NAME) : $(OBJS)
@echo "$(RED)Compilation fixed... $(DEF_COLOR)"
$(CC) $(CFLAGS) $(OBJS) -g -o $(NAME)
@echo "$(GREEN)Compilation complete. $(ORANGE)Type "./whatever" to execute the program!!$(DEF_COLOR)"
$(LOGO)
clean :
@echo "$(RED)Deleating files objects... $(DEF_COLOR)"
$(RM) $(OBJS)
@echo "$(GREEN)files deleted!! $(DEF_COLOR)"
$(LOGO)
fclean : clean
@echo "$(RED)Delete program name... $(DEF_COLOR)"
$(RM) $(NAME)
@echo "$(GREEN)File program deleted!! $(DEF_COLOR)"
$(LOGO)
re : fclean all
.PHONY : all clean fclean re

33
cpp07/ex00/main.cpp Normal file
View File

@@ -0,0 +1,33 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/02 19:06:16 by fgras-ca #+# #+# */
/* Updated: 2024/03/02 19:13:43 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#include <iostream>
#include "whatever.hpp"
int main()
{
int a = 2;
int b = 3;
::swap(a, b);
std::cout << RED << "a = " << RESET << a << RED << ", b = " << RESET << b << std::endl;
std::cout << GREEN << "min( a, b ) = " << RESET << ::min(a, b) << std::endl;
std::cout << MAGENTA << "max( a, b ) = " << RESET << ::max(a, b) << std::endl;
std::string c = "chaine1";
std::string d = "chaine2";
::swap(c, d);
std::cout << RED << "c = " << RESET << c << RED << ", d = " << RESET << d << std::endl;
std::cout << GREEN << "min( c, d ) = " << RESET << ::min(c, d) << std::endl;
std::cout << MAGENTA << "max( c, d ) = " << RESET << ::max(c, d) << std::endl;
return (0);
}

46
cpp07/ex00/whatever.hpp Normal file
View File

@@ -0,0 +1,46 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* whatever.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/02 18:56:24 by fgras-ca #+# #+# */
/* Updated: 2024/03/02 19:05:10 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef WHATEVER_HPP
#define WHATEVER_HPP
#define RESET "\033[0m"
#define BLACK "\033[30m"
#define RED "\033[31m"
#define GREEN "\033[32m"
#define YELLOW "\033[33m"
#define BLUE "\033[34m"
#define MAGENTA "\033[35m"
#define CYAN "\033[36m"
#define WHITE "\033[37m"
template<typename T>
void swap(T& a, T& b)
{
T temp = a;
a = b;
b = temp;
}
template<typename T>
T const &min(T const &a, T const &b)
{
return (a < b) ? a : b;
}
template<typename T>
T const &max(T const &a, T const &b)
{
return (a > b) ? a : b;
}
#endif