<aside> 💡 Key concepts
Learning Objectives
Starter code is available for download in Coursera: [Starter code]
</aside>
First, we will build the OrderBook class together. It contains the following functions:
constructor(filename)
: a constructor that takes in a csv file name and load the datagetKnownProduct()
: get known products would give us the list of all the known productsgetOrders(type, product, timestamp)
: retrieve a set of orders from the OrderBookIn the Topic4 starter project, create the OrderBook.h
and implement the headers of the above-mentioned functions.
#pragma once
#include "OrderBookEntry.h"
#include "CSVReader.h"
#include <string>
#include <vector>
class OrderBook
{
public:
// constructors, reading a csv data file
OrderBook(std::string filename);
// return vector of all known products in the dataset
std::vector<std::string> getKnownProducts();
// return vector of orders according to the sent filter
std::vector<OrderBookEntry> getOrders(OrderBookType type, std::string product, std::string timestamp);
};
Next, let’s create a OrderBook.cpp
file and implement the OrderBook
class hierarchy.
#include "OrderBook.h"
// constructors, reading a csv data file
OrderBook::OrderBook(std::string filename)
{
}
// return vector of all known products in the dataset
std::vector<std::string> OrderBook::getKnownProducts()
{
std::vector<std::string> products;
return products;
}
// return vector of orders according to the sent filter
std::vector<OrderBookEntry> OrderBook::getOrders(OrderBookType type, std::string product, std::string timestamp)
{
std::vector<OrderBookEntry> orders;
return orders;
}
Bring up the terminal and try to compile the OrderBook
class.
>> g++ -o orderbook CSVReader.cpp MerkelMain.cpp OrderBookEntry.cpp OrderBook.cpp main.cpp -std=c++11
>> ./orderbook
Next, let’s implement the constructor.
Create a private variable in the OrderBook.h
header file
// ...
class OrderBook
{
public:
// ...
**private:
std::vector<OrderBookEntry> orders;**
};