#include #include #include "./Stock.h" // Constructs a new Stock with the given symbol and current price per share. Stock::Stock(string symbol, double share_price) { _symbol = symbol; _share_price = share_price; _cost = 0.0; _shares = 0; } // Gets the stock symbol. string Stock::get_symbol() const { return _symbol; } // Returns the total number of shares purchased. int Stock::get_shares() const { return _shares; } // Returns the price per share of this asset. double Stock::get_share_price() const { return _share_price; } // 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 get_shares() * get_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 (" << get_symbol() << "):" << endl; cout << " value: $" << setw(7) << GetMarketValue() << endl; cout << " cost: $" << setw(7) << GetCost() << endl; cout << " profit: $" << setw(7) << GetProfit() << endl; }