// lbooklst.h // ---------------------------------------------------------------------- // Do not modify this file. // declaration and consts for class LibraryBookList, an unsorted vector // of LibraryBook objects // modified copy of ListA.h/cpp, Carrano et al. // // CSE 143 // Homework 3 // http://www.cs.washington.edu/education/courses/143/00su/homework/ // 05 Jul 2000; Ken Yasuhara #ifndef _LBOOKLST_H_ #define _LBOOKLST_H_ #include "lbook.h" const int MAX_BOOK_COUNT = 100; const int BOOK_ENTRIES_PER_SCREEN = 4; // see print method class LibraryBookList { public: // constructs an empty list LibraryBookList(); // constructs a list initialized from data file w/ given name; see // private method readFile LibraryBookList(char dataFileName[]); // (destructor is supplied by compiler) // // standard list operations // // Determines whether a list is empty. // Precondition: None. // Postcondition: Returns true if the list is empty, // otherwise returns false. bool isEmpty(); // Determines the length of a list. // Precondition: None. // Postcondition: Returns the number of items // that are currently in the list. int getLength(); // Inserts an item into a list. // Precondition: newPosition indicates where the // insertion should occur. newItem is the item to be // inserted. // Postcondition: If insertion was successful, newItem is // at position newPosition in the list, other items are // renumbered accordingly, and success is true; // otherwise success is false. // Note: Insertion will not be successful if // newPosition < 0 or > getLength(). void insertItem(int newPosition, LibraryBook newItem, bool &success); // Deletes an item from a list. // Precondition: position indicates where the deletion // should occur. // Postcondition: If 0 <= position < getLength(), // the item at position position in the list is // deleted, other items are renumbered accordingly, // and success is true; otherwise success is false. void deleteItem(int position, bool &success); // Retrieves a list item by position number. // Precondition: position is the number of the item to // be retrieved. // Postcondition: If 0 <= position < getLength(), // retrievedItem is the value of the desired item and // success is true; otherwise success is false. void retrieveByPosition(int position, LibraryBook &retrievedItem, bool &success); // replaces item at given position w/ given (updated) item; if // position is in valid range (from 0 to getLength() - 1), success // is set to true and update is successful void updateItem(int position, LibraryBook updatedItem, bool &success); // // specialized list operations // // attempts to find item w/ given ID and assigns a copy to // retrievedItem; success is set to true only if an item w/ given ID // exists in the list void retrieveByID(int ID, LibraryBook &retrievedItem, bool &success); // attempts to find item w/ given ID and returns its position; // success is set to true only if an item w/ given ID exists in the // list; if not, success is set to false and method returns -1 int findPositionByID(int ID, bool &success); // prints list items in increasing order from position 0 void print(); private: LibraryBook itemArray[MAX_BOOK_COUNT]; // array of list items int itemCount; // number of items currently in list // used by data file constructor; opens given file and reads book // catalogue data into this list void readFile(char fileName[]); }; #endif // _LBOOKLST_H_