-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathiterativeStyles.cpp
More file actions
68 lines (58 loc) · 1.9 KB
/
iterativeStyles.cpp
File metadata and controls
68 lines (58 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <iostream>
#include <string>
#include <vector>
//specifying a new data type for bid,ask
enum class OrderBookType{bid,ask};
//Define the class OrderBookEntry
class OrderBookEntry
{
public:
// Constructor with member initialization list
OrderBookEntry(double price,
double amount,
std::string timestamp,
std::string product,
OrderBookType orderType)
: price(price),
amount(amount),
timestamp(timestamp),
product(product),
orderType(orderType)
{
// Constructor body
}
public:
double price;
double amount;
std::string timestamp;
std::string product;
OrderBookType orderType;
};
int main()
{
//Define a vector named 'orders' to store instances of the 'OrderBookEntry' class.
std::vector<OrderBookEntry> orders;
//push an instance of the 'OrderBookEntry' class to the 'orders'
orders.push_back(OrderBookEntry{23594,0.00000033,"2020/03/17 17:01:24.884492","DOGE/BTC",OrderBookType::ask});
orders.push_back(OrderBookEntry{25000,0.00000078,"2020/03/18 17:01:24.884492","DOGE/BTC",OrderBookType::bid});
orders.push_back(OrderBookEntry{25600,0.00000093,"2020/03/19 17:01:24.884492","DOGE/BTC",OrderBookType::ask});
std::cout << orders[0].price << std::endl;
for(OrderBookEntry order:orders)
{
std::cout << order.price << std::endl;
}
//using ampersand make it more efficint as it will directly reference to the object instead of copy it
for(OrderBookEntry& order:orders)
{
std::cout << order.price << std::endl;
}
for(unsigned int i=0;i<orders.size();++i)
{
std::cout << orders[i].price << std::endl;
}
for(unsigned int i=0; i<orders.size(); ++i)
{
std::cout << orders.at(i).price << std::endl;
}
return 0;
}