「🏗️」 wip: work in progress, not done yet.
This commit is contained in:
87
ex00/BitcoinExchange.cpp
Normal file
87
ex00/BitcoinExchange.cpp
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
#include "BitcoinExchange.hpp"
|
||||||
|
|
||||||
|
Date::Date(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Date::Date(const std::string str)
|
||||||
|
{
|
||||||
|
// check format (4 char & isdigit into dash into 2 char isdigit & < 1 && isdigit & < 2, and same for day except ahah funny cuz 30 and 31 and 28 and 29 agfjasfgfjahkfga)
|
||||||
|
|
||||||
|
for (std::string::iterator it = str.begin(); it < str.end(); ++it)
|
||||||
|
{
|
||||||
|
if (*it != '-')
|
||||||
|
continue ;
|
||||||
|
_value *= 10;
|
||||||
|
_value += *it - '0';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Date::Date(const Date &other)
|
||||||
|
{
|
||||||
|
this->_value = other._value;
|
||||||
|
}
|
||||||
|
|
||||||
|
Date &Date::operator=(const Date &other)
|
||||||
|
{
|
||||||
|
this->_value = other._value;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
Date::~Date(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Date::operator==(const Date &other) const
|
||||||
|
{
|
||||||
|
return this->_value == other._value;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Date::operator!=(const Date &other) const
|
||||||
|
{
|
||||||
|
return this->_value != other._value;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Date::operator<(const Date &other) const
|
||||||
|
{
|
||||||
|
return this->_value < other._value;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Date::operator>(const Date &other) const
|
||||||
|
{
|
||||||
|
return this->_value > other._value;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Date::operator<=(const Date &other) const
|
||||||
|
{
|
||||||
|
return this->_value <= other._value;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Date::operator>=(const Date &other) const
|
||||||
|
{
|
||||||
|
return this->_value >= other._value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// --------------------------------------------------- //
|
||||||
|
|
||||||
|
void parseData(const std::string filename)
|
||||||
|
{
|
||||||
|
(void) filename;
|
||||||
|
}
|
||||||
|
|
||||||
|
void str(std::string input)
|
||||||
|
{
|
||||||
|
input = "2024-10-04 | 135.00\n2014-04-14 | 24.00\n2001-09-11 | 135.00"
|
||||||
|
std::stringstream input_ss(input);
|
||||||
|
std::string line;
|
||||||
|
|
||||||
|
while (std::getline(input_ss, line))
|
||||||
|
{
|
||||||
|
std::stringstream ss(input);
|
||||||
|
std::string date_str;
|
||||||
|
std::string value_str;
|
||||||
|
if (!std::getline(ss, date_str, '|') || !std::getline(ss, value_str, '|'))
|
||||||
|
throw ; //add exception ig
|
||||||
|
this->_data.insert(std::pair{Date(date_str), std::atoi(value_str.c_str())});
|
||||||
|
}
|
||||||
|
}
|
||||||
40
ex00/BitcoinExchange.hpp
Normal file
40
ex00/BitcoinExchange.hpp
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <string>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
|
class Date {
|
||||||
|
public:
|
||||||
|
Date(void);
|
||||||
|
Date(const std::string);
|
||||||
|
Date(const Date &);
|
||||||
|
Date &operator=(const Date &);
|
||||||
|
~Date(void);
|
||||||
|
|
||||||
|
bool operator==(const Date &) const;
|
||||||
|
bool operator!=(const Date &) const;
|
||||||
|
|
||||||
|
bool operator<(const Date &) const;
|
||||||
|
bool operator>(const Date &) const;
|
||||||
|
|
||||||
|
bool operator<=(const Date &) const;
|
||||||
|
bool operator>=(const Date &) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
unsigned long long _value;
|
||||||
|
};
|
||||||
|
|
||||||
|
class BitcoinExchange {
|
||||||
|
public:
|
||||||
|
BitcoinExchange(void) {parseData("data.csv");}
|
||||||
|
BitcoinExchange(const BitcoinExchange &other) {this->_data = other._data;}
|
||||||
|
BitcoinExchange &operator=(const BitcoinExchange &other) {this->_data = other._data; return *this;}
|
||||||
|
~BitcoinExchange(void) {}
|
||||||
|
|
||||||
|
void parseData(const std::string filename);
|
||||||
|
void str(std::string input);
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::map<Date, double> _data;
|
||||||
|
};
|
||||||
58
ex00/Makefile
Normal file
58
ex00/Makefile
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
# **************************************************************************** #
|
||||||
|
# #
|
||||||
|
# ::: :::::::: #
|
||||||
|
# Makefile :+: :+: :+: #
|
||||||
|
# +:+ +:+ +:+ #
|
||||||
|
# By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ #
|
||||||
|
# +#+#+#+#+#+ +#+ #
|
||||||
|
# Created: 2024/01/22 07:21:18 by mmoussou #+# #+# #
|
||||||
|
# Updated: 2025/08/19 13:58:37 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
|
||||||
|
|
||||||
|
CXX = c++
|
||||||
|
|
||||||
|
FLAGS = -std=c++98 -Wall -Werror -Wextra
|
||||||
|
|
||||||
|
INCLUDES = .
|
||||||
|
|
||||||
|
NAME = btc
|
||||||
|
|
||||||
|
SRCS = main.cpp BitcoinExchange.cpp
|
||||||
|
|
||||||
|
OBJSDIR = obj/
|
||||||
|
OBJS = $(addprefix $(OBJSDIR), $(SRCS:.cpp=.o))
|
||||||
|
|
||||||
|
all: $(NAME)
|
||||||
|
|
||||||
|
$(NAME): $(OBJS)
|
||||||
|
@$(CXX) $(FLAGS) -I$(INCLUDES) $(OBJS) -o $(NAME)
|
||||||
|
@printf "$(NC)$(YELLOW)「✨」 feat($(NAME)): program compiled\n$(NC)"
|
||||||
|
|
||||||
|
$(OBJSDIR)%.o: %.cpp
|
||||||
|
@mkdir -p $(@D)
|
||||||
|
@$(CXX) $(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
|
||||||
1613
ex00/data.csv
Normal file
1613
ex00/data.csv
Normal file
File diff suppressed because it is too large
Load Diff
7
ex00/main.cpp
Normal file
7
ex00/main.cpp
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
#include "BitcoinExchange.hpp"
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
(void) argc;
|
||||||
|
(void) argv;
|
||||||
|
}
|
||||||
BIN
ex00/obj/main.o
Normal file
BIN
ex00/obj/main.o
Normal file
Binary file not shown.
Reference in New Issue
Block a user