diff --git a/ex00/Main.cpp b/ex00/Main.cpp index bf678b8..9a7857a 100644 --- a/ex00/Main.cpp +++ b/ex00/Main.cpp @@ -10,6 +10,5 @@ int main(int argc, char **argv) BitcoinExchange btc; btc.loadDatabase("data.csv"); btc.processInput(argv[1]); - std::cout << btc.isValidDate("2000-02-29") << std::endl; return (0); } diff --git a/ex00/Makefile b/ex00/Makefile index b31ee8e..0fb259b 100644 --- a/ex00/Makefile +++ b/ex00/Makefile @@ -1,9 +1,9 @@ CXX = c++ CXXFLAGS = -Wall -Wextra -Werror -std=c++98 OBJDIR = obj -SOURCES = Main.cpp BitcoinExchange.cpp +SOURCES = Main.cpp BitcoinExchange.cpp OBJECTS = $(addprefix $(OBJDIR)/, $(SOURCES:.cpp=.o)) -NAME = btc +NAME = btv all: $(NAME) diff --git a/ex00/btc b/ex00/btc deleted file mode 100755 index 5d703c9..0000000 Binary files a/ex00/btc and /dev/null differ diff --git a/ex00/btv b/ex00/btv new file mode 100755 index 0000000..6b35e40 Binary files /dev/null and b/ex00/btv differ diff --git a/ex00/obj/Main.o b/ex00/obj/Main.o index 8de3843..f50abfb 100644 Binary files a/ex00/obj/Main.o and b/ex00/obj/Main.o differ diff --git a/ex00/output.txt b/ex00/output.txt deleted file mode 100644 index 404aae1..0000000 --- a/ex00/output.txt +++ /dev/null @@ -1,2 +0,0 @@ -dsd -2000-02-29 | 1 diff --git a/ex01/Main.cpp b/ex01/Main.cpp new file mode 100644 index 0000000..b5ef2fe --- /dev/null +++ b/ex01/Main.cpp @@ -0,0 +1,21 @@ +#include "RPN.hpp" + +int main(int ac, char **av) +{ + if (ac == 2) + { + RPN rpn; + try + { + std::cout << rpn.compute(av[1]) << std::endl; + } + catch(const std::exception& e) + { + std::cerr << e.what() << '\n'; + } + return 0; + } + std::cerr << "Error" << std::endl; + return 1; + +} diff --git a/ex01/Makefile b/ex01/Makefile new file mode 100644 index 0000000..fc149a7 --- /dev/null +++ b/ex01/Makefile @@ -0,0 +1,36 @@ +CXX = c++ +CXXFLAGS = -Wall -Wextra -Werror -std=c++98 +OBJDIR = obj +SOURCES = Main.cpp RPN.cpp +OBJECTS = $(addprefix $(OBJDIR)/, $(SOURCES:.cpp=.o)) +NAME = RPN + +all: $(NAME) + +$(OBJDIR): + @echo "๐Ÿ“ Creating obj directory..." + @mkdir -p $(OBJDIR) + +$(OBJDIR)/%.o: %.cpp | $(OBJDIR) + @echo "๐Ÿง  Compiling $< ..." + @$(CXX) $(CXXFLAGS) -c $< -o $@ + @echo "โœ… $@ ready!" + +$(NAME): $(OBJECTS) + @echo "๐Ÿ”— Linking $(NAME) ..." + @$(CXX) $(CXXFLAGS) $(OBJECTS) -o $(NAME) + @echo "๐ŸŽ‰ $(NAME) is ready!" + +clean: + @echo "๐Ÿงน Cleaning object files..." + @rm -rf $(OBJDIR) + @echo "โœจ Objects cleaned!" + +fclean: clean + @echo "๐Ÿ—‘๏ธ Removing $(NAME)..." + @rm -f $(NAME) + @echo "๐Ÿ’€ Full clean complete!" + +re: fclean all + +.PHONY: all clean fclean re diff --git a/ex01/RPN.cpp b/ex01/RPN.cpp new file mode 100644 index 0000000..2ca7a63 --- /dev/null +++ b/ex01/RPN.cpp @@ -0,0 +1,66 @@ +#include "RPN.hpp" + +RPN::RPN(){} + +RPN::RPN(const RPN &other) +{ + this->_stack = other._stack; +} + +RPN &RPN::operator=(const RPN &other) +{ + this->_stack = other._stack; + return (*this); +} + +RPN::~RPN(){} + +int RPN::compute(const std::string &string) +{ + std::istringstream iss(string); + std::string token; + std::string ops = "+-*/"; + int b; + int a; + while (iss >> token) + { + if (token.size() == 1) + { + if (isdigit(token[0])) + _stack.push(token[0] - '0'); + else if (ops.find(token[0]) != std::string::npos) + { + if (_stack.size() <= 1) + throw std::runtime_error("Error"); + b = _stack.top(); + _stack.pop(); + a = _stack.top(); + _stack.pop(); + switch (token[0]) + { + case '+': + _stack.push(a + b); + break; + case '-': + _stack.push(a - b); + break; + case '*': + _stack.push(a * b); + break; + case '/': + if (b == 0) + throw std::runtime_error("Error"); + _stack.push(a / b); + break; + } + } + else + throw std::runtime_error("Error"); + } + else + throw std::runtime_error("Error"); + } + if (_stack.size() != 1) + throw std::runtime_error("Error"); + return _stack.top(); +} diff --git a/ex01/RPN.hpp b/ex01/RPN.hpp new file mode 100644 index 0000000..9037b7c --- /dev/null +++ b/ex01/RPN.hpp @@ -0,0 +1,23 @@ +#ifndef RPN_HPP +# define RPN_HPP + +#include +#include +#include +#include + +class RPN +{ + public: + RPN(); + RPN(const RPN &other); + RPN &operator=(const RPN &other); + ~RPN(); + + int compute(const std::string &string); + + private: + std::stack _stack; +}; + +#endif diff --git a/test.c b/test.c deleted file mode 100644 index e878e68..0000000 --- a/test.c +++ /dev/null @@ -1,13 +0,0 @@ -#include -#include - -int main(int ac, char **av) -{ - int month; - int days; - if (ac == 2) { - month = atoi(av[1]); - days = 30 + (month + month / 8) % 2; - printf("Nombre de jour : %d", days); - } -}