Skip to content

cpp09 ex00: Bitcoin Exchange#1

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/add-bitcoin-exchange-feature
Draft

cpp09 ex00: Bitcoin Exchange#1
Copilot wants to merge 2 commits intomainfrom
copilot/add-bitcoin-exchange-feature

Conversation

Copy link
Copy Markdown

Copilot AI commented Mar 29, 2026

Implements the 42 school cpp09 Exercise 00 (Bitcoin Exchange) in a new ex00/ directory. The program btc reads a CSV price database and an input file of date | value pairs, outputting each value multiplied by the exchange rate on the closest earlier date in the DB.

Structure

  • BitcoinExchange.hpp/cpp — Canonical C++98 class; uses std::map<std::string, double> as the price database (ISO-8601 string keys sort chronologically, enabling lower_bound for closest-lower-date lookup)
  • main.cpp — Validates argc, loads data.csv, delegates to processInput
  • Makefile — Builds btc with -Wall -Wextra -Werror -std=c++98
  • data.csv — Historical BTC prices 2009–2022
  • input.txt — Sample input matching subject example

Key logic

Closest lower date via lower_bound:

std::map<std::string, double>::const_iterator it = _db.lower_bound(date);
if (it != _db.end() && it->first == date) return it->second; // exact
if (it == _db.begin()) throw std::runtime_error("Error: bad input => " + date);
return (--it)->second; // closest lower

Value parsingstrtod with full-string consumption check, then range/sign guards:

double value = std::strtod(valueStr.c_str(), &end);
if (end == valueStr.c_str() || *end != '\0') /* bad input */;
if (value < 0)    /* not a positive number */;
if (value > 1000) /* too large a number */;

Date validation — checks length, delimiter positions, digit-only fields, month/day bounds, and leap-year correctness for Feb 29.

Error messages (per spec)

Condition Output
Wrong/no argument or unreadable file Error: could not open file.
Missing | separator or bad date Error: bad input => …
Negative value Error: not a positive number.
Value > 1000 Error: too large a number.

🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Agent-Logs-Url: https://github.com/Mohamed0013/WebProject/sessions/4eeabe96-7d63-4451-82ba-c39c01ac2626

Co-authored-by: Mohamed0013 <123728001+Mohamed0013@users.noreply.github.com>
Copilot AI changed the title [WIP] Add bitcoin exchange program for price evaluation cpp09 ex00: Bitcoin Exchange Mar 29, 2026
Copilot AI requested a review from Mohamed0013 March 29, 2026 15:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants