1
0

🔨」 fix: fixed ex00

This commit is contained in:
2025-07-03 14:01:38 +02:00
parent 81064ed6f4
commit 14cda73db2
3 changed files with 12 additions and 26 deletions

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */ /* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/21 10:39:45 by adjoly #+# #+# */ /* Created: 2025/05/21 10:39:45 by adjoly #+# #+# */
/* Updated: 2025/06/30 10:54:14 by adjoly ### ########.fr */ /* Updated: 2025/07/03 13:58:35 by adjoly ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -210,7 +210,7 @@ BitcoinExchange::BitcoinExchange(char *av) : _is(av), _filename(av) {
try { try {
_csv = new CsvParser(); _csv = new CsvParser();
} catch (std::exception &e) { } catch (std::exception &e) {
throw e; throw std::runtime_error("there is a issue with the data.csv");
} }
if (!_is.is_open()) { if (!_is.is_open()) {
@ -294,18 +294,14 @@ std::pair<Date, float> BitcoinExchange::_parseLine(void) {
void BitcoinExchange::_printPair(std::pair<Date, float> pair) { void BitcoinExchange::_printPair(std::pair<Date, float> pair) {
auto map = _csv->getCsv(); auto map = _csv->getCsv();
auto it = std::find_if(map.begin(), map.end(), CompareDate(pair.first)); auto itDate = map.begin();
if (it == map.end()) { for (auto it = range(map)) {
delete _csv; if (it->first >= pair.first) {
throw std::out_of_range("out of range"); break;
}
itDate = it;
} }
float i = it->second * pair.second; float i = itDate->second * pair.second;
std::cout << pair.first << " => " << pair.second << " = " << i << std::endl; std::cout << pair.first << " => " << pair.second << " = " << i << std::endl;
} }
CompareDate::CompareDate(Date date) : _date(date) {}
bool CompareDate::operator()(const std::pair<Date, float> &pair) const {
return pair.first >= _date;
}

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */ /* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/21 10:38:49 by adjoly #+# #+# */ /* Created: 2025/05/21 10:38:49 by adjoly #+# #+# */
/* Updated: 2025/06/03 12:09:58 by adjoly ### ########.fr */ /* Updated: 2025/07/03 13:54:16 by adjoly ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -106,13 +106,3 @@ class BitcoinExchange {
std::pair<Date, float> _parseLine(void); std::pair<Date, float> _parseLine(void);
void _printPair(std::pair<Date, float>); void _printPair(std::pair<Date, float>);
}; };
class CompareDate {
public:
CompareDate(Date);
bool operator()(const std::pair<Date, float> &pair) const;
private:
Date _date;
};

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */ /* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/05/21 10:34:50 by adjoly #+# #+# */ /* Created: 2025/05/21 10:34:50 by adjoly #+# #+# */
/* Updated: 2025/06/30 10:52:15 by adjoly ### ########.fr */ /* Updated: 2025/07/03 13:52:10 by adjoly ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -23,7 +23,7 @@ int main(int ac, char **av) {
try { try {
btc = new BitcoinExchange(av[1]); btc = new BitcoinExchange(av[1]);
btc->print(); btc->print();
} catch (std::runtime_error &e) { } catch (std::exception &e) {
btc = NULL; btc = NULL;
std::cout << e.what() << std::endl; std::cout << e.what() << std::endl;
} }