#include #include #include using namespace std; #include "holding.h" // Constructor -------------------------------------------- Constructor // Create a new Holding object using a stock's sticker symbol, the // number of shares, the price paid at purchase, and the current // price of the stock. // Note: Often the last two parameters will be the same value when // an object is created. // Holding::Holding(const string &Name, int Num, double PurchasePrice, double CurrentPrice ) { } // Default constructor -------------------------------- Default constructor // (This is required to store Holdings in an array.) // Set ticker to "Unitialized" and all numeric data members to zero. // Holding::Holding(void) { } // GetTicker (inspector) -------------------------------------- GetTicker() // Returns the value of the Holding's stock ticker symbol. // string Holding::GetTicker() const { } // GetNumShares (inspector) -------------------------------- GetNumShares() // Returns the value of the number of shares in the Holding. // int Holding::GetNumShares() const { } // GetCurrPrice (inspector) -------------------------------- GetCurrPrice() // Returns the current price of the stock stored in the Holding. // double Holding::GetCurrPrice() const { } // GetPurcPrice (inspector) -------------------------------- GetPurcPrice() // Returns the purchase price that we paid for the stock in the Holding. // double Holding::GetPurcPrice() const { } // GetValue (inspector) ---------------------------------------- GetValue() // Returns the total value of the stock Holding (based on // these current price and the number of shares). // double Holding::GetValue() const { } // SetTicker (mutator) ---------------------------------------- SetTicker() // void Holding::SetTicker(const string &s) { } // SetNumShares (inspector) -------------------------------- SetNumShares() // void Holding::SetNumShares(int num) { } // SetCurrPrice (inspector) -------------------------------- SetCurrPrice() // void Holding::SetCurrPrice(double price) { } // GetGainLoss (inspector) ---------------------------------- GetGainLoss() // Returns the gain (a positive number) or the loss (a negative number) // for the stock Holding. This is based on the current total value // compared to the total value when it was purchased. // double Holding::GetGainLoss() const { } // SetPurcPrice (mutator) ---------------------------------- SetPurcPrice() // void Holding::SetPurcPrice(double price) { } // Insert -------------------------------------------------------- Insert() // // Implementation provided for you. You are allowed to alter this if // you wish, but right now we see no reason to do so. // void Holding::Insert(ostream& sout) const { sout << left << setw(4) << GetTicker() << " " << right << setw(4) << GetNumShares(); sout << right << fixed << setprecision(2) << " Cur. Price: $" << setw(6) << GetCurrPrice() << " Value: $" << setw(8) << GetValue() << endl; sout << setw(9) << " " << " Pur. Price: $" << setw(6) << GetPurcPrice() << " Gain/Loss: $" << setw(8) << GetGainLoss() << endl; } // Extract ------------------------------------------------------- Extract() // Implementation provided for you. You do not really need this for the // assignment, but if you want to use it in your testing, you may find // this member function convenient. // void Holding::Extract(istream& sin) { sin >> Ticker >> NumShares >> CurrPrice; if (NumShares < 0) { cerr << "** Error: Number of shares should be > 0 not " << NumShares << endl << "** Setting number to " << Ticker << " to zero." << endl; SetNumShares(0.0); } if (CurrPrice < 0.0) { cerr << "** Error: Price should be > 0 not " << CurrPrice << endl << "** Setting price for " << Ticker << " to zero." << endl; SetCurrPrice(0.0); } } // Auxiliary Functions: // operator<< -------------------------------------------- operator<< // ostream& operator<<(ostream& sout, const Holding &h) { h.Insert(sout); return sout; } // operator>> --------------------------------------------- operator>> // istream& operator>>(istream& sin, Holding &h) { h.Extract(sin); return sin; }