#ifndef _CDLIST_H #define _CDLIST_H #include "vector.h" #include "CPstring.h" // declaration for a class to store/maintain a list of CD's // struct holds info for one CD, use struct since this is really // a simple "record", i.e., only needs Get/Set operations struct CDinfo { int id_number; // as assigned by BMG string title; // title of CD, e.g., Workingman's Dead double price; // to buy CD string group; // artist/grop, e.g., Grateful Dead // define default and other constructor CDinfo(); CDinfo(int id, const string & t, double p, const string & g); }; // CD info can be inserted onto an ostream ostream & operator << (ostream & output, const CDinfo & cd); // class for storing/maintaining list of CD's (of type CDinfo) // this class only stores CDinfo 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: // CDlist() -- default, create a list of capacity zero // CDlist(int size) -- create a list of capacity size // // example: // CDlist list(2000); // can store 2000 CD's // *** destructor // ~CDlist() -- called automatically when CDlist 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 by one // bool IsDone() -- returns true when index is past end of list // CDinfo Current() -- returns current item in list // // example: (prints information in list) // // // read information into CD // for(list.First(); !list.IsDone(); list.Next()) // { // cout << list.Current() << endl; // } // // // *** functions to determine size/contents of list // // int Size() -- returns # of entries in list // bool IsFull() -- returns true if list is full (at capacity) // // void SetSize(int size) -- set capacity of list to size // // *** changing contents of list // // void Add(const CDinfo & cd) -- add cd to end of list (if room) // void Delete(int id) -- deletes item with id_number id // void DeleteAll() -- delete all items from list // // *** search functions // // (the first parameter, a pointer to a string data member, is // an advanced C++ feature) // // void Search(string CDinfo:: *, CDlist & match) // // search by either artist or title by passing appropriate // field as first parameter. // searches for string, either as part of artist/title // The matches are for occurrence of first param string as substring // so that given the name "Dead", the following titles match // // Dead Letter Office // Rock Is Dead But It Won't Lie Down // Live Dead // Workingman's Dead // The Queen is Dead : There is a Light... // Dead Serious // De La Soul Is Dead // // all the matching CD's are stored in parameter match // class CDlist { public: CDlist(); CDlist(int size); ~CDlist(); // 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 current past end of list CDinfo Current(); // return current item in list int Size(); // return # items in list bool IsFull(); // return true iff # items = capacity void SetSize(int size); // set capacity of list to size void Add(const CDinfo & cd); // add cd to list (at end) void Delete(int id); // delete item with idnum from list void DeleteAll(); // delete all items from list void Print(); // print items in list // search for artist/title matches void Search(string CDinfo::* str, const string & name, CDlist & match); private: Vector myList; // the CDs stored in a vector int myCount; // how many cd's stored int myIndex; // current element of list }; #endif // _LIST_H not defined