「✨」 feat(Ex00): Finished Ex00
This commit is contained in:
BIN
ex00/Fixed
Executable file
BIN
ex00/Fixed
Executable file
Binary file not shown.
41
ex00/Fixed.cpp
Normal file
41
ex00/Fixed.cpp
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* Fixed.cpp :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2024/11/12 21:14:55 by adjoly #+# #+# */
|
||||||
|
/* Updated: 2024/11/12 21:52:16 by adjoly ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "Fixed.hpp"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
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; }
|
28
ex00/Fixed.hpp
Normal file
28
ex00/Fixed.hpp
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* Fixed.hpp :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* 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 );
|
||||||
|
};
|
55
ex00/Makefile
Normal file
55
ex00/Makefile
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
# **************************************************************************** #
|
||||||
|
# #
|
||||||
|
# ::: :::::::: #
|
||||||
|
# Makefile :+: :+: :+: #
|
||||||
|
# +:+ +:+ +:+ #
|
||||||
|
# By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ #
|
||||||
|
# +#+#+#+#+#+ +#+ #
|
||||||
|
# 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
|
25
ex00/main.cpp
Normal file
25
ex00/main.cpp
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* main.cpp :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2024/11/09 19:23:26 by adjoly #+# #+# */
|
||||||
|
/* Updated: 2024/11/12 21:14:50 by adjoly ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "Fixed.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;
|
||||||
|
}
|
Reference in New Issue
Block a user