Add included the header file to the main file and both cpp files
This commit is contained in:
@ -0,0 +1,18 @@
|
||||
#include "OrderBookEntry.h"
|
||||
|
||||
OrderBookEntry::OrderBookEntry
|
||||
(
|
||||
double price,
|
||||
double amount,
|
||||
std::string timestamp,
|
||||
std::string product,
|
||||
OrderBookType orderType
|
||||
)
|
||||
:
|
||||
price{price},
|
||||
amount{amount},
|
||||
timestamp{timestamp},
|
||||
product{product},
|
||||
orderType{orderType}
|
||||
{
|
||||
}
|
||||
@ -0,0 +1,25 @@
|
||||
#include <string>
|
||||
|
||||
enum class OrderBookType
|
||||
{
|
||||
bid,
|
||||
ask
|
||||
};
|
||||
|
||||
class OrderBookEntry
|
||||
{
|
||||
public:
|
||||
OrderBookEntry
|
||||
(
|
||||
double price,
|
||||
double amount,
|
||||
std::string timestamp,
|
||||
std::string product,
|
||||
OrderBookType orderType
|
||||
);
|
||||
double price;
|
||||
double amount;
|
||||
std::string timestamp;
|
||||
std::string product;
|
||||
OrderBookType orderType;
|
||||
};
|
||||
BIN
CM2005 Object Oriented Programming/Topic 2/2.5.3/a.exe
Normal file
BIN
CM2005 Object Oriented Programming/Topic 2/2.5.3/a.exe
Normal file
Binary file not shown.
37
CM2005 Object Oriented Programming/Topic 2/2.5.3/main.cpp
Normal file
37
CM2005 Object Oriented Programming/Topic 2/2.5.3/main.cpp
Normal file
@ -0,0 +1,37 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "OrderBookEntry.h"
|
||||
|
||||
double computeAveragePrice(std::vector<OrderBookEntry>& entries)
|
||||
{
|
||||
double avg = 0;
|
||||
for(unsigned int i=0; i<entries.size(); ++i) //thid doesn't create a copy, ++i increments on the same variable
|
||||
{
|
||||
//std::cout << "The price is " << entries[i].price << std::endl;
|
||||
avg += entries[i].price;
|
||||
}
|
||||
return avg/entries.size();
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
std::vector<OrderBookEntry> orders;
|
||||
|
||||
orders.push_back( OrderBookEntry{
|
||||
10000,
|
||||
0.002,
|
||||
"2020/03/17 17:01:24.884492",
|
||||
"BTC/USDT",
|
||||
OrderBookType::bid});
|
||||
|
||||
orders.push_back( OrderBookEntry{
|
||||
50000,
|
||||
0.002,
|
||||
"2020/03/17 17:01:24.884492",
|
||||
"BTC/USDT",
|
||||
OrderBookType::bid});
|
||||
|
||||
std::cout << "Average price: " << computeAveragePrice(orders) << std::endl;
|
||||
}
|
||||
Reference in New Issue
Block a user