#include "Stock.h" #include const unsigned int Stock::historySize = 100; Stock::Stock( const string& symbol, double price ) : symbol_( symbol ) { for ( int i = 0; i < historySize; i++ ) history_.push_front( price ); } double Stock::price() const { return history_.front(); } void Stock::setPrice( double price ) { history_.push_front( price ); history_.pop_back(); } double Stock::gain( unsigned int time ) const { assert( time < historySize ); double price1 = price(); double price0 = history_[ time ]; return ( price1 - price0 ) / price0; } void Stock::printHistory() const { cout << "stock "<< symbol_ << " history: "; deque::const_iterator i; for ( i = history_.begin(); i != history_.end(); i++ ) cout << *i << " "; cout << endl; }