<aside> 💡 Key concepts


Learning Objectives

Starter code is available for download in Coursera: [Starter code]

</aside>

4.1. Setup the OrderBook class

First, we will build the OrderBook class together. It contains the following functions:

In 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;**
};