diff --git a/ex00/Makefile b/ex00/Makefile index d3ebf41..c2343f7 100644 --- a/ex00/Makefile +++ b/ex00/Makefile @@ -1,6 +1,6 @@ NAME = swap -SRC = main.cpp \ +SRC = main.cpp OBJ = $(SRC:.cpp=.o) diff --git a/ex01/Makefile b/ex01/Makefile index 919ddf8..0f42348 100644 --- a/ex01/Makefile +++ b/ex01/Makefile @@ -1,6 +1,6 @@ NAME = iter -SRC = main.cpp \ +SRC = main.cpp OBJ = $(SRC:.cpp=.o) diff --git a/ex02/.build_start b/ex02/.build_start new file mode 100644 index 0000000..e69de29 diff --git a/ex02/Array/Array.hpp b/ex02/Array/Array.hpp new file mode 100644 index 0000000..fd1ee32 --- /dev/null +++ b/ex02/Array/Array.hpp @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Array.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2026/03/21 17:04:01 by aortigos #+# #+# */ +/* Updated: 2026/03/21 17:04:01 by aortigos ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef ARRAY_HPP + +# define ARRAY_HPP + +# include + +# include "Array.tpp" + +#endif diff --git a/ex02/Array/Array.tpp b/ex02/Array/Array.tpp new file mode 100644 index 0000000..966e095 --- /dev/null +++ b/ex02/Array/Array.tpp @@ -0,0 +1,54 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Array.tpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos +class Array +{ + private: + T *element; + unsigned int size; + public: + Array() + { + new T[n](); + } + + Array(const Array &other) + { + if (this != other) + { + this->element = other.element; + this->size = other.size; + } + return (*this); + } + + Array& operator=(const Array &other) + { + this = other; + } + + ~Array() + { + delete[] T; + } + + Array(unsigned int n) + { + this->size = n; + } + + int size() + { + return (this->size); + } +}; diff --git a/ex02/Makefile b/ex02/Makefile new file mode 100644 index 0000000..8481fef --- /dev/null +++ b/ex02/Makefile @@ -0,0 +1,42 @@ +NAME = array + +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 diff --git a/ex02/main.cpp b/ex02/main.cpp new file mode 100644 index 0000000..11191e8 --- /dev/null +++ b/ex02/main.cpp @@ -0,0 +1,64 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: aortigos numbers(MAX_VAL); + int* mirror = new int[MAX_VAL]; + srand(time(NULL)); + for (int i = 0; i < MAX_VAL; i++) + { + const int value = rand(); + numbers[i] = value; + mirror[i] = value; + } + //SCOPE + { + Array tmp = numbers; + Array test(tmp); + } + + for (int i = 0; i < MAX_VAL; i++) + { + if (mirror[i] != numbers[i]) + { + std::cerr << "didn't save the same value!!" << std::endl; + return 1; + } + } + try + { + numbers[-2] = 0; + } + catch(const std::exception& e) + { + std::cerr << e.what() << '\n'; + } + try + { + numbers[MAX_VAL] = 0; + } + catch(const std::exception& e) + { + std::cerr << e.what() << '\n'; + } + + for (int i = 0; i < MAX_VAL; i++) + { + numbers[i] = rand(); + } + delete [] mirror;// + return 0; +} \ No newline at end of file