#ifndef __BOOKS_HPP_ #define __BOOKS_HPP_ #include #include #include #include using std::cerr; using std::string; using std::ostream; using std::istream; using std::cout; using std::cin; using std::endl; class Book { string id; // a six-digit numeric ID. Can begin with 0, so we /eed a string to store. string authorName; // Author name string title; // book title int edition; // edition int year; // year published string isbn; // ISBN 10-digit public: Book(); Book( string sid, string fName, string lName, int edition, int year, string isbn ); int getEdition() const; void setEdition( int edition ); string getAuthor() const; void setAuthor( string aName ); string getTitle() const; void setTitle( string title ); string getID() const; void setID( string sID ); int getYear() const; void setYear( int year ); string getISBN() const; void setISBN( string sIsbn ); friend ostream& operator>( istream &is, Book &s ); friend void Sort( Book bookList[], int size, short field ); }; #endif // Getters and setters for each of the private fields. int Book::getEdition() const { return edition; } void Book::setEdition( int edition ) { this->edition = edition; } string Book::getAuthor() const { return authorName; } void Book::setAuthor( string aName ) { authorName = aName; } string Book::getTitle() const { return title; } void Book::setTitle( string tName ) { title = tName; } string Book::getID() const { return id; } void Book::setID( string sID ) { if( id.length() == 6 ) id = sID; } string Book::getISBN() const { return isbn; } void Book::setISBN( string sIsbn ) { isbn = sIsbn; } ostream& operator>( istream &is, Book &s ) { string str=""; getline( is, str ); if( is.fail() ) { return is; } std::stringstream jStream( str ); string id="", author="", title="", isbn=""; string edition="", year=""; getline( jStream, id, ',' ); getline( jStream, author, ',' ); getline( jStream, title, ',' ); getline( jStream, edition, ',' ); getline( jStream, year, ',' ); getline( jStream, isbn ); Book newBook( id, author, title, stoi(edition), stoi(year), isbn ); s = newBook; return is; } Book::Book() { id=authorName=title=isbn=""; edition=1; year=1970; } Book::Book( string sid, string fName, string lName, int edition, int year, string isbn ) { d=sid; authorName=fName; title=lName; this->isbn=isbn; this->edition=edition; this->year = year; } template void Swap( T &a, T &b ) { T temp =a; a=b; b=temp; } void Sort( Book bookList[], int size, short field ) { for( int i = 0; i bookList[j].id ) Swap( bookList[i], bookList[j] ); break; case 2: if( bookList[i].authorName > bookList[j].authorName ) Swap( bookList[i], bookList[j] ); break; case 3: if( bookList[i].title > bookList[j].title ) Swap( bookList[i], bookList[j] ); break; case 4: if( bookList[i].edition > bookList[j].edition ) Swap( bookList[i], bookList[j] ); break; case 5: if( bookList[i].year > bookList[j].year ) Swap( bookList[i], bookList[j] ); break; case 6: if( bookList[i].isbn > bookList[j].isbn ) Swap( bookList[i], bookList[j] ); break; } } } } int LoadDatabase( Book *books) { std::ifstream infile("bookinput.dat"); if( infile.fail() ) return -1; string iString=""; Book newBook; int bookNum=0; while( infile >> newBook ) { books[bookNum++] = newBook; } if (bookNum==0 ) { cout > choice; cin.ignore(); switch( toupper(choice) ) { case 'A': /* Add record */ { cout > newBook; library[bookNum++]=newBook; cout > lName; int i=0; bool found=false; for( i=0; i> sortChoice; cin.ignore(); switch( sortChoice ) { case '1': Sort( sortedBooks, bookNum, 1 ); break; case '2': Sort( sortedBooks, bookNum, 2 ); break; case '3': Sort( sortedBooks, bookNum, 3 ); break; case '4': Sort( sortedBooks, bookNum, 4 ); break; case '5': Sort( sortedBooks, bookNum, 5 ); break; case '6': Sort( sortedBooks, bookNum, 6 ); break; default: break; } for( int i=0; i Problemn: An even "Beefier" Book Database This homework will carry on our work on the book database. A solution file for homework 9 is going to be provided, in case you need it. However, you are not required to use this, as long as your own solution is complete and 100% correct as per the requirements of homework 9 1. Program Tasks ("What do I have to do exactly?") In this homework, you will extend your book database from homework 9 in the following way: Add a feature to delete a record from the book database. The book to be deleted can be searched for by any attribute of the book. This means, the user may want to search for the book to be deleted by ID, title, author name, edition, year or ISBN number. Only one attribute will be used to search for the book. 1. 2. The search to find the book to be deleted will be conducted by the binary search algorithml, (as opposed to linear search which you already have done in homework 9) which we have discussed in class 3. These two features will be added to the program that you completed in homework 9. As mentioned, a complete solution is already given, so you just have to add these two features Problemn: An even "Beefier" Book Database This homework will carry on our work on the book database. A solution file for homework 9 is going to be provided, in case you need it. However, you are not required to use this, as long as your own solution is complete and 100% correct as per the requirements of homework 9 1. Program Tasks ("What do I have to do exactly?") In this homework, you will extend your book database from homework 9 in the following way: Add a feature to delete a record from the book database. The book to be deleted can be searched for by any attribute of the book. This means, the user may want to search for the book to be deleted by ID, title, author name, edition, year or ISBN number. Only one attribute will be used to search for the book. 1. 2. The search to find the book to be deleted will be conducted by the binary search algorithml, (as opposed to linear search which you already have done in homework 9) which we have discussed in class 3. These two features will be added to the program that you completed in homework 9. As mentioned, a complete solution is already given, so you just have to add these two features