Question: ******************************[//this is library.h ] #pragma once #include using namespace std; static const int Max = 100; using namespace std; //Library can store books as well
******************************[//this is library.h ]
#pragma once #include
//Library can store books as well as add, remove, and list availible books
class Library { //list all books in file friend ostream& operator
public: //construct with given name explicit Library(const string& name);
virtual ~Library();
//add book bool addBook(const string& book);
//remove a book bool removeBook(const string& book);
//list availible books void listAllBooks() const;
//list books in random order until count number book is outputted void listRandomBooks(unsigned int count) const;
//It is True if book is found in the Library bool isInLibrary(const string& book)const;
public: int randNumList = 0; int numberOfBooks = 0; int bookRandom{MAX]; string bookList[MAX]; string takeListName;
}
***********************************[This is library.cpp]
#include "library.h" #include
Library::Library(const string& name) { Library:takeListName = name; numberOfBooks = 0; }
Library::~Library() {
}
bool Library::isInLibrary(const string& book) const {
for (int i = 0; i
}
bool Library::addBook(const string& book) {
if (isInLibrary(book) == false) { bookList[numberOfBooks] = book; numberOfBooks = numberOfBooks + 1; return true; } else { return false; } }
bool Library::removeBook(const string& book) {
for (int i = 0; i
} return false; }
void Library::listAllBooks() const { for (int i = 0; i
ostream& operator
*************************************[This is main.cpp]
#include "library.h" #include
using namespace std;
void test1() { Library library("The Books"); library.addBook("The Hunger Games"); library.addBook("Divergent"); library.addBook("Twilight"); library.addBook("The Faults In Our Stars"); library.addBook("The Hate You Give"); library.addBook("After"); library.addBook("Lord of the Rings"); library.addBook("Thirteen Reasons Why"); library.addBook("Catching Fire"); library.addBook("The Hobbit"); library.addBook("Fifty Shades of Grey");
cout
cout
cout
cout
bool result = library.isInLibrary("Divergent"); assert(!result);
//can not add it twice, so results will be false result = library.addBook("Divergent"); assert(!result);
//test remove, so it should be true result = library.removeBook("Divergent"); assert(!result);
/ot in the library so result is false result = library.isInLibrary("Divergent"); assert(!result);
//can not remove book twice, result is false result = library.removeBook("Divergent"); assert(!result);
cout
void testAll() { cout
}
int main() { testAll(); return 0; }
So for some reason i cant figure out why some of the code is in error in visual studio.
CPP Explores Toolbox arry hvery. ConsoleApplication 1 hrey" Garba de coure cet Invalid tats) Library rarythe B) Bhary (the grand (ver) Library (1) (The Palts in Our Star) 2brary obile Mate You G.) 15 brary. After brary.ad("Lord of the R) 2hvery.admiram Rains i Wbrary.add(Catch Fire") brary. (The Wit) Ibrary.dk (Fifty Shades of Grey) cout Library Server Explores Toolbox Consolaapplication1.cpp ConsoleApplication pandorry. include catre cine Burry rary contestan) Library Larry rary) Library Library and string book) cont for (i numbers) 17 (4) return Er return false; al Library:ookconst string book) I (LTLibrary() false) Lumbers) - Number of shares 13 ala return falses hool Library Tract string book) ( for ( 11 herroks; 4) { If helst) book) Booklist) - Rekisterros. 3): Numbers Ruberoflooks - 11 return true return false 51 53 svold Library Stones() const { for (int 101 Ciserslan In
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
