Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a portion of a class called Library. To be called Library.cpp and will inc

ID: 644614 • Letter: W

Question

Write a portion of a class called Library. To be called Library.cpp and will include (#include "Library.hpp") Library.hpp which is included below.

Library:
*returnBook
-
if the specified Book is not in the Library, print out that message and return to the menu
   -
if the Book is not checked out, print out that message and return to the menu
   -
update the Patron's list; update the Book's location depending on whether another Patron has requested it; update the Book's checkedOutBy; print out that Book title has been returned

Here is the Library.hpp file:

Explanation / Answer

Program:

#include<iostream>

#include<vector>

#include<fstream>

#include "Library.h"

#include "sqlite3.h"

void Library::ManageCheckout()

{

control = 1;

while(control != 4)

{

cout << endl << "What would you like to do?" << endl;

cout << "1 - Show checkouts" << endl;

cout << "2 - Check-out material" << endl;

cout << "3 - Check-in material" << endl;

cout << "4 - Return to main menu" << endl;

cout << "-->";

cin >> control;

while(control < 1 || control > 4)

{

cout << "Incorrect input, try again" << endl << "-->";

cin >> control;

}

switch(control)

{

case 1:

PrintCheckouts();

break;

case 2:

checkOut();

break;

case 3:

checkIn();

break;

case 4:

break;

}

}

}

void Library::PrintCheckouts()

{

//Typical select statement layout, it can all go in one line if you want

cout << sqlite3_exec(db, //<-- created in Library.cpp after libraries are included, links the program to the database

"select * from Checkout;", //<-- Select statement goes here

NULL, //Always put these next three arguments in when issuing an SQL command

0,

NULL);

}

/*void Library::BookCheckout()

{*/

//Prompt user for data

bool checkOut( const std::vector<ManagePatrons>& vecPatrons, const std::vector<ManageMaterials>& vecMaterials, std::vector<checkOut>& vecChecked ){

Patron patronOut;

Material materialOut;

bool success = false;

std::string strDate = "";

// Get the patron.

patronOut = selectPatron( vecPatrons );

// Get the material.

materialOut = selectMaterial( vecMaterials );

// Get the due date.

do{const std::vector<Patron>& vecPatrons, const std::vector<Material>& vecMaterials, std::vector<CheckedOut>& vecChecked

std::cout << "Enter the due date (mm/dd/yyyy): ";

cin >> strDate;

if( strDate.length() < 10 ){

// Alert user.

std::cout << "Error! Invalid date format." << endl;

} else {

success = true;

}

} while( !success );

// Add this item to the list of checked out items.

vecChecked.push_back( CheckedOut( patronOut.getID(), materialOut.getTitle(), strDate ) );

return success;

//Enter data into Header file

//Insert data into database

}

/*void Library::BookCheckin()

{*/

//Ask what book was checked out

bool checkIn( const std::vector<Patron>& vecPatrons, std::vector<CheckedOut>& vecChecked ){
bool success = false;

// Function variables...

static const int LIST_SIZE = 10;

int offset = 0;

int selection = -1;

char cSelect = ' ';

bool valid = false;

bool found = false;

do{

std::cout << "Make a selection from the menu below: " << endl << endl;

// Print the specified number of entries.

for( int menuCnt = 0; menuCnt < LIST_SIZE && menuCnt+offset < vecChecked.size(); ++menuCnt ){

// Print out each line selection option.

cout << menuCnt+1 << ". ";

// Find and print the patron's name.

for(std::vector<Patron>::const_iterator iter_patron = vecPatrons.begin(); iter_patron < vecPatrons.end() && !found ; ++iter_patron ){

found = (iter_patron->getID() == vecChecked[offset+menuCnt].getPatronID() );

if( found ){

cout << iter_patron->getName().toStr();

}

}

std::cout << " " << vecChecked[offset+menuCnt].getMaterial() << " " << vecChecked[offset+menuCnt].getDueDate() << endl;

}

if( offset > 0 ){

std::cout << " p for previous page";

}

if( offset < (int) vecChecked.size() - LIST_SIZE ){

std::cout << " n for next page";

}

std::cout << endl << endl << "Enter selection: ";

cin.ignore(1); // Ignore previous return stroke.

cin >> cSelect;

switch( cSelect ){

case 'p':

case 'P':

if( offset > 0 ){

offset -= LIST_SIZE;

}

break;

case 'n':

case 'N':

if( offset < (int) vecPatrons.size() - LIST_SIZE ){

offset += LIST_SIZE;

}

break;

default:

selection = (int) cSelect - 49;

if( selection < 0 || selection > 9 ){

// Alert user.

std::cout << "Error! Invalid selection attempted." << endl << endl;

} else {

// Set flag for a valid entry.

selection += offset;

valid = true;

}

}

}while( !valid );

// Remove the selected checked material from the vector.

vecChecked.erase( vecChecked.begin() + selection );

return success;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote