mirror of
https://github.com/Ladebeze66/cpp-partie-2.git
synced 2025-12-17 06:27:52 +01:00
cpp0902
This commit is contained in:
parent
e80766919d
commit
4438d4f930
4
.vscode/settings.json
vendored
4
.vscode/settings.json
vendored
@ -50,7 +50,9 @@
|
|||||||
"typeinfo": "cpp",
|
"typeinfo": "cpp",
|
||||||
"cstring": "cpp",
|
"cstring": "cpp",
|
||||||
"*.tpp": "c",
|
"*.tpp": "c",
|
||||||
"list": "cpp"
|
"list": "cpp",
|
||||||
|
"map": "cpp",
|
||||||
|
"set": "cpp"
|
||||||
},
|
},
|
||||||
"C_Cpp_Runner.cCompilerPath": "gcc",
|
"C_Cpp_Runner.cCompilerPath": "gcc",
|
||||||
"C_Cpp_Runner.cppCompilerPath": "g++",
|
"C_Cpp_Runner.cppCompilerPath": "g++",
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/03/06 15:04:53 by fgras-ca #+# #+# */
|
/* Created: 2024/03/06 15:04:53 by fgras-ca #+# #+# */
|
||||||
/* Updated: 2024/03/06 15:40:51 by fgras-ca ### ########.fr */
|
/* Updated: 2024/03/06 17:18:53 by fgras-ca ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -15,21 +15,22 @@
|
|||||||
|
|
||||||
RPNCalculator::RPNCalculator()
|
RPNCalculator::RPNCalculator()
|
||||||
{
|
{
|
||||||
// Le constructeur par défaut reste inchangé.
|
std::cout << GREEN << "RPNCalculator default constructor called!" << RESET << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
RPNCalculator::~RPNCalculator()
|
RPNCalculator::~RPNCalculator()
|
||||||
{
|
{
|
||||||
// Le destructeur reste inchangé.
|
std::cout << RED << "RPNCalculator is destroyed!" << RESET << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
RPNCalculator::RPNCalculator(const RPNCalculator& other) : stack(other.stack)
|
RPNCalculator::RPNCalculator(const RPNCalculator& other) : stack(other.stack)
|
||||||
{
|
{
|
||||||
// Le constructeur de copie reste inchangé.
|
std::cout << CYAN << "Copy constructor called for RPNCalculator." << RESET << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
RPNCalculator& RPNCalculator::operator=(const RPNCalculator& other)
|
RPNCalculator& RPNCalculator::operator=(const RPNCalculator& other)
|
||||||
{
|
{
|
||||||
|
std::cout << YELLOW << "Copy assignment RPNCalculator operator called." << RESET << std::endl;
|
||||||
if (this != &other)
|
if (this != &other)
|
||||||
{
|
{
|
||||||
this->stack = other.stack;
|
this->stack = other.stack;
|
||||||
@ -76,7 +77,8 @@ void RPNCalculator::processToken(const std::string& token)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (stack.size() < 2) throw std::runtime_error("Error: Not enough operands.");
|
if (stack.size() < 2)
|
||||||
|
throw std::runtime_error("Error: Not enough operands.");
|
||||||
|
|
||||||
float operand2 = stack.top(); stack.pop();
|
float operand2 = stack.top(); stack.pop();
|
||||||
float operand1 = stack.top(); stack.pop();
|
float operand1 = stack.top(); stack.pop();
|
||||||
@ -86,7 +88,8 @@ void RPNCalculator::processToken(const std::string& token)
|
|||||||
case '-': stack.push(operand1 - operand2); break;
|
case '-': stack.push(operand1 - operand2); break;
|
||||||
case '*': stack.push(operand1 * operand2); break;
|
case '*': stack.push(operand1 * operand2); break;
|
||||||
case '/':
|
case '/':
|
||||||
if (operand2 == 0) throw std::runtime_error("Error: Division by zero.");
|
if (operand2 == 0)
|
||||||
|
throw std::runtime_error("Error: Division by zero.");
|
||||||
stack.push(operand1 / operand2);
|
stack.push(operand1 / operand2);
|
||||||
break;
|
break;
|
||||||
default: throw std::runtime_error("Error: Invalid operator.");
|
default: throw std::runtime_error("Error: Invalid operator.");
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/03/06 14:49:08 by fgras-ca #+# #+# */
|
/* Created: 2024/03/06 14:49:08 by fgras-ca #+# #+# */
|
||||||
/* Updated: 2024/03/06 15:42:36 by fgras-ca ### ########.fr */
|
/* Updated: 2024/03/06 17:18:55 by fgras-ca ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/03/06 15:13:10 by fgras-ca #+# #+# */
|
/* Created: 2024/03/06 15:13:10 by fgras-ca #+# #+# */
|
||||||
/* Updated: 2024/03/06 15:44:07 by fgras-ca ### ########.fr */
|
/* Updated: 2024/03/06 17:18:59 by fgras-ca ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|||||||
61
cpp09/ex02/Makefile
Normal file
61
cpp09/ex02/Makefile
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
# **************************************************************************** #
|
||||||
|
# #
|
||||||
|
# ::: :::::::: #
|
||||||
|
# Makefile :+: :+: :+: #
|
||||||
|
# +:+ +:+ +:+ #
|
||||||
|
# By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ #
|
||||||
|
# +#+#+#+#+#+ +#+ #
|
||||||
|
# Created: 2023/12/27 20:57:42 by fgras-ca #+# #+# #
|
||||||
|
# Updated: 2024/03/06 15:58:19 by fgras-ca ### ########.fr #
|
||||||
|
# #
|
||||||
|
# **************************************************************************** #
|
||||||
|
|
||||||
|
LOGO = @echo "🅻🅰🅳🅴🅱🅴🆉🅴";\
|
||||||
|
|
||||||
|
DEF_COLOR = \033[0m
|
||||||
|
GRAY = \033[0;90m
|
||||||
|
RED = \033[0;91m
|
||||||
|
GREEN = \033[0;92m
|
||||||
|
YELLOW = \033[0;93m
|
||||||
|
BLUE = \033[0;94m
|
||||||
|
MAGENTA = \033[0;95m
|
||||||
|
CYAN = \033[0;96m
|
||||||
|
WHITE = \033[0;97m
|
||||||
|
ORANGE = \033[38;5;214m
|
||||||
|
|
||||||
|
NAME = pmergeme
|
||||||
|
|
||||||
|
SRC = main.cpp \
|
||||||
|
PmergeMe.cpp \
|
||||||
|
|
||||||
|
CC = c++
|
||||||
|
CFLAGS = -Wall -Werror -Wextra -std=c++98
|
||||||
|
RM = rm -f
|
||||||
|
OBJS = ${SRC:.cpp=.o}
|
||||||
|
|
||||||
|
all : $(NAME)
|
||||||
|
|
||||||
|
%.o: %.cpp
|
||||||
|
$(CC) $(CFLAGS) -c $< -o $@
|
||||||
|
|
||||||
|
$(NAME) : $(OBJS)
|
||||||
|
@echo "$(RED)Compilation fixed... $(DEF_COLOR)"
|
||||||
|
$(CC) $(CFLAGS) $(OBJS) -g -o $(NAME)
|
||||||
|
@echo "$(GREEN)Compilation complete. $(ORANGE)Type "./pmergeme" to execute the program!!$(DEF_COLOR)"
|
||||||
|
$(LOGO)
|
||||||
|
|
||||||
|
clean :
|
||||||
|
@echo "$(RED)Deleating files objects... $(DEF_COLOR)"
|
||||||
|
$(RM) $(OBJS)
|
||||||
|
@echo "$(GREEN)files deleted!! $(DEF_COLOR)"
|
||||||
|
$(LOGO)
|
||||||
|
|
||||||
|
fclean : clean
|
||||||
|
@echo "$(RED)Delete program name... $(DEF_COLOR)"
|
||||||
|
$(RM) $(NAME)
|
||||||
|
@echo "$(GREEN)File program deleted!! $(DEF_COLOR)"
|
||||||
|
$(LOGO)
|
||||||
|
|
||||||
|
re : fclean all
|
||||||
|
|
||||||
|
.PHONY : all clean fclean re
|
||||||
0
cpp09/ex02/PmergeMe.cpp
Normal file
0
cpp09/ex02/PmergeMe.cpp
Normal file
42
cpp09/ex02/PmergeMe.hpp
Normal file
42
cpp09/ex02/PmergeMe.hpp
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* PmergeMe.hpp :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2024/03/06 16:17:28 by fgras-ca #+# #+# */
|
||||||
|
/* Updated: 2024/03/06 17:18:48 by fgras-ca ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef PMERGEME_HPP
|
||||||
|
#define PMERGEME_HPP
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <list>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
class PmergeMe
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
PmergeMe();
|
||||||
|
~PmergeMe();
|
||||||
|
PmergeMe(const PmergeMe& other);
|
||||||
|
PmergeMe& operator=(const PmergeMe& other);
|
||||||
|
|
||||||
|
void sortAndDisplay(const std::vector<int>& input);
|
||||||
|
void sortAndDisplay(const std::list<int>& input);
|
||||||
|
|
||||||
|
private:
|
||||||
|
template<typename Container>
|
||||||
|
void forJohnsonSort(Container& container);
|
||||||
|
|
||||||
|
template<typename Container>
|
||||||
|
void displaySequence(const Container& sequence, const std::string& prefix);
|
||||||
|
|
||||||
|
template<typename Container>
|
||||||
|
void mesureAndSort(Container& container);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
0
cpp09/ex02/main.cpp
Normal file
0
cpp09/ex02/main.cpp
Normal file
Loading…
x
Reference in New Issue
Block a user