- Added BitcoinExchange class to manage Bitcoin data. - Implemented methods for loading data from files and processing input. - Introduced exception handling for various error scenarios (file not found, line format issues, negative values, etc.). - Created a main function to demonstrate usage and handle command-line arguments. - Added input data file with various test cases for validation.
62 lines
1.3 KiB
C++
62 lines
1.3 KiB
C++
#pragma once
|
|
|
|
#include <map>
|
|
#include <string>
|
|
#include <stdexcept>
|
|
#include <iostream>
|
|
#include <fstream>
|
|
#include <sstream>
|
|
#include <iomanip>
|
|
#include <ctime>
|
|
#include <exception>
|
|
|
|
class BitcoinExchange
|
|
{
|
|
public:
|
|
BitcoinExchange() = delete;
|
|
BitcoinExchange(const std::string &data_file);
|
|
BitcoinExchange(const BitcoinExchange &other);
|
|
~BitcoinExchange();
|
|
BitcoinExchange &operator=(const BitcoinExchange &other);
|
|
|
|
void printData() const;
|
|
void loadInputFile(const std::string &filename);
|
|
|
|
class FileNotFoundException : public std::exception
|
|
{
|
|
public:
|
|
virtual const char *what() const noexcept;
|
|
};
|
|
|
|
class LineFormatException : public std::exception
|
|
{
|
|
public:
|
|
virtual const char *what() const noexcept;
|
|
};
|
|
|
|
class ValueNegativeException : public std::exception
|
|
{
|
|
public:
|
|
virtual const char *what() const noexcept;
|
|
};
|
|
|
|
class ValueTooLargeException : public std::exception
|
|
{
|
|
public:
|
|
virtual const char *what() const noexcept;
|
|
};
|
|
|
|
class DateInvalidException : public std::exception
|
|
{
|
|
public:
|
|
virtual const char *what() const noexcept;
|
|
};
|
|
|
|
private:
|
|
std::map<long, float>
|
|
_data;
|
|
long getTimestamp(const std::string &date) const;
|
|
void loadDataFile(const std::string &filename);
|
|
float getRate(long timestamp) const;
|
|
float getValue(long timestamp, float amount) const;
|
|
}; |