#ifndef _STLIST_H #define _STLIST_H #include "vector.h" #include "CPstring.h" #include "stock.h" // struct holds info for one stock, use struct to get used to // manipulating pointers struct StockNode { Stock stock; //Stock Object StockNode * next; //Pointer to Next Stock Object StockNode(); //Constructor StockNode(const string & symbol, char Exchange, double price, unsigned int volume, double volatility, const string & name); }; // class for storing/maintaining database of stock quotes // this class only stores StockNode objects, but the operations are // generic in that they could apply to a list of different kinds of // objects (except for specific Artist/Title searches) // // *** constructors: // StockList() -- create a list of size buckets // // *** destructor // ~StockList() -- called automatically when StockList // object goes out of scope // // *** functions to traverse list, uses concept of 'current' index into list // // void First() -- sets current index to the beginning // void Next() -- advances current index to next stock // bool IsDone() -- returns true when index is past end of list // void SetCurrent(string symbol) -- moves current item to point at stock // -- with given symbol (used as search) // Stock & Current() -- returns current item in list // // *** functions to determine size/contents of list // // int NumStocks() -- returns # of stocks in list // // *** changing contents of list // // void AddStock(const string & symbol, -- add stock to list // char Exchange, -- alphabetized // double price, // unsigned int volume, // double volatility, // const string & name); // // *** search functions class StockList { public: StockList(); ~StockList(); // for traversing/accessing list void First(); // reset current to front of list void Next(); // advance current to next item in list bool IsDone(); // return true iff iteration done Stock & Current(); // return current item in list bool SetCurrent(const string & symbol); // changes "current" // accessor functions int NumStocks() const; // return # items in list void Print(); // print all stocks void Print(char ch); // stocks starting with ch void Print(const string & symbol); // print one stock // mutator functions void Add(const string & symbol, // add stock in alphabetical order char Exchange, double price, unsigned int volume, double volatility, const string & name); void Delete(const string & symbol); // delete item with symbol void DeleteAll(); // delete all items from list private: Vector myList; // the CDs stored in a vector int myCount; // how many stocks // for iterating using First, IsDone, and Next int myBucket; // current element of list StockNode * myCurrent; // current stock void GetNextNonEmptyBucket(); // advance current and myBucket }; #endif // _STLIST_H not defined