09 Lab (Graded) - Morning
09 Lab (Graded) - Morning
Lab 09
Da t a
Lab 09 Instructions
S t r u c tu r e s
A n d
A l g o r i th m s
Marks 100
Work on this lab individually. You can use your books, notes, handouts etc. but you are not allowed to borrow anything from your peer student. What you have to do Implement the BookList class which stores Books in unsorted order. Your class declarations should look like: class Book { friend class BookList; private: int id; string title; float price; Book *next;
//id of a book. //name of a book. //price of a book. //address of the next available object. //parameterized constructor
public: Book(int id, string title, float price, Book *next); }; class BookList { private: Book *head; Book *cursor; public: BookList(); ~BookList(); };
//start of the list //current item of the list //default constructor //destructor
The BookList class should also have the following public member functions: void insert (const Book &newItem) Inserts newItem into a list. If the list is not empty, then inserts newItem after the cursor. Otherwise, inserts newItem as the first (and only) data item in the list. In either case, moves the cursor to newItem. void remove () Remove the data item marked by the cursor from a list. If the resulting list is not empty, then moves the cursor to the data item that followed the deleted data item. If the deleted data item was at the end of the list, then moves the cursor to the beginning of the list. void search (string title) This function searches for book(s) based on its title in the book list. It should dispaly all the information about the book(s) if found otherwise display an appropriate message. void replace (const Book &newItem) Replace the data item marked by the cursor with newItem. The cursor remains at newItem. bool isEmpty () const Returns true if a list is empty. Otherwise, returns false. bool isFull () const Returns true if a list is full. Otherwise, returns false. void gotoBeginning () Moves the cursor to the beginning of the list
Page 1 of 2
Lab 09
void gotoEnd () Moves the cursor to the end of the list. Book getCursor () Returns a copy of the data item marked by the cursor. void showStructure () const Outputs the data items in a list. If the list is empty, outputs Empty list. In the main function, your program should take the data of books from a text file input.txt and store the info of each book into the book list. The file is in the following format: id; line break, title; line break, price and then a blank line followed by the data of next book, exactly in the same order as described above. Test the functionality of your BookList class by creating some of its objects.
BEST OF LUCK
Page 2 of 2