#include #include #include "./Stock.h" using std::cout; using std::endl; using std::setw; using std::string; // Constructs a new Stock with the given symbol and current price per share. Stock::Stock(const string &symbol, double share_price) { symbol_ = symbol; share_price_ = share_price; cost_ = 0.0; shares_ = 0; } // Sets the current share price of this asset. void Stock::set_share_price(double share_price) { share_price_ = share_price; } // Returns this asset's total cost spent on all shares. double Stock::GetCost() const { return cost_; } // Returns the market value of this stock, which is the total number // of shares times the share price. double Stock::GetMarketValue() const { return shares() * share_price(); } // Returns the profit earned on this stock. double Stock::GetProfit() const { return GetMarketValue() - GetCost(); } // Records a purchase of the given number of shares of stock at the // given price per share. void Stock::Purchase(int shares, double share_price) { shares_ += shares; cost_ += shares * share_price; } // Print out the stock information. void Stock::Print() const { cout << "Stock (" << symbol() << "):" << endl; cout << " value: $" << setw(8) << GetMarketValue() << endl; cout << " cost: $" << setw(8) << GetCost() << endl; cout << " profit: $" << setw(8) << GetProfit() << endl; }