/* Rafay Ahmad 23I-2526 */ #include #include using namespace std; class Library{ char* bookTitle; char* author; int bookID; int quantity; float price; static int totalBooks; public: Library(const Library& library) : bookID(library.bookID), quantity(library.quantity), price(library.price){ bookTitle = new char[strlen(library.bookTitle)]; strcpy(this->bookTitle, library.bookTitle); author = new char[strlen(library.author)]; strcpy(this->author, library.author); } char* getBookTitle(){ return bookTitle; } char* getAuthor(){ return author; } int getBookID(){ return bookID; } int getQuantity(){ return quantity; } float getPrice(){ return price; } void setBookTitle(char* title){ bookTitle = title; } void setAuthor(char* authorName){ author = authorName; } void setBookID(int id){ bookID = id; } void setQuantity(int q){ quantity = q; } void setPrice(float p){ price = p; } static void setTotalBooks(int totalBooks){ Library::totalBooks = totalBooks; } static int getTotalBooks(){ return Library::totalBooks; } void calcTotalPrice(){ cout<<"Total Price: "<price * this->quantity<books[j].getBookTitle()[0]){ Library temp(books[i]); books[i] = Library(books[j]); books[j] = Library(temp); } } } } void sortByAuthor(Library books[]){ for(int i=0;ibooks[j].getAuthor()[0]){ Library temp(books[i]); books[i] = Library(books[j]); books[j] = Library(temp); } } } } void sortByPrice(Library books[]){ for(int i=0;ibooks[j].getPrice()){ Library temp(books[i]); books[i] = Library(books[j]); books[j] = Library(temp); } } } } bool searchByTitle(Library books[], char* titlename){ for(int i=0;imax.getPrice()) max = Library(books[i]); } return max; } int main(){ // take input and test all fucntions Library::setTotalBooks(0); Library books[100]; char title[100], author[100]; int id, quantity; float price; cout<<"Enter number of books: "; int n; cin>>n; for(int i=0;i>title; cout<<"Enter author name: "; cin>>author; cout<<"Enter book ID: "; cin>>id; cout<<"Enter quantity: "; cin>>quantity; cout<<"Enter price: "; cin>>price; Library book; book.setBookTitle(title); book.setAuthor(author); book.setBookID(id); book.setQuantity(quantity); book.setPrice(price); addBook(books, book); } return 0; }