starting ex00
This commit is contained in:
70
ex00/BitcoinExchange/BitcoinExchange.cpp
Normal file
70
ex00/BitcoinExchange/BitcoinExchange.cpp
Normal 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);
|
||||
}
|
||||
|
||||
}
|
||||
38
ex00/BitcoinExchange/BitcoinExchange.hpp
Normal file
38
ex00/BitcoinExchange/BitcoinExchange.hpp
Normal file
@@ -0,0 +1,38 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* BitcoinExchange.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* 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 */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef BITCOINEXCHANGE_HPP
|
||||
# define BITCOINEXCHANGE_HPP
|
||||
|
||||
# include <iostream>
|
||||
# include <fstream>
|
||||
# include <map>
|
||||
# include <cstdlib>
|
||||
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
class BitcoinExchange
|
||||
{
|
||||
private:
|
||||
std::map<std::string, double> data;
|
||||
|
||||
public:
|
||||
BitcoinExchange();
|
||||
BitcoinExchange(const BitcoinExchange &other);
|
||||
BitcoinExchange& operator=(const BitcoinExchange &other);
|
||||
~BitcoinExchange();
|
||||
|
||||
void readDatabase(std::ifstream &db);
|
||||
};
|
||||
|
||||
#endif
|
||||
BIN
ex00/BitcoinExchange/BitcoinExchange.o
Normal file
BIN
ex00/BitcoinExchange/BitcoinExchange.o
Normal file
Binary file not shown.
Reference in New Issue
Block a user