adding the first of cpp06
This commit is contained in:
parent
12c51ae90e
commit
f4bd73f103
6 changed files with 325 additions and 1 deletions
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/03/18 18:05:02 by rparodi #+# #+# */
|
/* Created: 2025/03/18 18:05:02 by rparodi #+# #+# */
|
||||||
/* Updated: 2025/03/19 20:25:27 by rparodi ### ########.fr */
|
/* Updated: 2025/03/20 15:31:02 by rparodi ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
127
cpp06/ex00/Makefile
Normal file
127
cpp06/ex00/Makefile
Normal file
|
|
@ -0,0 +1,127 @@
|
||||||
|
# **************************************************************************** #
|
||||||
|
# #
|
||||||
|
# ::: :::::::: #
|
||||||
|
# Makefile :+: :+: :+: #
|
||||||
|
# +:+ +:+ +:+ #
|
||||||
|
# By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ #
|
||||||
|
# +#+#+#+#+#+ +#+ #
|
||||||
|
# Created: 2023/11/12 11:05:05 by rparodi #+# #+# #
|
||||||
|
# Updated: 2025/03/21 15:09:04 by rparodi ### ########.fr #
|
||||||
|
# #
|
||||||
|
# **************************************************************************** #
|
||||||
|
|
||||||
|
# Variables
|
||||||
|
|
||||||
|
# Name
|
||||||
|
NAME = intern
|
||||||
|
|
||||||
|
# Commands
|
||||||
|
CXX = c++
|
||||||
|
RM = rm -rf
|
||||||
|
|
||||||
|
# Flags
|
||||||
|
# Mandatory flags for 42
|
||||||
|
CXXFLAGS = -Werror -Wextra -Wall -std=c++98 -I./includes/
|
||||||
|
# Flags to have the dependences (can be removed for correction)
|
||||||
|
CXXFLAGS += -MMD
|
||||||
|
# Flags to have the debug (can be removed for correction)
|
||||||
|
DEBUG = -g3
|
||||||
|
DEBUG += -fsanitize=address
|
||||||
|
CXXFLAGS += $(DEBUG)
|
||||||
|
|
||||||
|
# Sources
|
||||||
|
SRC = sources/ScalarConverter.cpp \
|
||||||
|
main.cpp
|
||||||
|
|
||||||
|
# Objects
|
||||||
|
OBJDIRNAME = ./build
|
||||||
|
OBJ = $(addprefix $(OBJDIRNAME)/,$(SRC:.cpp=.o))
|
||||||
|
|
||||||
|
# Colors
|
||||||
|
GREEN = \033[32m
|
||||||
|
GREY = \033[0;90m
|
||||||
|
RED = \033[0;31m
|
||||||
|
GOLD = \033[38;5;220m
|
||||||
|
END = \033[0m
|
||||||
|
|
||||||
|
# Rules
|
||||||
|
|
||||||
|
# All (make all)
|
||||||
|
all: header $(NAME) footer
|
||||||
|
|
||||||
|
# Bonus (make bonus)
|
||||||
|
bonus: header $(OBJ) footer
|
||||||
|
@mkdir -p $(OBJDIRNAME)
|
||||||
|
@printf '$(GREY) Creating $(END)$(GREEN)$(OBJDIRNAME)$(END)\n'
|
||||||
|
@$(CXX) $(CXXFLAGS) -o $(NAME) $(OBJ)
|
||||||
|
|
||||||
|
# Clean (make clean)
|
||||||
|
clean:
|
||||||
|
@printf '$(GREY) Removing $(END)$(RED)Objects$(END)\n'
|
||||||
|
@printf '$(GREY) Removing $(END)$(RED)Objects Folder$(END)\n'
|
||||||
|
@$(RM) $(OBJDIRNAME)
|
||||||
|
|
||||||
|
# Clean (make fclean)
|
||||||
|
fclean: clean
|
||||||
|
@printf '$(GREY) Removing $(END)$(RED)Program$(END)\n'
|
||||||
|
@$(RM) $(NAME)
|
||||||
|
@echo ""
|
||||||
|
|
||||||
|
# Restart (make re)
|
||||||
|
re: header fclean all
|
||||||
|
|
||||||
|
# Dependences for all
|
||||||
|
$(NAME): $(OBJ)
|
||||||
|
@mkdir -p $(OBJDIRNAME)
|
||||||
|
@printf '$(GREY) Creating $(END)$(GREEN)$(OBJDIRNAME)$(END)\n'
|
||||||
|
@$(CXX) $(CXXFLAGS) -o $(NAME) $(OBJ)
|
||||||
|
|
||||||
|
# Creating the objects
|
||||||
|
$(OBJDIRNAME)/%.o: %.cpp
|
||||||
|
@mkdir -p $(dir $@)
|
||||||
|
@printf '$(GREY) Compiling $(END)$(GREEN)$<$(END)\n'
|
||||||
|
@$(CXX) $(CXXFLAGS) -o $@ -c $<
|
||||||
|
|
||||||
|
# Header
|
||||||
|
header:
|
||||||
|
@clear
|
||||||
|
@printf '\n\n'
|
||||||
|
@printf '$(GOLD) ******* ****** ******* $(END)\n'
|
||||||
|
@printf '$(GOLD) ****** *** ******* $(END)\n'
|
||||||
|
@printf '$(GOLD) ******* * ******* $(END)\n'
|
||||||
|
@printf '$(GOLD) ****** ******* $(END)\n'
|
||||||
|
@printf '$(GOLD) ******* ******* $(END)\n'
|
||||||
|
@printf '$(GOLD) ******************* ******* * $(END)\n'
|
||||||
|
@printf '$(GOLD) ******************* ******* *** $(END)\n'
|
||||||
|
@printf '$(GOLD) ****** ******* ****** $(END)\n'
|
||||||
|
@printf '$(GOLD) ****** $(END)\n'
|
||||||
|
@printf '$(GOLD) ****** $(END)\n'
|
||||||
|
@printf '$(GREY) Made by rparodi$(END)\n\n'
|
||||||
|
|
||||||
|
# Footer
|
||||||
|
footer:
|
||||||
|
@printf "\n"
|
||||||
|
@printf "$(GOLD) ,_ _,$(END)\n"
|
||||||
|
@printf "$(GOLD) | \\___//|$(END)\n"
|
||||||
|
@printf "$(GOLD) |=6 6=|$(END)\n"
|
||||||
|
@printf "$(GOLD) \\=._Y_.=/$(END)\n"
|
||||||
|
@printf "$(GOLD) ) \` ( ,$(END)\n"
|
||||||
|
@printf "$(GOLD) / \\ (('$(END)\n"
|
||||||
|
@printf "$(GOLD) | | ))$(END)\n"
|
||||||
|
@printf "$(GOLD) /| | | |\\_//$(END)\n"
|
||||||
|
@printf "$(GOLD) \\| |._.| |/-\`$(END)\n"
|
||||||
|
@printf "$(GOLD) '\"' '\"'$(END)\n"
|
||||||
|
@printf ' $(GREY)The compilation is$(END) $(GOLD)finish$(END)\n $(GREY)Have a good $(END)$(GOLD)correction !$(END)\n'
|
||||||
|
|
||||||
|
clangd:
|
||||||
|
@echo \
|
||||||
|
"CompileFlags:\n" \
|
||||||
|
" Add:\n" \
|
||||||
|
" - \"-std=c++98 -Wall -Wextra -Werror\"\n" \
|
||||||
|
" - \"-I"$(shell pwd)"/includes\"\n" \
|
||||||
|
" - \"-xc++\"\n" \
|
||||||
|
> .clangd
|
||||||
|
|
||||||
|
# Phony
|
||||||
|
.PHONY: all bonus clean fclean re clangd
|
||||||
|
-include ${OBJ:.o=.d}
|
||||||
25
cpp06/ex00/includes/ScalarConverter.hpp
Normal file
25
cpp06/ex00/includes/ScalarConverter.hpp
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ScalarConverter.hpp :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/03/20 15:50:13 by rparodi #+# #+# */
|
||||||
|
/* Updated: 2025/03/21 15:05:26 by rparodi ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
class ScalarConverter {
|
||||||
|
public:
|
||||||
|
ScalarConverter();
|
||||||
|
~ScalarConverter();
|
||||||
|
ScalarConverter(ScalarConverter const ©);
|
||||||
|
ScalarConverter& operator = (ScalarConverter const &assign);
|
||||||
|
static void convert(std::string *input);
|
||||||
|
private:
|
||||||
|
};
|
||||||
47
cpp06/ex00/includes/color.hpp
Normal file
47
cpp06/ex00/includes/color.hpp
Normal file
|
|
@ -0,0 +1,47 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* color.hpp :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2024/10/17 15:27:54 by rparodi #+# #+# */
|
||||||
|
/* Updated: 2025/02/18 16:43:18 by rparodi ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef COLOR_HPP
|
||||||
|
#define COLOR_HPP
|
||||||
|
|
||||||
|
#define RESET "\033[0m"
|
||||||
|
|
||||||
|
#define BLACK "\033[0;30m"
|
||||||
|
#define RED "\033[0;31m"
|
||||||
|
#define GREEN "\033[0;32m"
|
||||||
|
#define YELLOW "\033[0;33m"
|
||||||
|
#define BLUE "\033[0;34m"
|
||||||
|
#define MAGENTA "\033[0;35m"
|
||||||
|
#define CYAN "\033[0;36m"
|
||||||
|
#define WHITE "\033[0;37m"
|
||||||
|
#define GOLD "\033[38;5;220m"
|
||||||
|
#define GREY "\033[38;5;240m"
|
||||||
|
|
||||||
|
#define L_BLACK "\033[0;90m"
|
||||||
|
#define L_RED "\033[0;91m"
|
||||||
|
#define L_GREEN "\033[0;92m"
|
||||||
|
#define L_YELLOW "\033[0;93m"
|
||||||
|
#define L_BLUE "\033[0;94m"
|
||||||
|
#define L_MAGENTA "\033[0;95m"
|
||||||
|
#define L_CYAN "\033[0;96m"
|
||||||
|
#define L_WHITE "\033[0;97m"
|
||||||
|
|
||||||
|
#define B_BLACK "\033[1;30m"
|
||||||
|
#define B_RED "\033[1;31m"
|
||||||
|
#define B_GREEN "\033[1;32m"
|
||||||
|
#define B_YELLOW "\033[1;33m"
|
||||||
|
#define B_BLUE "\033[1;34m"
|
||||||
|
#define B_MAGENTA "\033[1;35m"
|
||||||
|
#define B_CYAN "\033[1;36m"
|
||||||
|
#define B_WHITE "\033[1;37m"
|
||||||
|
|
||||||
|
#endif
|
||||||
36
cpp06/ex00/main.cpp
Normal file
36
cpp06/ex00/main.cpp
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* main.cpp :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/03/20 15:49:02 by rparodi #+# #+# */
|
||||||
|
/* Updated: 2025/03/21 18:26:21 by rparodi ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "ScalarConverter.hpp"
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
ScalarConverter test;
|
||||||
|
test.convert(new std::string("a"));
|
||||||
|
std::cout << std::endl;
|
||||||
|
test.convert(new std::string("0"));
|
||||||
|
std::cout << std::endl;
|
||||||
|
test.convert(new std::string("4294967300"));
|
||||||
|
std::cout << std::endl;
|
||||||
|
test.convert(new std::string("42.42"));
|
||||||
|
std::cout << std::endl;
|
||||||
|
test.convert(new std::string("-inff"));
|
||||||
|
std::cout << std::endl;
|
||||||
|
test.convert(new std::string("+inff"));
|
||||||
|
std::cout << std::endl;
|
||||||
|
test.convert(new std::string("nanf"));
|
||||||
|
std::cout << std::endl;
|
||||||
|
test.convert(new std::string("-inf"));
|
||||||
|
std::cout << std::endl;
|
||||||
|
test.convert(new std::string("+inf"));
|
||||||
|
std::cout << std::endl;
|
||||||
|
test.convert(new std::string("nan"));
|
||||||
|
}
|
||||||
89
cpp06/ex00/sources/ScalarConverter.cpp
Normal file
89
cpp06/ex00/sources/ScalarConverter.cpp
Normal file
|
|
@ -0,0 +1,89 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ScalarConverter.cpp :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/03/20 16:41:16 by rparodi #+# #+# */
|
||||||
|
/* Updated: 2025/03/21 15:49:00 by rparodi ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "ScalarConverter.hpp"
|
||||||
|
#include <cctype>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <sstream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
ScalarConverter::ScalarConverter() {
|
||||||
|
std::cout << "[ScalarConverter] Default constructor called" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
ScalarConverter::ScalarConverter(ScalarConverter const ©) {
|
||||||
|
std::cout << "[ScalarConverter] Copy constructor called" << std::endl;
|
||||||
|
*this = copy;
|
||||||
|
}
|
||||||
|
|
||||||
|
ScalarConverter::~ScalarConverter() {
|
||||||
|
std::cout << "[ScalarConverter] Destructor called" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
ScalarConverter& ScalarConverter::operator = (ScalarConverter const &assign) {
|
||||||
|
std::cout << "[ScalarConverter] Assignation operator called" << std::endl;
|
||||||
|
(void)assign;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isChar(std::string *input) {
|
||||||
|
if (input->length() == 1 && std::isprint(input->at(0)))
|
||||||
|
return true;
|
||||||
|
if (input->length() == 1 && std::isprint(input->at(0))) {
|
||||||
|
std::cerr << "Please note that non-displayable characters shouldn’t be used as inputs." << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isInt(std::string *input) {
|
||||||
|
for (size_t i = 0; i < input->length(); i++) {
|
||||||
|
if (!std::isdigit(input->at(i))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::ostringstream oss;
|
||||||
|
try {
|
||||||
|
oss << std::stoi(*input);
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isFloat(std::string *input) {
|
||||||
|
std::ostringstream oss;
|
||||||
|
try {
|
||||||
|
oss << std::stof(*input);
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isDouble(std::string *input) {
|
||||||
|
std::ostringstream oss;
|
||||||
|
try {
|
||||||
|
oss << std::stod(*input);
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScalarConverter::convert(std::string *input) {
|
||||||
|
std::cout << "Input:\t\t" << *input << std::endl;
|
||||||
|
std::cout << "IsChar:\t\t" << (isChar(input) ? "✅ | true" : "❌ | false") << std::endl;
|
||||||
|
std::cout << "IsInt:\t\t" << (isInt(input) ? "✅ | true" : "❌ | false") << std::endl;
|
||||||
|
std::cout << "IsFloat:\t" << (isFloat(input) ? "✅ | true" : "❌ | false") << std::endl;
|
||||||
|
std::cout << "IsDouble:\t" << (isDouble(input) ? "✅ | true" : "❌ | false") << std::endl;
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue