/* CSE 333 Su12 lecture 14 demo: stocks_virtual/Stock.cc */
/* Gribble/Perkins */

// Implementation of class Stock

#include <iostream>
#include <iomanip>

#include "./Stock.h"

// Construct a new Stock with the given symbol and initial price per share,
// and no shares initially held.
Stock::Stock(string symbol, double share_price) {
  symbol_ = symbol;
  share_price_ = share_price;
  cost_ = 0.0;
  shares_ = 0;
}

// Return the stock symbol.
string Stock::get_symbol() const {
  return symbol_;
}

// Return the total number of shares purchased.
int Stock::get_shares() const {
  return shares_;
}

// Return the price per share of this stock.
double Stock::get_share_price() const {
  return share_price_;
}

// Set the current share price of this stock.
void Stock::set_share_price(double share_price) {
  share_price_ = share_price;
}

// Return the total cost spent to buy all shares of this stock.
double Stock::GetCost() const {
  return cost_;
}

// Return 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();
}

// Return the profit earned on this stock
double Stock::GetProfit() const {
  return GetMarketValue() - GetCost();
}

// Record 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 to cout.
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;
}