#include #include "stock.h" #include "CPstring.h" // Constants static const double DEFAULT_VOLATILITY = 0.0; // default volatility static const double NULL_PRICE = DBL_MIN; // default price static const string NO_SYMBOL = "No Symbol"; // default symbol static const string DEFAULT_NAME = "No Name"; // default name static const char DEFAULT_EXCHANGE = '?'; // default exchange // *********************************************** // Member Functions of Stock class // // *********************************************** Stock::Stock() // postcondition: Fields initializes to DEFAULT values : mySymbol(NO_SYMBOL), myExchange(DEFAULT_EXCHANGE), myLast(NULL_PRICE), myVolume(0), myChange(NULL_PRICE), myVolatility(DEFAULT_VOLATILITY), myCompanyName(DEFAULT_NAME) { } Stock::Stock(const string & symbol, char Exchange, double price, unsigned int volume, double volatility, const string & name) // postcondition: all fields initialized to given data : mySymbol(symbol), myExchange(Exchange), myLast(price), myVolume(volume), myChange(0.0), myVolatility(volatility), myCompanyName(name) { } void Stock::SetSymbol(const string & symbol) // postcondition: Stock's symbol is set to symbol { mySymbol = symbol; } void Stock::SetExchange(char Exchange) // postcondition: Stock's exchange is set to Exchange { myExchange = Exchange; } void Stock::SetLast(double price) // postcondition: Stock's last price is set to price // stock's "change" is initialized to 0 { myLast = price; myChange = 0.0; } void Stock::SetCompanyName(const string & name) // postcondition: stock's company name is set to name { myCompanyName = name; } void Stock::AddTrade(double Price, unsigned int shares) // postcondition: Stock's Last, volume, and change updated { myChange += (Price - myLast); // calculate the change myLast = Price; // new last price myVolume += shares; // total volume increases } string Stock::GetSymbol () const // postcondition: returns stock's symbol { return mySymbol; } string Stock::GetCompanyName() const // postcondition: returns company name { return myCompanyName; } char Stock::GetExchange() const // returns stock exchange { return myExchange; } double Stock::GetLast() const // returns last { return myLast; } double Stock::GetChange() const // returns change in stock { return myChange; } unsigned int Stock::GetVolume() const // returns volume of stock traded { return myVolume; } double Stock::GetVolatility() const //Post Condition: Returns volatility { return myVolatility; } void Stock::Print() const { cout << mySymbol << '\t' << myExchange << '\t' << myLast << '\t' << myChange << '\t' << myVolume << '\t' << myCompanyName << endl; }