#include "Stock.h" // Constructs a new Stock with the given symbol and current price per share. Stock::Stock(string symbol, double sharePrice) { m_symbol = symbol; m_sharePrice = sharePrice; m_cost = 0.0; m_shares = 0; } // Returns this asset's total cost spent on all shares. double Stock::cost() const { return m_cost; } // Returns the market value of this stock, which is // the number of total shares times the share price. double Stock::marketValue() const { return shares() * sharePrice(); } // Returns the profit earned on shares of this asset. double Stock::profit() const { return marketValue() - cost(); } // Records a purchase of the given number of shares of // stock at the given price per share. void Stock::purchase(int shares, double sharePrice) { m_shares += shares; m_cost += shares * sharePrice; } // Sets the current share price of this asset. void Stock::setSharePrice(double sharePrice) { m_sharePrice = sharePrice; } // Returns the total number of shares purchased. int Stock::shares() const { return m_shares; } // Returns the price per share of this asset. double Stock::sharePrice() const { return m_sharePrice; }