#include #include #include using namespace std; // Note to students: If you look in portfolio.h you'll see it includes // holding.h since you can't have portfolios without holdings. // So no need to include holding.h here. #include "portfolio.h" // Constructor ----------------------------------------------- Constructor // Create a new Portfolio object given the name you want to use to // identify the object. // Portfolio::Portfolio(const string& name) { } // GetName (inspector) ----------------------------------------- GetName() // string Portfolio::GetName() const { } // GetNumStocks (inspector) ----------------------------------- GetNumStocks() // Returns the number of stock Holdings contained in the Portfolio. // int Portfolio::GetNumStocks() const { } // FindHolding ------------------------------------------------- FindHolding() // Purpose: This function searches for a Holding in the Portfolio that // has the parameter "ticker" as its ticker symbol. // Return value: If the matching Holding is found, the function returns // its position in the list of Holdings. If no match is found, the // function returns the last position plus one. // int Portfolio::FindHolding(const string &ticker) const { } // GetTotalValue (inspector) ---------------------------------- GetTotalValue() // Purpose: This returns that grand total of all the Holdings values. // Each Holding's value is the number of stocks times the current price. // double Portfolio::GetTotalValue() const { } // UpdatePrice ---------------------------------------------- UpdatePrice() // Purpose: This function searches the Portfolio for a Holding that // matches the first argument "ticker". If found that Holding's // current price is updated using the second argument "price". // Return value: If the Holding is found, return true. If not, return false. // Errors detected: If following error is detected, print // an appropriate message and return false. // Error 1: Second argument is negative. // bool Portfolio::UpdatePrice(const string& ticker, double price) { } // SellShares ------------------------------------------------- SellShares() // // Purpose: This function searches the Portfolio for a Holding that // matches the first argument "ticker". If found then that Holding's // number of shares is updated by subtracting the second argument "shares" // to reflect that this number of shares has been sold by the user. // Also, if this sells all the shares, remove the Holding from the Portfolio. // Return value: If the Holding is found and no error occurs, return true. // If not, return false. // Errors detected: If either of the following errors is detected, print // an appropriate message and return false. // Error 1: Second argument is negative. (Impossible to sell a negative // number of shares.) // Error 2: Selling the specified number of shares would leave the remaining // number of shares in the holding less than zero. // bool Portfolio::SellShares(const string& ticker, int shares) { } // AddHolding ------------------------------------------------- AddHolding() // // Purpose: A new Holding for the stock given as the first parameter is added // to the Portfolio. The parameters are the stock's ticker symbol, the // number of shares in the Holding, the price of the stock when it was // purchased, and the current price of the stock. (The 3rd and 4th parameters // may often be the same.) // NOTE: This function makes no guarantee about what position the new Holding // will occupy. (It may be in the first position, the last, or anywhere.) // Errors detected: If any of the following errors are detected, the function // prints an appropriate message about the error, and no new Holding is added. // Error 1: The number of shares is less than zero. // Error 2: The price for the stock is less than zero. // Error 3: It is impossible for the Portfolio to contain any more Holdings. // Error 4: There is already a Holding in the Portfolio with this ticker. // void Portfolio::AddHolding(const string &ticker, int quantity, double purcPrice, double currPrice) { } // AddHolding ------------------------------------------------- AddHolding() // // Purpose: A new Holding for the stock given as the first parameter is added // to the Portfolio. // Except for the difference in its parameters, this behaves exactly as the // other overloaded function AddHolding(). // Note to students: Perhaps one of these functions should call the other one? // Why duplicate the same code? Our motto: Write once, and reuse when possible! // void Portfolio::AddHolding(const Holding& h) { } // DeleteHolding ------------------------------------------------- DeleteHolding() // Purpose: The Holding with the given ticker is removed from the Portfolio. // Return value: If the ticker cannot be found in the Portfolio, return false. // If it can and the Holding is removed, return true. // NOTE: When this function removes a Holding, the remaining Holdings may // or may not be in their original order. (The function does not guarantee // that it preserves the original order.) // bool Portfolio::DeleteHolding(const string &ticker) { } // Insert --------------------------------------------------------- Insert() // // Purpose: This function displays the current contents of the Portfolio. // It prints a heading line with the Portfolio name, then output for // each Holding in the Portfolio. Finally it prints the total value // of all Holdings and the overall gain/loss for the Portfolio. // For example, the output produced might look like this: // // Portfolio: BlueChips // LLY 300 Cur. Price: $ 76.50 Value: $22950.00 // Pur. Price: $ 77.00 Gain/Loss: $ -150.00 // KO 250 Cur. Price: $ 45.00 Value: $11250.00 // Pur. Price: $ 44.00 Gain/Loss: $ 250.00 // HD 100 Cur. Price: $ 41.00 Value: $ 4100.00 // Pur. Price: $ 42.00 Gain/Loss: $ -100.00 // GE 100 Cur. Price: $ 45.50 Value: $ 4550.00 // Pur. Price: $ 44.00 Gain/Loss: $ 150.00 // Total value: $ 42850.00 // Total gain/loss: $ 150.00 // void Portfolio::Insert(ostream& sout) const { } // DisplayProportions ----------------------------------------- DisplayProportions() // // Purpose: Prints a list of each Holdings ticker plus the percentage that // stock's value is in terms of the total portfolio, plus the percent // that stock's gain/loss is in terms of the total gains or losses. // For proportion of gain or loss, if the stock has gained value, we // print its contribution to the total gain for the Portfolio. If it's // lost value, we calculate its contribution to the total loss. (See example.) // Note: If the total gain/loss of the Portfolio happens to be zero, print // "N/A" (meaning not applicable) instead of a percentage for each Holding's // gain or loss. (Otherwise we'd be dividing by zero. Assume that the total // value of a Porfolio can never be zero.) // For example, for the Portfolio contents shown above for Insert, the output // might be formatted like this: // // Portfolio "BlueChips" Holdings: Proportional Values and Gains/Losses: // Stock %Value %Gain/Loss // LLY 53.56% -60.00% // KO 26.25% 62.50% // HD 9.57% -40.00% // GE 10.62% 37.50% // void Portfolio::DisplayProportions(ostream& sout) const { } // operator<< ------------------------------------------------- operator<< // // Purpose: This operator calls the member function Insert to display // the current contents of a Portfolio. // ostream& operator<<(ostream& sout, const Portfolio &p) { p.Insert(sout); return sout; }