Below the Library.h file
#include<bits/stdc++.h>
using namespace std;
class Textbook{
public:
string title,author,ISBN;
Textbook* next;
Textbook(string t,string a,string
i){
this->title=t;
this->author=a;
this->ISBN=i;
next=NULL;
}
};
Below is the code of Library.cpp:
#include<bits/stdc++.h>
#include "Library.h"
using namespace std;
class library{
public:
Textbook *head=NULL;
void addBook(string title,string
author,string ISBN){
Textbook
*t;
t=new
Textbook(title,author,ISBN);
if(head==NULL){
head=t;
return;
}
else{
Textbook *temp,*prev=NULL;
temp=head;
while(temp!=NULL){
if(temp->title>=title)
break;
prev=temp;
temp=temp->next;
}
if(prev==NULL){
t->next=head;
head=t;
}
else{
prev->next=t;
t->next=temp;
}
}
}
void removeBook(string ISBN){
Textbook
*temp,*prev=NULL;
temp=head;
while(temp!=NULL){
if(temp->ISBN==ISBN){
if(prev==NULL){
head=head->next;
return;
}
prev->next=temp->next;
return;
}
prev=temp;
temp=temp->next;
}
throw "Error
occured.";
}
void print(){
Textbook
*temp;
temp=head;
while(temp!=NULL){
cout<<"Title:
"<<temp->title<<" Author:
"<<temp->author<<" ISBN:
"<<temp->ISBN<<endl;
temp=temp->next;
}
}
void print(string author){
Textbook
*temp;
temp=head;
while(temp!=NULL){
if(temp->author==author)
cout<<"Title:
"<<temp->title<<" Author:
"<<temp->author<<" ISBN:
"<<temp->ISBN<<endl;
temp=temp->next;
}
}
void print(char start){
Textbook
*temp;
temp=head;
while(temp!=NULL){
if(temp->author.at(0)==start){
cout<<"Title:
"<<temp->title<<" Author:
"<<temp->author<<" ISBN:
"<<temp->ISBN<<endl;
}
temp=temp->next;
}
}
Textbook* at(int index){
if(index<0)
return NULL;
Textbook
*temp=head;
int i=0;
while(i<index
&& temp!=NULL){
temp=temp->next;
++i;
}
if(i<index)
return NULL;
return
temp;
}
bool isEmpty(){
if(head==NULL)
return true;
return
false;
}
int getSize(){
if(head==NULL)
return 0;
Textbook
*temp;
temp=head;
int n=0;
while(temp!=NULL){
temp=temp->next;
++n;
}
return n;
}
};
Sample Run:
library l;
l.addBook("Algorithms","asdf","1234");
l.addBook("The C Programming","fdge","3453");
l.addBook("The Society of mind","asdf","4356");
cout<<endl<<l.getSize()<<endl;
l.print();
l.addBook("Applied","ertrh","454");
l.print();
cout<<l.getSize()<<endl;
l.print("fdge");
l.print('a');
l.removeBook("3453");
l.print();
cout<<endl<<l.getSize();
Output:
Title: Algorithms Author: asdf ISBN:
1234
Title: Applied Author: ertrh ISBN: 454
Title: The C Programming Author: fdge ISBN: 3453
Title: The Society of mind Author: asdf ISBN: 4356
4
Title: The C Programming Author: fdge ISBN: 3453
Title: Algorithms Author: asdf ISBN: 1234
Title: The Society of mind Author: asdf ISBN: 4356
Title: Algorithms Author: asdf ISBN: 1234
Title: Applied Author: ertrh ISBN: 454
Title: The Society of mind Author: asdf ISBN: 4356
3
C++ In this homework, you will implement a single linked list to store a list of computer science textbooks. Ever...
Please provide original Answer, I can not turn in the same as my classmate. thanks In this homework, you will implement a single linked list to store a list of computer science textbooks. Every book has a title, author, and an ISBN number. You will create 2 classes: Textbook and Library. Textbook class should have all above attributes and also a “next” pointer. Textbook Type Attribute String title String author String ISBN Textbook* next Textbook Type Attribute String title String...
You need to program a simple book library system. There are three java classes Book.java // book object class Library.java //library class A2.java //for testing The Book.java class represents book objects which contain the following fields title: a string which represents the book title. author: a string to hold the book author name year: book publication year isbn: a string of 10 numeric numbers. The book class will have also 3 constructors. -The default no argument constructor - A constructor...
A library maintains a collection of books. Books can be added to and deleted from and checked out and checked in to this collection. Title and author name identify a book. Each book object maintains a count of the number of copies available and the number of copies checked out. The number of copies must always be greater than or equal to zero. If the number of copies for a book goes to zero, it must be deleted from the...
How to write the insert, search, and remove functions for this hash table program? I'm stuck... This program is written in C++ Hash Tables Hash Table Header File Copy and paste the following code into a header file named HashTable.h Please do not alter this file in any way or you may not receive credit for this lab For this lab, you will implement each of the hash table functions whose prototypes are in HashTable.h. Write these functions in a...
please Code in c++ Create a new Library class. You will need both a header file and a source file for this class. The class will contain two data members: an array of Book objects the current number of books in the array Since the book array is moving from the main.cc file, you will also move the constant array size definition (MAX_ARR_SIZE) into the Library header file. Write the following functions for the Library class: a constructor that initializes...
C++ Help. I am new to Visual Studio and C++ so please include comments! Please follow the directions and make as simple as possible. Write a C++ program that reads the following list of input data (book.dat) and then allows users to search and view the books from a Menu List all available books Search for book using A. Title or B. ISBN? Exit Program The format of the file is as follows: // The title of the book // ...
Using C++ Skills Required Create and use classes Exception Handling, Read and write files, work vectors. Create Functions, include headers and other files, Loops(while, for), conditional(if, switch), datatypes, etc. Assignment You work at the computer science library, and your boss just bought a bunch of new books for the library! All of the new books need to be cataloged and sorted back on the shelf. You don’t need to keep track of which customer has the book or not, just whether...
I wrote this code but there’s an issue with it : #include <iostream> #include <vector> #include <string> #include <fstream> using namespace std; class Borrower { private: string ID, name; public: Borrower() :ID("0"), name("no name yet") {} void setID(string nID); void setName(string nID); string getID(); string getName(); }; void Borrower::setID(string nID) { ID = nID; } void Borrower::setName(string nname) { name = nname; } string Borrower::getID() { return ID; } string Borrower::getName() { return name; } class Book { private: string...
Objectives: The main objective of this assignment is checking students’ ability to implement membership functions. After completing this assignment, students will be able to: implement member functions convert a member function into a standalone function convert a standalone function into a member function call member functions implement constructors use structs for function overloading Problem description: In this assignment, we will revisit Assignment #1. Mary has now created a small commercial library and has managed...
Part 1 The purpose of this part of the assignment is to give you practice in creating a class. You will develop a program that creates a class for a book. The main program will simply test this class. The class will have the following data members: A string for the name of the author A string for the book title A long integer for the ISBN The class will have the following member functions (details about each one are...