This is a C++ question.
Implement a class StockMarket in C++ that has the two following functions:
class StockMarket
{
public:
void addTrade(string stockName, int share);
- This function keeps track the number of shares transacted for a stock by adding the trade information
void printTop(int numberOfStock);
- This function prints the top numberOfStock stocks that has the highest number of transacted shares
}
And here's a sample calling sequence that uses the above class:
StockMarket stockMarket;
stockMarket.addTrade("GOOGLE", 50);
stockMarket.addTrade("APPLE", 150);
stockMarket.addTrade("GOOGLE", 100);
stockMarket.addTrade("MSFT", 250);
stockMarket.addTrade("GOOGLE", 200);
stockMarket.printTop(2);
Expected output:
GOOGLE 350
MSFT 250