Question
implement library.cpp and book.cpp by using c++ and show the output. Library.h #pragma once #include #include namespace cs20a { using namespace std; class Book {
implement library.cpp and book.cpp by using c++ and show the output.
Library.h
#pragma once #include
namespace cs20a { using namespace std; class Book { public: Book(); Book(string author, string title, int copies = 1, int checkedOut = 0);
string getAuthor() const; string getTitle() const;
void setAuthor(string author); void setTitle(string title);
int getCopies() const; int getCheckedOut() const;
void addCopy(); void deleteCopy();
void checkOut(); void checkIn();
friend ostream& operator << (ostream& outs, const Book& book);
private: string author, title; int copies, checkedOut; }; }
Library.cpp
#include
namespace cs20a { Library::Library() {}
ostream & operator<<(ostream & outs, const Library & library) { for (int i = 0; i < library.getTotalBooks(); i++) outs << library.books[i] << endl;
return outs; }
//*** Code goes here ***// //*** Code goes here ***// //*** Code goes here ***//
}
Book.h
#pragma once #include
namespace cs20a { using namespace std; class Book { public: Book(); Book(string author, string title, int copies = 1, int checkedOut = 0);
string getAuthor() const; string getTitle() const;
void setAuthor(string author); void setTitle(string title);
int getCopies() const; int getCheckedOut() const;
void addCopy(); void deleteCopy();
void checkOut(); void checkIn();
friend ostream& operator << (ostream& outs, const Book& book);
private: string author, title; int copies, checkedOut; }; }
Book.cpp
#include
namespace cs20a { Book::Book() : author(), title(), copies(1), checkedOut(0) {}
Book::Book(string author, string title, int copies, int checkedOut) : author(author), title(title), copies(copies), checkedOut(checkedOut) {}
ostream & cs20a::operator<<(ostream & outs, const Book & book) { cout << book.title << ", by " << book.author << " Copies: " << book.copies << " Checked out: " << book.checkedOut; return outs; }
//*** Code goes here ***// //*** Code goes here ***// //*** Code goes here ***//
}
Librarydriver.cpp
#include
using namespace std; using namespace cs20a;
int main() { Library library;
try { cout << "--> Before Initial State." << endl;
library.addBook("Ernest Hemingway", "For Whom the Bell Tolls"); library.addBook("Ernest Hemingway", "For Whom the Bell Tolls"); library.addBook("John Steinbeck", "The Grapes of Wrath"); library.addBook("John Steinbeck", "The Grapes of Wrath"); library.addBook("John Steinbeck", "East of Eden"); library.addBook("Mark Twain", "Huckleberry Finn");
cout << library; } catch (const std::exception& e) { cout << "*** " << e.what() << " ***" << endl; } cout << "--> After Initial State." << endl << endl;
try { cout << "--> Before deleting Main Street and For Whom the Bell Tolls." << endl;
if (library.hasBook("Sinclair Lewis", "Main Street")) library.deleteBook("Sinclair Lewis", "Main Street");
library.deleteBook("Ernest Hemingway", "For Whom the Bell Tolls"); library.deleteBook("Ernest Hemingway", "For Whom the Bell Tolls");
cout << library; } catch (const std::exception& e) { cout << "*** " << e.what() << " ***" << endl; } cout << "--> After deleting Main Street and For Whom the Bell Tolls." << endl << endl;
try { cout << "--> Before checking out For Whom the Bell Tolls and The Grapes of Wrath." << endl;
if (library.hasBook("Ernest Hemingway", "For Whom the Bell Tolls")) library.checkOutBook("Ernest Hemingway", "For Whom the Bell Tolls");
if (library.hasBook("John Steinbeck", "The Grapes of Wrath")) library.checkOutBook("John Steinbeck", "The Grapes of Wrath");
cout << library; } catch (const std::exception& e) { cout << "*** " << e.what() << " ***" << endl; } cout << "--> After checking out For Whom the Bell Tolls and The Grapes of Wrath." << endl << endl;
try { cout << "--> Before checking checking in For Whom the Bell Tolls." << endl;
library.checkInBook("Ernest Hemingway", "For Whom the Bell Tolls"); library.checkInBook("Ernest Hemingway", "For Whom the Bell Tolls");
cout << library; } catch (const std::exception& e) { cout << "*** " << e.what() << " ***" << endl; } cout << "--> After checking checking in For Whom the Bell Tolls." << endl << endl;
try { cout << "--> Before checking in The Grapes of Wrath." << endl;
library.checkInBook("John Steinbeck", "The Grapes of Wrath");
cout << library; } catch (const std::exception& e) { cout << "*** " << e.what() << " ***" << endl; } cout << "--> After checking in The Grapes of Wrath." << endl << endl;
try { cout << "--> Before checking in Huckleberry Finn." << endl;
library.checkInBook("Mark Twain", "Huckleberry Finn"); cout << endl;
cout << library; } catch (const std::exception& e) { cout << "*** " << e.what() << " ***" << endl; } cout << "--> After checking in Huckleberry Finn." << endl << endl;
system("pause"); return 0; }
Dynamicarray.h
#pragma once #include
{ const int INITIAL_CAPACITY = 2; const int GROWTH_FACTOR = 2; const double MINIMUM_SIZE_ALLOWED = 0.25;
template
~DynamicArray();
void add(const T& value); void removeAt(int index); void insert(int index, const T& value); bool remove(const T& value);
int indexOf(const T& value) const; bool contains(const T& value) const;
void clear();
int getSize() const; int getCapacity() const;
bool isEmpty() const;
DynamicArray
T& operator[](int index); const T& operator[](int index) const;
bool operator==(DynamicArray
private: int size, capacity; T *elements;
void deepCopy(const DynamicArray
template
template
template
template
template
for (int i = 0; i < size; i++) elements[i] = rhs.elements[i]; }
template
template
T item = value; elements[size++] = item; }
template
for (int i = index; i < (size - 1); i++) elements[i] = elements[i + 1];
size--;
if (isCapacityAdjustmentNeeded()) setCapacity(size + 1); }
template
if (i >= 0) { removeAt(i); return true; } else return false; }
template
if (isCapacityAdjustmentNeeded()) setCapacity(size + 1);
for (int i = size; i > index; i--) elements[i] = elements[i - 1];
elements[index] = value; size++; }
template
return -1; }
template
template
template
template
for (int i = 0; i < size; i++) if (rhs[i] != elements[i]) return false; }
return true; }
template
template
template
template
if (minCapacity >= 0) { int limit = 1; while (limit <= minCapacity) limit *= GROWTH_FACTOR;
T *tarray = new T[limit];
for (int i = 0; i < size; i++) tarray[i] = elements[i];
delete[] elements;
elements = tarray; capacity = limit; } }
template
return elements[index]; }
template
return elements[index]; }
template
size = 0; capacity = INITIAL_CAPACITY; elements = new T[capacity]; }
template
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started