diff --git a/ex00/Fixed b/ex00/Fixed new file mode 100755 index 0000000..e854d5d Binary files /dev/null and b/ex00/Fixed differ diff --git a/ex00/Fixed.cpp b/ex00/Fixed.cpp new file mode 100644 index 0000000..59fc2d1 --- /dev/null +++ b/ex00/Fixed.cpp @@ -0,0 +1,41 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Fixed.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: adjoly +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/11/12 21:14:55 by adjoly #+# #+# */ +/* Updated: 2024/11/12 21:52:16 by adjoly ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "Fixed.hpp" +#include + +Fixed::Fixed(void) : _number(0) { + std::cout << "Default constructor called" << std::endl; +} + +Fixed::Fixed(const Fixed& cpy) { + std::cout << "Copy constructor called" << std::endl; + _number = cpy.getRawBits(); +} + +Fixed::~Fixed(void) { + std::cout << "Destructor called" << std::endl; +} + +Fixed &Fixed::operator=(const Fixed& cpy) { + std::cout << "Copy assignment operator called" << std::endl; + if (this != &cpy) + _number = cpy.getRawBits(); + return (*this); +} + +int Fixed::getRawBits(void) const { + std::cout << "getRawBits member function called" << std::endl; + return (_number); +} + +void Fixed::setRawBits(int const raw) { _number = raw; } diff --git a/ex00/Fixed.hpp b/ex00/Fixed.hpp new file mode 100644 index 0000000..d24e84c --- /dev/null +++ b/ex00/Fixed.hpp @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Fixed.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: adjoly +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/11/09 19:23:08 by adjoly #+# #+# */ +/* Updated: 2024/11/12 21:49:21 by adjoly ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#pragma once + +class Fixed { + private: + int _number; + static const int _factBit = 8; + public: + Fixed(void); + Fixed(const Fixed& cpy); + Fixed& operator=(const Fixed&); + + ~Fixed(void); + + int getRawBits( void ) const; + void setRawBits( int const raw ); +}; diff --git a/ex00/Makefile b/ex00/Makefile new file mode 100644 index 0000000..c333ff1 --- /dev/null +++ b/ex00/Makefile @@ -0,0 +1,55 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: adjoly +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2024/10/25 16:09:27 by adjoly #+# #+# # +# Updated: 2024/11/12 21:50:23 by adjoly ### ########.fr # +# # +# **************************************************************************** # + +NAME = Fixed + +CC = c++ + +OBJSDIR = obj/ + +SRCS = main.cpp \ + Fixed.cpp + +OBJS = $(addprefix $(OBJSDIR), $(SRCS:.cpp=.o)) + +FLAGS = -Wall -Werror -Wextra -std=c++98 -MMD -MP + +RED = \033[0;31m +GREEN = \033[0;32m +YELLOW = \033[1;33m +PURPLE = \e[0;35m +NC = \033[0m +DELETE = \x1B[2K\r + +all: $(NAME) + +$(NAME): $(OBJS) + @$(CC) $(FLAGS) $(OBJS) -o $(NAME) + @printf "$(YELLOW)「✨」($(NAME)) Program compiled\n" + +$(OBJSDIR)%.o: %.cpp + @mkdir -p $(@D) + @$(CC) $(FLAGS) -c $< -o $@ + @printf "$(DELETE)$(GREEN)「🔨」($<) Object compiled\n" + +clean: + @rm -f $(OBJS) + @printf "$(DELETE)$(RED)「🗑️」($(OBJS)) Object deleted\n" + +fclean: clean + @rm -f $(NAME) + @rm -Rf $(OBJSDIR) + @printf "$(RED)「🗑️」($(NAME)) Program deleted\n" + +re: fclean all + +.PHONY: clean fclean all re diff --git a/ex00/main.cpp b/ex00/main.cpp new file mode 100644 index 0000000..7d05b6c --- /dev/null +++ b/ex00/main.cpp @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: adjoly +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/11/09 19:23:26 by adjoly #+# #+# */ +/* Updated: 2024/11/12 21:14:50 by adjoly ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "Fixed.hpp" +#include + +int main( void ) { + Fixed a; + Fixed b( a ); + Fixed c; + c = b; + std::cout << a.getRawBits() << std::endl; + std::cout << b.getRawBits() << std::endl; + std::cout << c.getRawBits() << std::endl; + return 0; +}