🎉」 init: hello world !

This commit is contained in:
2025-08-02 13:51:40 +02:00
commit 224ed0cf99
44 changed files with 2108 additions and 0 deletions

95
ex00/Bureaucrat.cpp Normal file
View File

@@ -0,0 +1,95 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Bureaucrat.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/06/18 20:11:39 by mmoussou #+# #+# */
/* Updated: 2025/06/27 13:35:28 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#include "Bureaucrat.hpp"
#include <exception>
void _log(std::string emoji, std::string what, std::string who, std::string str)
{
#ifdef VERBOSE
if (who.empty())
std::cout << "" << emoji << "" << what << ": " << str << std::endl;
else
std::cout << "" << emoji << "" << what << "(" << who << "): " << str
<< std::endl;
#else
(void)emoji, (void)what, (void)who, (void)str;
#endif
}
Bureaucrat::Bureaucrat(void)
: _name("kanel"), _grade(69)
{
_log("", "Bureaucrat", "", "default constructor called");
}
Bureaucrat::Bureaucrat(const Bureaucrat &cpy)
{
_log("", "Bureaucrat", "", "copy constructor called");
if (&cpy != this)
{
_name = cpy.getName();
_grade = cpy.getGrade();
}
}
Bureaucrat::Bureaucrat(std::string name, uint8_t grade)
: _name(name), _grade(grade)
{
_log("", "Bureaucrat", "", "constructor called");
}
const std::string &Bureaucrat::getName(void) const { return _name; }
uint8_t Bureaucrat::getGrade(void) const { return _grade; }
Bureaucrat::~Bureaucrat(void)
{
_log("", "Bureaucrat", "", "destructor called");
}
Bureaucrat &Bureaucrat::operator=(Bureaucrat const &cpy)
{
if (&cpy == this)
return *this;
_grade = cpy._grade;
return *this;
}
void Bureaucrat::IncrementGrade(void)
{
if (_grade - 1 < MAXGRADE)
throw GradeTooHighException();
_grade--;
}
void Bureaucrat::DecrementGrade(void)
{
if (_grade + 1 > MINGRADE)
throw GradeTooLowException();
_grade++;
}
std::ostream &operator<<(std::ostream &os, Bureaucrat &val)
{
os << val.getName() << ", bureaucrat grade " << (int)val.getGrade();
return os;
}
const char *Bureaucrat::GradeTooHighException::what() const throw()
{
return ("Grade is too high");
}
const char *Bureaucrat::GradeTooLowException::what() const throw()
{
return ("Grade is too low");
}

59
ex00/Bureaucrat.hpp Normal file
View File

@@ -0,0 +1,59 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Bureaucrat.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/06/18 20:11:25 by mmoussou #+# #+# */
/* Updated: 2025/06/27 13:35:33 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#pragma once
#include <exception>
#include <fstream>
#include <iostream>
#include <stdexcept>
#include <string>
void _log(std::string emoji, std::string what, std::string who, std::string str);
class Form;
typedef unsigned char uint8_t;
#define MAXGRADE 1
#define MINGRADE 150
class Bureaucrat {
public:
Bureaucrat(void);
Bureaucrat(const Bureaucrat &cpy);
Bureaucrat(std::string name, uint8_t grade);
~Bureaucrat(void);
Bureaucrat &operator=(const Bureaucrat& other);
const std::string &getName(void) const;
uint8_t getGrade(void) const;
void IncrementGrade(void);
void DecrementGrade(void);
class GradeTooHighException : public std::exception {
public:
virtual const char *what() const throw();
};
class GradeTooLowException : public std::exception {
public:
virtual const char *what() const throw();
};
private:
std::string _name;
uint8_t _grade;
};
std::ostream &operator<<(std::ostream &, Bureaucrat &);

58
ex00/Makefile Normal file
View File

@@ -0,0 +1,58 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2024/01/22 07:21:18 by mmoussou #+# #+# #
# Updated: 2025/06/19 01:08:50 by mmoussou ### ########.fr #
# #
# **************************************************************************** #
SHELL = bash
RED = \033[0;31m
GREEN = \033[0;32m
YELLOW = \033[1;33m
PURPLE = \e[0;35m
NC = \033[0m
DELETE = \x1B[2K
CC = c++
FLAGS = -std=c++98 -Wall -Werror -Wextra
INCLUDES = .
NAME = ex00
SRCS = main.cpp Bureaucrat.cpp
OBJSDIR = obj/
OBJS = $(addprefix $(OBJSDIR), $(SRCS:.cpp=.o))
all: $(NAME)
$(NAME): $(OBJS)
@$(CC) $(FLAGS) -I$(INCLUDES) $(OBJS) -o $(NAME)
@printf "$(NC)$(YELLOW)「✨」 feat($(NAME)): program compiled\n$(NC)"
$(OBJSDIR)%.o: %.cpp
@mkdir -p $(@D)
@$(CC) $(FLAGS) -I$(INCLUDES) -c $< -o $@
@printf "$(NC)$(GREEN)「🔨」 build($<): object compiled\n$(NC)"
clean:
@rm -f $(OBJS)
@printf "$(NC)$(RED)「🗑️」 clean($(OBJS)): object deleted\n$(NC)"
fclean: clean
@rm -f $(NAME)
@rm -Rf $(OBJSDIR)
@printf "$(NC)$(RED)「🗑️」 fclean($(NAME)): program deleted\n$(NC)"
re: fclean
@$(MAKE) -s all
.PHONY: clean fclean all re

49
ex00/main.cpp Normal file
View File

@@ -0,0 +1,49 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/06/18 20:08:53 by mmoussou #+# #+# */
/* Updated: 2025/06/18 23:58:04 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#include "Bureaucrat.hpp"
#include <iostream>
int main(void)
{
Bureaucrat knl("kanel", 10);
knl.DecrementGrade();
std::cout << knl << std::endl;
knl.IncrementGrade();
std::cout << knl << std::endl;
try
{
knl.IncrementGrade();
knl.IncrementGrade();
knl.IncrementGrade();
knl.IncrementGrade();
knl.IncrementGrade();
knl.IncrementGrade();
knl.IncrementGrade();
knl.IncrementGrade();
knl.IncrementGrade();
knl.IncrementGrade();
knl.IncrementGrade();
knl.IncrementGrade();
knl.IncrementGrade();
knl.IncrementGrade();
knl.IncrementGrade();
knl.IncrementGrade();
knl.IncrementGrade();
}
catch (const std::exception &e)
{
std::cerr << "error: " << e.what() << std::endl;
}
std::cout << knl << std::endl;
}