bastien před 4 měsíci
rodič
revize
e7fc067764

binární
Module_02/ex00/.objects/Fixed.class.o


binární
Module_02/ex00/.objects/main.o


+ 50 - 0
Module_02/ex00/Makefile

@@ -0,0 +1,50 @@
+#******************************************************************************#
+#                                                                              #
+#                                                         :::      ::::::::    #
+#    Makefile                                           :+:      :+:    :+:    #
+#                                                     +:+ +:+         +:+      #
+#    By: bchanot <bchanot@students.42.fr>           +#+  +:+       +#+         #
+#                                                 +#+#+#+#+#+   +#+            #
+#    Created: 2016/07/24 00:00:08 by bchanot           #+#    #+#              #
+#*   Updated: 2025/07/17 15:11:48 by bchanot          ###   ########.fr       *#
+#                                                                              #
+#******************************************************************************#
+
+NAME = ex00
+MAKE_LIBS = make --no-print-directory
+SRCS_DIR = srcs/
+OBJS_DIR = .objects/
+CC = g++ -Wall -Wextra -Werror -g
+INC = -I./includes
+FILES = main Fixed.class
+SRCS = $(FILES)
+OBJS = $(addprefix $(OBJS_DIR), $(addsuffix .o, $(SRCS)))
+RED = \033[1;31m
+BLUE = \033[1;34m
+CYAN = \033[0;36m
+GREEN = \033[1;32m
+YELLOW = \033[1;33m
+EOC = \033[0m
+
+all: $(NAME)
+
+$(NAME): $(OBJS)
+	@echo -e "$(GREEN)Objects created.$(EOC)"
+	@$(CC) $(OBJS) $(INC) -o $(NAME)
+	@echo -e "$(GREEN)Compilation complete.$(EOC)"
+
+$(OBJS_DIR)%.o: $(SRCS_DIR)%.cpp
+	@mkdir -p $(dir $@)
+	$(CC) -c $< $(INC) -o $@
+
+clean:
+	@echo -e "$(RED)Deleting objects.$(EOC)"
+	@/bin/rm -rf $(OBJS_DIR)
+
+fclean: clean
+	@echo -e "$(RED)Deleting binary.$(EOC)"
+	@/bin/rm -rf $(NAME)
+
+re: fclean all
+
+.PHONY: all clean fclean re

binární
Module_02/ex00/ex00


+ 7 - 6
Module_02/ex00/includes/Fixed.class.hpp

@@ -6,7 +6,7 @@
 /*   By: bchanot <bchanot@gmail.fr>                 +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2025/07/16 15:46:39 by bchanot           #+#    #+#             */
-/*   Updated: 2025/07/16 16:14:21 by bchanot          ###   ########.fr       */
+/*   Updated: 2025/07/17 15:24:37 by bchanot          ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -19,13 +19,14 @@ class	Fixed {
 		Fixed(Fixed const &src);
 		~Fixed(void);
 
-		int					getRawBits(void) const;
-		void				setRawBits(int const raw);
+		int			getRawBits(void) const;
+		void		setRawBits(int const raw);
 
-		Fixed				&operator=(Fixed const &rhs);
+		Fixed		&operator=(Fixed const &rhs);
 
 	private:
-		int					_value;
+		int			_value;
 		int const	_integer;
 };
-#ifndef
+
+#endif

+ 14 - 5
Module_02/ex00/srcs/Fixed.class.cpp

@@ -6,7 +6,7 @@
 /*   By: bchanot <bchanot@gmail.fr>                 +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2025/07/16 16:07:34 by bchanot           #+#    #+#             */
-/*   Updated: 2025/07/16 16:43:03 by bchanot          ###   ########.fr       */
+/*   Updated: 2025/07/17 15:33:54 by bchanot          ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -18,7 +18,7 @@ Fixed::Fixed(void) : _value(0), _integer(8) {
 	return ;
 }
 
-Fixed::Fixed(Fixed const &src) {
+Fixed::Fixed(Fixed const &src) : _integer(8) {
 	*this = src;
 	std::cout << "Copy constructor called" << std::endl;
 	return ;
@@ -29,10 +29,19 @@ Fixed::~Fixed(void) {
 	return ;
 }
 
-int	getRawBits(void) const {
+int	Fixed::getRawBits(void) const {
+	std::cout << "getRawBits member function called" << std::endl;
 	return this->_value;
 }
 
-void	setRawBits(int const raw)
+void	Fixed::setRawBits(int const raw) {
+	std::cout << "setRawBits member function called" << std::endl;
+	this->_value = raw;
+	return ;
+}
 
-		Fixed				&operator=(Fixed const &rhs);
+Fixed				&Fixed::operator=(Fixed const &rhs) {
+	std::cout << "Copy assignment operator called" << std::endl;
+	this->_value = rhs.getRawBits();
+	return *this;
+}

+ 28 - 0
Module_02/ex00/srcs/main.cpp

@@ -0,0 +1,28 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   main.cpp                                           :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: bchanot <bchanot@gmail.fr>                 +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2025/07/17 15:10:40 by bchanot           #+#    #+#             */
+/*   Updated: 2025/07/17 15:11:09 by bchanot          ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "Fixed.class.hpp"
+
+#include <iostream>
+
+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;
+}

binární
Module_02/ex01/.objects/Fixed.class.o


binární
Module_02/ex01/.objects/main.o


+ 50 - 0
Module_02/ex01/Makefile

@@ -0,0 +1,50 @@
+#******************************************************************************#
+#                                                                              #
+#                                                         :::      ::::::::    #
+#    Makefile                                           :+:      :+:    :+:    #
+#                                                     +:+ +:+         +:+      #
+#    By: bchanot <bchanot@students.42.fr>           +#+  +:+       +#+         #
+#                                                 +#+#+#+#+#+   +#+            #
+#    Created: 2016/07/24 00:00:08 by bchanot           #+#    #+#              #
+#*   Updated: 2025/07/17 15:11:48 by bchanot          ###   ########.fr       *#
+#                                                                              #
+#******************************************************************************#
+
+NAME = ex00
+MAKE_LIBS = make --no-print-directory
+SRCS_DIR = srcs/
+OBJS_DIR = .objects/
+CC = g++ -Wall -Wextra -Werror -g
+INC = -I./includes
+FILES = main Fixed.class
+SRCS = $(FILES)
+OBJS = $(addprefix $(OBJS_DIR), $(addsuffix .o, $(SRCS)))
+RED = \033[1;31m
+BLUE = \033[1;34m
+CYAN = \033[0;36m
+GREEN = \033[1;32m
+YELLOW = \033[1;33m
+EOC = \033[0m
+
+all: $(NAME)
+
+$(NAME): $(OBJS)
+	@echo -e "$(GREEN)Objects created.$(EOC)"
+	@$(CC) $(OBJS) $(INC) -o $(NAME)
+	@echo -e "$(GREEN)Compilation complete.$(EOC)"
+
+$(OBJS_DIR)%.o: $(SRCS_DIR)%.cpp
+	@mkdir -p $(dir $@)
+	$(CC) -c $< $(INC) -o $@
+
+clean:
+	@echo -e "$(RED)Deleting objects.$(EOC)"
+	@/bin/rm -rf $(OBJS_DIR)
+
+fclean: clean
+	@echo -e "$(RED)Deleting binary.$(EOC)"
+	@/bin/rm -rf $(NAME)
+
+re: fclean all
+
+.PHONY: all clean fclean re

binární
Module_02/ex01/ex00


+ 40 - 0
Module_02/ex01/includes/Fixed.class.hpp

@@ -0,0 +1,40 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   Fixed.class.hpp                                    :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: bchanot <bchanot@gmail.fr>                 +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2025/07/16 15:46:39 by bchanot           #+#    #+#             */
+/*   Updated: 2025/07/17 17:16:03 by bchanot          ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#ifndef FIXED_CLASS_H
+# define FIXED_CLASS_H
+
+#include <iostream>
+
+class	Fixed {
+	public:
+		Fixed(void);
+		Fixed(Fixed const &src);
+		Fixed(int const num);
+		Fixed(float const num);
+		~Fixed(void);
+
+		int			getRawBits(void) const;
+		void		setRawBits(int const raw);
+		float		toFloat(void) const;
+		int			toInt(void) const;
+
+		Fixed		&operator=(Fixed const &rhs);
+
+	private:
+		int			_value;
+		static int const	_frac = 8;
+};
+
+std::ostream	&operator<<(std::ostream &o, Fixed const &i);
+
+#endif

+ 71 - 0
Module_02/ex01/srcs/Fixed.class.cpp

@@ -0,0 +1,71 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   Fixed.class.cpp                                    :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: bchanot <bchanot@gmail.fr>                 +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2025/07/16 16:07:34 by bchanot           #+#    #+#             */
+/*   Updated: 2025/07/17 17:13:55 by bchanot          ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "Fixed.class.hpp"
+#include <iostream>
+#include <cmath>
+
+Fixed::Fixed(void) : _value(0) {
+	std::cout << "Default constructor called" << std::endl;
+	return ;
+}
+
+Fixed::Fixed(int const num) : _value((int)roundf(num * (1 << _frac))){
+	std::cout << "Int constructor called" << std::endl;
+	return ;
+}
+
+Fixed::Fixed(float const num) : _value((float)roundf(num * (1 << _frac))){
+	std::cout << "Float constructor called" << std::endl;
+	return ;
+}
+
+Fixed::Fixed(Fixed const &src) {
+	*this = src;
+	std::cout << "Copy constructor called" << std::endl;
+	return ;
+}
+
+Fixed::~Fixed(void) {
+	std::cout << "Destructor called" << std::endl;
+	return ;
+}
+
+int	Fixed::getRawBits(void) const {
+	std::cout << "getRawBits member function called" << std::endl;
+	return this->_value;
+}
+
+void	Fixed::setRawBits(int const raw) {
+	std::cout << "setRawBits member function called" << std::endl;
+	this->_value = raw;
+	return ;
+}
+
+Fixed				&Fixed::operator=(Fixed const &rhs) {
+	std::cout << "Copy assignment operator called" << std::endl;
+	this->_value = rhs.getRawBits();
+	return *this;
+}
+
+float		Fixed::toFloat(void) const {
+	return (float(this->_value) / float(1 << this->_frac));
+}
+
+int			Fixed::toInt(void) const {
+	return (int(this->_value) / int(1 << this->_frac));
+}
+
+std::ostream	&operator<<(std::ostream &o, Fixed const &i) {
+	o << i.toFloat();
+	return o;
+}

+ 33 - 0
Module_02/ex01/srcs/main.cpp

@@ -0,0 +1,33 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   main.cpp                                           :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: bchanot <bchanot@gmail.fr>                 +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2025/07/17 15:10:40 by bchanot           #+#    #+#             */
+/*   Updated: 2025/07/17 17:36:23 by bchanot          ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "Fixed.class.hpp"
+
+#include <iostream>
+
+int main( void ) {
+	Fixed a;
+	Fixed const b( 10 );
+	Fixed const c( 42.42f );
+	Fixed const d( b );
+
+	a = Fixed( 1234.4321f );
+	std::cout << "a is " << a << std::endl;
+	std::cout << "b is " << b << std::endl;
+	std::cout << "c is " << c << std::endl;
+	std::cout << "d is " << d << std::endl;
+	std::cout << "a is " << a.toInt() << " as integer" << std::endl;
+	std::cout << "b is " << b.toInt() << " as integer" << std::endl;
+	std::cout << "c is " << c.toInt() << " as integer" << std::endl;
+	std::cout << "d is " << d.toInt() << " as integer" << std::endl;
+	return 0;
+}

binární
Module_02/ex02/.objects/Fixed.class.o


binární
Module_02/ex02/.objects/main.o


+ 50 - 0
Module_02/ex02/Makefile

@@ -0,0 +1,50 @@
+#******************************************************************************#
+#                                                                              #
+#                                                         :::      ::::::::    #
+#    Makefile                                           :+:      :+:    :+:    #
+#                                                     +:+ +:+         +:+      #
+#    By: bchanot <bchanot@students.42.fr>           +#+  +:+       +#+         #
+#                                                 +#+#+#+#+#+   +#+            #
+#    Created: 2016/07/24 00:00:08 by bchanot           #+#    #+#              #
+#*   Updated: 2025/07/17 15:11:48 by bchanot          ###   ########.fr       *#
+#                                                                              #
+#******************************************************************************#
+
+NAME = ex00
+MAKE_LIBS = make --no-print-directory
+SRCS_DIR = srcs/
+OBJS_DIR = .objects/
+CC = g++ -Wall -Wextra -Werror -g
+INC = -I./includes
+FILES = main Fixed.class
+SRCS = $(FILES)
+OBJS = $(addprefix $(OBJS_DIR), $(addsuffix .o, $(SRCS)))
+RED = \033[1;31m
+BLUE = \033[1;34m
+CYAN = \033[0;36m
+GREEN = \033[1;32m
+YELLOW = \033[1;33m
+EOC = \033[0m
+
+all: $(NAME)
+
+$(NAME): $(OBJS)
+	@echo -e "$(GREEN)Objects created.$(EOC)"
+	@$(CC) $(OBJS) $(INC) -o $(NAME)
+	@echo -e "$(GREEN)Compilation complete.$(EOC)"
+
+$(OBJS_DIR)%.o: $(SRCS_DIR)%.cpp
+	@mkdir -p $(dir $@)
+	$(CC) -c $< $(INC) -o $@
+
+clean:
+	@echo -e "$(RED)Deleting objects.$(EOC)"
+	@/bin/rm -rf $(OBJS_DIR)
+
+fclean: clean
+	@echo -e "$(RED)Deleting binary.$(EOC)"
+	@/bin/rm -rf $(NAME)
+
+re: fclean all
+
+.PHONY: all clean fclean re

binární
Module_02/ex02/ex00


+ 59 - 0
Module_02/ex02/includes/Fixed.class.hpp

@@ -0,0 +1,59 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   Fixed.class.hpp                                    :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: bchanot <bchanot@gmail.fr>                 +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2025/07/16 15:46:39 by bchanot           #+#    #+#             */
+/*   Updated: 2025/07/17 18:52:26 by bchanot          ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#ifndef FIXED_CLASS_H
+# define FIXED_CLASS_H
+
+#include <iostream>
+
+class	Fixed {
+	public:
+		Fixed(void);
+		Fixed(Fixed const &src);
+		Fixed(int const num);
+		Fixed(float const num);
+		~Fixed(void);
+
+		int			getRawBits(void) const;
+		void		setRawBits(int const raw);
+		float		toFloat(void) const;
+		int			toInt(void) const;
+
+		Fixed		&operator=(Fixed const &rhs);
+		bool		operator!=(Fixed const &rhs) const;
+		bool		operator==(Fixed const &rhs) const;
+		bool		operator<=(Fixed const &rhs) const;
+		bool		operator>=(Fixed const &rhs) const;
+		bool		operator<(Fixed const &rhs) const;
+		bool		operator>(Fixed const &rhs) const;
+		Fixed		operator+(Fixed const &rhs) const;
+		Fixed		operator-(Fixed const &rhs) const;
+		Fixed		operator*(Fixed const &rhs) const;
+		Fixed		operator/(Fixed const &rhs) const;
+		Fixed		&operator++();
+		Fixed		&operator--();
+		Fixed		operator++(int);
+		Fixed		operator--(int);
+
+		static const Fixed	&min(Fixed const &left, Fixed const &right);
+		static Fixed	&min(Fixed &left, Fixed &right);
+		static const Fixed	&max(Fixed const &left, Fixed const &right);
+		static Fixed	&max(Fixed &left, Fixed &right);
+
+	private:
+		int			_value;
+		static int const	_frac = 8;
+};
+
+std::ostream	&operator<<(std::ostream &o, Fixed const &i);
+
+#endif

+ 152 - 0
Module_02/ex02/srcs/Fixed.class.cpp

@@ -0,0 +1,152 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   Fixed.class.cpp                                    :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: bchanot <bchanot@gmail.fr>                 +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2025/07/16 16:07:34 by bchanot           #+#    #+#             */
+/*   Updated: 2025/07/17 18:55:07 by bchanot          ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "Fixed.class.hpp"
+#include <iostream>
+#include <cmath>
+
+Fixed::Fixed(void) : _value(0) {
+	std::cout << "Default constructor called" << std::endl;
+	return ;
+}
+
+Fixed::Fixed(int const num) : _value((int)roundf(num * (1 << _frac))){
+	std::cout << "Int constructor called" << std::endl;
+	return ;
+}
+
+Fixed::Fixed(float const num) : _value((float)roundf(num * (1 << _frac))){
+	std::cout << "Float constructor called" << std::endl;
+	return ;
+}
+
+Fixed::Fixed(Fixed const &src) {
+	*this = src;
+	std::cout << "Copy constructor called" << std::endl;
+	return ;
+}
+
+Fixed::~Fixed(void) {
+	std::cout << "Destructor called" << std::endl;
+	return ;
+}
+
+int	Fixed::getRawBits(void) const {
+	std::cout << "getRawBits member function called" << std::endl;
+	return this->_value;
+}
+
+void	Fixed::setRawBits(int const raw) {
+	std::cout << "setRawBits member function called" << std::endl;
+	this->_value = raw;
+	return ;
+}
+
+Fixed				&Fixed::operator=(Fixed const &rhs) {
+	std::cout << "Copy assignment operator called" << std::endl;
+	this->_value = rhs.getRawBits();
+	return *this;
+}
+
+bool		Fixed::operator==(Fixed const &rhs) const {
+	return this->toFloat() == rhs.toFloat();
+}
+
+bool		Fixed::operator!=(Fixed const &rhs) const {
+	return this->toFloat() != rhs.toFloat();
+}
+
+bool		Fixed::operator<=(Fixed const &rhs) const {
+	return this->toFloat() <= rhs.toFloat();
+}
+
+bool		Fixed::operator>=(Fixed const &rhs) const {
+	return this->toFloat() >= rhs.toFloat();
+}
+
+bool		Fixed::operator<(Fixed const &rhs) const {
+	return this->toFloat() < rhs.toFloat();
+}
+
+bool		Fixed::operator>(Fixed const &rhs) const {
+	return this->toFloat() > rhs.toFloat();
+}
+
+Fixed		Fixed::operator+(Fixed const &rhs) const {
+	return Fixed::toFloat() + rhs.toFloat();
+}
+
+Fixed		Fixed::operator-(Fixed const &rhs) const {
+	return Fixed::toFloat() - rhs.toFloat();
+}
+
+Fixed		Fixed::operator*(Fixed const &rhs) const {
+	return Fixed::toFloat() * rhs.toFloat();
+}
+
+Fixed		Fixed::operator/(Fixed const &rhs) const {
+	return Fixed::toFloat() / rhs.toFloat();
+}
+
+Fixed		&Fixed::operator++(void) {
+	this->_value++;
+	return *this;
+}
+
+Fixed		&Fixed::operator--(void) {
+	this->_value--;
+	return *this;
+}
+
+Fixed		Fixed::operator++(int) {
+	Fixed	other(*this);
+
+	operator++();
+	return other;
+}
+
+Fixed		Fixed::operator--(int) {
+	Fixed	other(*this);
+
+	operator--();
+	return other;
+}
+
+
+const Fixed	&Fixed::min(Fixed const &left, Fixed const &right) {
+	return left < right ? left : right;
+}
+
+Fixed	&Fixed::min(Fixed &left, Fixed &right) {
+	return left < right ? left : right;
+}
+
+const Fixed	&Fixed::max(Fixed const &left, Fixed const &right) {
+	return left > right ? left : right;
+}
+
+Fixed	&Fixed::max(Fixed &left, Fixed &right) {
+	return left > right ? left : right;
+}
+
+float		Fixed::toFloat(void) const {
+	return (float(this->_value) / float(1 << this->_frac));
+}
+
+int			Fixed::toInt(void) const {
+	return (int(this->_value) / int(1 << this->_frac));
+}
+
+std::ostream	&operator<<(std::ostream &o, Fixed const &i) {
+	o << i.toFloat();
+	return o;
+}

+ 28 - 0
Module_02/ex02/srcs/main.cpp

@@ -0,0 +1,28 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   main.cpp                                           :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: bchanot <bchanot@gmail.fr>                 +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2025/07/17 15:10:40 by bchanot           #+#    #+#             */
+/*   Updated: 2025/07/17 18:53:18 by bchanot          ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "Fixed.class.hpp"
+#include <iostream>
+
+int main( void ) {
+	Fixed a;
+	Fixed const b( Fixed( 5.05f ) * Fixed( 2 ) );
+
+	std::cout << a << std::endl;
+	std::cout << ++a << std::endl;
+	std::cout << a << std::endl;
+	std::cout << a++ << std::endl;
+	std::cout << a << std::endl;
+	std::cout << b << std::endl;
+	std::cout << Fixed::max( a, b ) << std::endl;
+	return 0;
+}

binární
Module_02/ex03/.objects/Fixed.class.o


binární
Module_02/ex03/.objects/main.o


+ 50 - 0
Module_02/ex03/Makefile

@@ -0,0 +1,50 @@
+#******************************************************************************#
+#                                                                              #
+#                                                         :::      ::::::::    #
+#    Makefile                                           :+:      :+:    :+:    #
+#                                                     +:+ +:+         +:+      #
+#    By: bchanot <bchanot@students.42.fr>           +#+  +:+       +#+         #
+#                                                 +#+#+#+#+#+   +#+            #
+#    Created: 2016/07/24 00:00:08 by bchanot           #+#    #+#              #
+#*   Updated: 2025/07/17 15:11:48 by bchanot          ###   ########.fr       *#
+#                                                                              #
+#******************************************************************************#
+
+NAME = ex00
+MAKE_LIBS = make --no-print-directory
+SRCS_DIR = srcs/
+OBJS_DIR = .objects/
+CC = g++ -Wall -Wextra -Werror -g
+INC = -I./includes
+FILES = main Fixed.class
+SRCS = $(FILES)
+OBJS = $(addprefix $(OBJS_DIR), $(addsuffix .o, $(SRCS)))
+RED = \033[1;31m
+BLUE = \033[1;34m
+CYAN = \033[0;36m
+GREEN = \033[1;32m
+YELLOW = \033[1;33m
+EOC = \033[0m
+
+all: $(NAME)
+
+$(NAME): $(OBJS)
+	@echo -e "$(GREEN)Objects created.$(EOC)"
+	@$(CC) $(OBJS) $(INC) -o $(NAME)
+	@echo -e "$(GREEN)Compilation complete.$(EOC)"
+
+$(OBJS_DIR)%.o: $(SRCS_DIR)%.cpp
+	@mkdir -p $(dir $@)
+	$(CC) -c $< $(INC) -o $@
+
+clean:
+	@echo -e "$(RED)Deleting objects.$(EOC)"
+	@/bin/rm -rf $(OBJS_DIR)
+
+fclean: clean
+	@echo -e "$(RED)Deleting binary.$(EOC)"
+	@/bin/rm -rf $(NAME)
+
+re: fclean all
+
+.PHONY: all clean fclean re

binární
Module_02/ex03/ex00


+ 59 - 0
Module_02/ex03/includes/Fixed.class.hpp

@@ -0,0 +1,59 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   Fixed.class.hpp                                    :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: bchanot <bchanot@gmail.fr>                 +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2025/07/16 15:46:39 by bchanot           #+#    #+#             */
+/*   Updated: 2025/07/17 19:32:12 by bchanot          ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#ifndef FIXED_CLASS_H
+# define FIXED_CLASS_H
+
+#include <iostream>
+
+class	Fixed {
+	public:
+		Fixed(void);
+		Fixed(Fixed const &src);
+		Fixed(int const num);
+		Fixed(float const num);
+		~Fixed(void);
+
+		int			getRawBits(void) const;
+		void		setRawBits(int const raw);
+		float		toFloat(void) const;
+		int			toInt(void) const;
+
+		Fixed		&operator=(Fixed const &rhs);
+		bool		operator!=(Fixed const &rhs) const;
+		bool		operator==(Fixed const &rhs) const;
+		bool		operator<=(Fixed const &rhs) const;
+		bool		operator>=(Fixed const &rhs) const;
+		bool		operator<(Fixed const &rhs) const;
+		bool		operator>(Fixed const &rhs) const;
+		Fixed		operator+(Fixed const &rhs) const;
+		Fixed		operator-(Fixed const &rhs) const;
+		Fixed		operator*(Fixed const &rhs) const;
+		Fixed		operator/(Fixed const &rhs) const;
+		Fixed		&operator++();
+		Fixed		&operator--();
+		Fixed		operator++(int);
+		Fixed		operator--(int);
+
+		static const Fixed	&min(Fixed const &left, Fixed const &right);
+		static Fixed	&min(Fixed &left, Fixed &right);
+		static const Fixed	&max(Fixed const &left, Fixed const &right);
+		static Fixed	&max(Fixed &left, Fixed &right);
+
+	private:
+		int			_value;
+		static int const	_frac = 8;
+};
+
+std::ostream	&operator<<(std::ostream &o, Fixed const &i);
+
+#endif

+ 31 - 0
Module_02/ex03/includes/Point.class.hpp

@@ -0,0 +1,31 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   Point.class.hpp                                    :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: bchanot <bchanot@gmail.fr>                 +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2025/07/17 19:24:44 by bchanot           #+#    #+#             */
+/*   Updated: 2025/07/18 19:14:47 by Bastien Chanot   ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#ifndef POINT_CLASS_H
+# define POINT_CLASS_H
+
+#include "Fixed.class.hpp"
+
+class	Point {
+	public:
+		Point(void);
+		Point(Point const &src);
+		Point(float const &x, float const &y);
+		Point	operator=(Point const &src);
+		~Point(void);
+
+	private:
+		Fixed const		_x;
+		Fixed const		_y;
+}
+
+#endif

+ 152 - 0
Module_02/ex03/srcs/Fixed.class.cpp

@@ -0,0 +1,152 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   Fixed.class.cpp                                    :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: bchanot <bchanot@gmail.fr>                 +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2025/07/16 16:07:34 by bchanot           #+#    #+#             */
+/*   Updated: 2025/07/17 18:55:07 by bchanot          ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "Fixed.class.hpp"
+#include <iostream>
+#include <cmath>
+
+Fixed::Fixed(void) : _value(0) {
+	std::cout << "Default constructor called" << std::endl;
+	return ;
+}
+
+Fixed::Fixed(int const num) : _value((int)roundf(num * (1 << _frac))){
+	std::cout << "Int constructor called" << std::endl;
+	return ;
+}
+
+Fixed::Fixed(float const num) : _value((float)roundf(num * (1 << _frac))){
+	std::cout << "Float constructor called" << std::endl;
+	return ;
+}
+
+Fixed::Fixed(Fixed const &src) {
+	*this = src;
+	std::cout << "Copy constructor called" << std::endl;
+	return ;
+}
+
+Fixed::~Fixed(void) {
+	std::cout << "Destructor called" << std::endl;
+	return ;
+}
+
+int	Fixed::getRawBits(void) const {
+	std::cout << "getRawBits member function called" << std::endl;
+	return this->_value;
+}
+
+void	Fixed::setRawBits(int const raw) {
+	std::cout << "setRawBits member function called" << std::endl;
+	this->_value = raw;
+	return ;
+}
+
+Fixed				&Fixed::operator=(Fixed const &rhs) {
+	std::cout << "Copy assignment operator called" << std::endl;
+	this->_value = rhs.getRawBits();
+	return *this;
+}
+
+bool		Fixed::operator==(Fixed const &rhs) const {
+	return this->toFloat() == rhs.toFloat();
+}
+
+bool		Fixed::operator!=(Fixed const &rhs) const {
+	return this->toFloat() != rhs.toFloat();
+}
+
+bool		Fixed::operator<=(Fixed const &rhs) const {
+	return this->toFloat() <= rhs.toFloat();
+}
+
+bool		Fixed::operator>=(Fixed const &rhs) const {
+	return this->toFloat() >= rhs.toFloat();
+}
+
+bool		Fixed::operator<(Fixed const &rhs) const {
+	return this->toFloat() < rhs.toFloat();
+}
+
+bool		Fixed::operator>(Fixed const &rhs) const {
+	return this->toFloat() > rhs.toFloat();
+}
+
+Fixed		Fixed::operator+(Fixed const &rhs) const {
+	return Fixed::toFloat() + rhs.toFloat();
+}
+
+Fixed		Fixed::operator-(Fixed const &rhs) const {
+	return Fixed::toFloat() - rhs.toFloat();
+}
+
+Fixed		Fixed::operator*(Fixed const &rhs) const {
+	return Fixed::toFloat() * rhs.toFloat();
+}
+
+Fixed		Fixed::operator/(Fixed const &rhs) const {
+	return Fixed::toFloat() / rhs.toFloat();
+}
+
+Fixed		&Fixed::operator++(void) {
+	this->_value++;
+	return *this;
+}
+
+Fixed		&Fixed::operator--(void) {
+	this->_value--;
+	return *this;
+}
+
+Fixed		Fixed::operator++(int) {
+	Fixed	other(*this);
+
+	operator++();
+	return other;
+}
+
+Fixed		Fixed::operator--(int) {
+	Fixed	other(*this);
+
+	operator--();
+	return other;
+}
+
+
+const Fixed	&Fixed::min(Fixed const &left, Fixed const &right) {
+	return left < right ? left : right;
+}
+
+Fixed	&Fixed::min(Fixed &left, Fixed &right) {
+	return left < right ? left : right;
+}
+
+const Fixed	&Fixed::max(Fixed const &left, Fixed const &right) {
+	return left > right ? left : right;
+}
+
+Fixed	&Fixed::max(Fixed &left, Fixed &right) {
+	return left > right ? left : right;
+}
+
+float		Fixed::toFloat(void) const {
+	return (float(this->_value) / float(1 << this->_frac));
+}
+
+int			Fixed::toInt(void) const {
+	return (int(this->_value) / int(1 << this->_frac));
+}
+
+std::ostream	&operator<<(std::ostream &o, Fixed const &i) {
+	o << i.toFloat();
+	return o;
+}

+ 36 - 0
Module_02/ex03/srcs/Point.class.cpp

@@ -0,0 +1,36 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   Point.class.cpp                                    :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: Bastien Chanot <chanot.bastien@gmail.com>  +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2025/07/18 19:15:01 by Bastien Chanot    #+#    #+#             */
+/*   Updated: 2025/07/18 19:16:41 by Bastien Chanot   ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "Point.class.hpp"
+#include <iostream>
+
+Point::Point(void) : _x(0), _y(0) {
+	std::cout << "Default constructor called" << std::endl;
+	return ;
+}
+
+Point::Point(Point const &src) {
+	*this = src;
+	std::cout << "Copy constructor called" << std::endl;
+	return ;
+}
+
+Point::~Point(void) {
+	std::cout << "Default destructor called" << std::endl;
+	return ;
+}
+
+Point	&Point::operator=(Point const &src) {
+	std::cout << "Copy assignment operator called" << std::endl;
+	return *this;
+}
+

+ 28 - 0
Module_02/ex03/srcs/main.cpp

@@ -0,0 +1,28 @@
+/* ************************************************************************** */
+/*                                                                            */
+/*                                                        :::      ::::::::   */
+/*   main.cpp                                           :+:      :+:    :+:   */
+/*                                                    +:+ +:+         +:+     */
+/*   By: bchanot <bchanot@gmail.fr>                 +#+  +:+       +#+        */
+/*                                                +#+#+#+#+#+   +#+           */
+/*   Created: 2025/07/17 15:10:40 by bchanot           #+#    #+#             */
+/*   Updated: 2025/07/17 18:53:18 by bchanot          ###   ########.fr       */
+/*                                                                            */
+/* ************************************************************************** */
+
+#include "Fixed.class.hpp"
+#include <iostream>
+
+int main( void ) {
+	Fixed a;
+	Fixed const b( Fixed( 5.05f ) * Fixed( 2 ) );
+
+	std::cout << a << std::endl;
+	std::cout << ++a << std::endl;
+	std::cout << a << std::endl;
+	std::cout << a++ << std::endl;
+	std::cout << a << std::endl;
+	std::cout << b << std::endl;
+	std::cout << Fixed::max( a, b ) << std::endl;
+	return 0;
+}