Skip to content

Instantly share code, notes, and snippets.

View kennedysean's full-sized avatar
🎯
Focusing

Sean Kennedy kennedysean

🎯
Focusing
View GitHub Profile
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()
{
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;
struct StockPosition
{
std::string stockSymbol;
double stockValue;
double stockAverageCost;
unsigned int numShares;
};
class OopStockPortfolio
{
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);