starting ex00

This commit is contained in:
aortigos
2026-04-23 21:05:36 +02:00
commit 7afb0335ef
8 changed files with 1807 additions and 0 deletions

View File

@@ -0,0 +1,70 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* BitcoinExchange.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aortigos <aortigos@student.42malaga.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/04/23 19:54:20 by aortigos #+# #+# */
/* Updated: 2026/04/23 19:54:20 by aortigos ### ########.fr */
/* */
/* ************************************************************************** */
#include "BitcoinExchange.hpp"
//////////////////
// Constructors //
//////////////////
BitcoinExchange::BitcoinExchange()
{
// std::cout << "BitcoinExchange default constructor called" << std::endl;
}
BitcoinExchange::BitcoinExchange(const BitcoinExchange &other)
{
*this = other;
// std::cout << "BitcoinExchange copy constructor called" << std::endl;
}
BitcoinExchange& BitcoinExchange::operator=(const BitcoinExchange &other)
{
if (this != &other)
{
this->data = other.data;
}
// std::cout << "BitcoinExchange copy assignment operator called" << std::endl;
return (*this);
}
BitcoinExchange::~BitcoinExchange()
{
// std::cout << "BitcoinExchange destructor called" << std::endl;
}
void BitcoinExchange::readDatabase(std::ifstream &db)
{
std::string line;
std::getline(db, line);
if (line != "date,exchange_rate")
throw std::exception();
size_t pos;
std::string date;
std::string price;
while (std::getline(db, line))
{
pos = line.find(',');
if (pos == std::string::npos)
continue ;
date = line.substr(0, pos);
price = line.substr(pos + 1);
this->data[date] = std::strtod(price.c_str(), NULL);
}
}