This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
double OopStockPortfolio::getPortfolioValue() | |
{ | |
double returnVal = 0; | |
std::for_each(stockPortfolio.begin(), stockPortfolio.end(), | |
[&returnVal](const StockPosition &a) { returnVal += (a.numShares * a.stockValue); }); | |
return returnVal; | |
} | |
double OopStockPortfolio::getPortfolioCost() | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
double DodStockPortfolio::getPortfolioValue() | |
{ | |
double returnVal = 0; | |
for (unsigned int i = 0; i < size; i++) | |
{ | |
// std::cout << &(numShares[i]) << std::endl; | |
// std::cout << &(stockValues[i]) << std::endl; | |
returnVal += (numShares[i] * stockValues[i]); | |
} | |
return returnVal; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct StockPosition | |
{ | |
std::string stockSymbol; | |
double stockValue; | |
double stockAverageCost; | |
unsigned int numShares; | |
}; | |
class OopStockPortfolio | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DodStockPortfolio | |
{ | |
private: | |
std::vector<std::string> stockSymbols; | |
std::vector<double> stockValues; | |
std::vector<double> stockAverageCosts; | |
std::vector<unsigned int> numShares; | |
std::unordered_map<std::string, int> stockIndices; | |
unsigned int size; | |
unsigned int getStockIndex(const std::string &stockSymbol); |