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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
#include <iostream>
#include <map>
struct Price
{
int ref_no;
std::string symbol;
std::string date;
std::string closing_price;
Price(int aRef, std::string aSymbol, std::string aDate, std::string aClosing_price)
{
ref_no = aRef;
symbol = aSymbol;
date = aDate;
closing_price = aClosing_price;
}
};
std::ostream& operator<<(std::ostream& out, Price aPrice)
{
out
<< aPrice.ref_no << ' '
<< aPrice.symbol << ' '
<< aPrice.date << ' '
<< aPrice.closing_price;
return out;
}
struct Stock
{
std::string symbol;
std::string name;
Stock(std::string aSymbol, std::string aName)
{
symbol = aSymbol;
name = aName;
}
};
std::ostream& operator<<(std::ostream& out, Stock aStock)
{
out
<< aStock.symbol << ' '
<< aStock.name;
return out;
}
int main()
{
Stock apple( "APPL", "Apple Inc. Common Stock");
Stock starb( "SBUX", "Starbucks Corporation");
Price ap1(1, "APPL", "12/31/2019", "$293.65");
Price ap2(2, "APPL", "12/30/2019", "$291.52");
Price ap3(3, "APPL", "12/27/2019", "$289.80");
Price ap5(4, "SBUX", "12/31/2019", "$87.92");
Price ap7(5, "SBUX", "12/30/2019", "$83.45");
std::map<std::string, Stock> Stocks;
Stocks.emplace(apple.symbol, apple);
Stocks.emplace(starb.symbol, starb);
std::map<int, Price> Prices;
Prices.emplace(ap1.ref_no, ap1);
Prices.emplace(ap2.ref_no, ap2);
Prices.emplace(ap3.ref_no, ap3);
Prices.emplace(ap5.ref_no, ap5);
Prices.emplace(ap7.ref_no, ap7);
for(auto i:Stocks)
{
std::cout << i.second << '\n';
for(auto j: Prices)
{
if(i.first == j.second.symbol) // THE 'LINK'
std::cout << '*' << j.second << '\n';
}
std::cout << '\n';
}
return 0;
}
|