push ex01

This commit is contained in:
LEO FIRMIN 2026-05-06 17:05:05 +02:00
parent 0b56ac5cea
commit f4fec9e326
11 changed files with 148 additions and 18 deletions

View File

@ -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);
}

View File

@ -3,7 +3,7 @@ CXXFLAGS = -Wall -Wextra -Werror -std=c++98
OBJDIR = obj
SOURCES = Main.cpp BitcoinExchange.cpp
OBJECTS = $(addprefix $(OBJDIR)/, $(SOURCES:.cpp=.o))
NAME = btc
NAME = btv
all: $(NAME)

BIN
ex00/btc

Binary file not shown.

BIN
ex00/btv Executable file

Binary file not shown.

Binary file not shown.

View File

@ -1,2 +0,0 @@
dsd
2000-02-29 | 1

21
ex01/Main.cpp Normal file
View File

@ -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;
}

36
ex01/Makefile Normal file
View File

@ -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

66
ex01/RPN.cpp Normal file
View File

@ -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();
}

23
ex01/RPN.hpp Normal file
View File

@ -0,0 +1,23 @@
#ifndef RPN_HPP
# define RPN_HPP
#include <iostream>
#include <sstream>
#include <stack>
#include <string>
class RPN
{
public:
RPN();
RPN(const RPN &other);
RPN &operator=(const RPN &other);
~RPN();
int compute(const std::string &string);
private:
std::stack<int> _stack;
};
#endif

13
test.c
View File

@ -1,13 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
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);
}
}