#include \"book.hpp\" using namespace std; Book::Book(){ idCode = \"default\"; t
ID: 666756 • Letter: #
Question
#include "book.hpp"
using namespace std;
Book::Book(){
idCode = "default";
title = "defalut";
author = "default";
location = ON_SHELF;
}
Book::Book(string idc, string t, string a){
idCode = idc;
title = t;
author = a;
location = ON_SHELF;
}
string Book::getIdCode(){
return idCode;
}
string Book::getTitle(){
return title;
}
string Book::getAuthor(){
return author;
}
Locale Book::getLocation(){
return location;
}
void Book::setLocation(Locale lo){
location = lo;
}
Patron* Book::getCheckedOutBy(){
return checkedOutBy;
}
void Book::setCheckedOutBy(Patron* p){
checkedOutBy = p;
}
Patron* Book::getRequestedBy(){
return requestedBy;
}
void Book::setRequestedBy(Patron* p){
requestedBy = p;
}
int Book::getDateCheckedOut(){
return dateCheckedOut;
}
void Book::setDateCheckedOut(int d){
dateCheckedOut = d;
}
#include "patron.hpp"
#include <iostream>
using namespace std;
Patron::Patron(){
idNum = "0";
name = "default";
}
Patron::Patron(std::string idn, std::string n){
idNum = idn;
name = n;
}
string Patron::getIdNum(){
return idNum;
}
string Patron::getName(){
return name;
}
vector<Book *> Patron::getCheckedOutBooks(){
return checkedOutBooks;
}
void Patron::addBook(Book* b){
checkedOutBooks.push_back(b);
}
void Patron::removeBook(Book* b){
for(int i = 0; i < checkedOutBooks.size(); ++i){
if(checkedOutBooks[i] == b){
checkedOutBooks.erase(checkedOutBooks.begin() + i);
break;
}
}
}
double Patron::getFineAmount(){
return fineAmount;
}
void Patron::amendFine(double amount){
fineAmount += amount;
}
Library:
holdings - a vector of pointers to Books in the Library
members - a vector of pointers to Patrons in the Library
currentDate - stores the current date represented as an integer number of "days" since the Library object was created
a constructor that initializes the currentDate to zero
addBook - adds the parameter to holdings
addPatron - adds the parameter to members
getBook - returns a pointer to the Book corresponding to the ID parameter, or NULL if no such Book is in the holdings
getPatron - returns a pointer to the Patron corresponding to the ID parameter, or NULL if no such Patron is a member
checkOutBook
if the specified Book is not in the Library, return "book not found"
if the specified Patron is not in the Library, return "patron not found"
if the specified Book is already checked out, return "book already checked out"
if the specified Book is on hold by another Patron, return "book on hold by other patron"
otherwise update the Book's checkedOutBy, dateCheckedOut and Location; if the Book was on hold for this Patron, update requestedBy; update the Patron's checkedOutBooks; return "check out successful"
returnBook
if the specified Book is not in the Library, return "book not found"
if the Book is not checked out, return "book already in library"
update the Patron's checkedOutBooks; update the Book's location depending on whether another Patron has requested it; update the Book's checkedOutBy; return "return successful"
requestBook
if the specified Book is not in the Library, return "book not found"
if the specified Patron is not in the Library, return "patron not found"
if the specified Book is already requested by another Patron, return "book on hold by other patron"
update the Book's requestedBy; if the Book is on the shelf, update its location to on hold; return "request successful"
payFine
takes as a parameter the amount that is being paid (not the negative of that amount)
if the specified Patron is not in the Library, return "patron not found"
use amendFine to update the Patron's fine; return "payment successful"
incrementCurrentDate
increment current date; increase each Patron's fines by 10 cents for each overdue Book they have checked out (using amendFine)
If a book is checked out on day 0, then on day 1, the patron has had it for 1 day. On day 21, the patron has had it for 21 days, so it is still not overdue. On day 22, the book is overdue and fines will be charged.
be careful - a Book can be on request without its location being the hold shelf (if another Patron has it checked out);
You will be writing a Library simulator. It will have ultimately have three classes, but here we are only working on ONE, the class Library. I am supplying you with the .hpp file. The end result will be two files, the INCLUDED Library.hpp file and a
This code doesn't complete and doesn't work
#include
#include
#include
#include
#include
#include
class library
{
char bno[6];
char bname[50];
char aname[20];
char holdings[50];
char admno[6];
char name[20];
char stbno[6];
public:
library()
{
currentDate=0;
}
void add_book()
{
cout<<" NEW BOOK ENTRY... ";
cout<<" Enter The book no.";
cin>>bno;
holdings[1]=bno;
cout<<" Enter The Name of The Book ";
gets(bname);
cout<<" Enter The Author's Name ";
gets(aname);
cout<<" Book Created..";
}
void add_member()
{
clrscr();
cout<<" NEW STUDENT ENTRY... ";
cout<<" Enter The admission no. ";
cin>>admno;
cout<<" Enter The Name of The Student ";
gets(name);
token=0;
stbno[0]='/0';
cout<<" Student Record Created..";
}
void show_book()
{
cout<<" Book no. : "< for(i=0;i<50;i++)
{
if(holdings[i]==bno)
{
cout<<" Book Name : ";
puts(bname);
cout<<"Author Name : ";
puts(aname);
}
else
cout<<"book is not present";
return;
}
void update_book()
{
char n[6];
int found=0;
clrscr();
cout<<" MODIFY BOOK REOCORD.... ";
cout<<" Enter The book no. of The book";
cin>>n;
fp.open("book.dat",ios::in|ios::out);
while(fp.read((char*)&bk,sizeof(book)) && found==0)
{
if(strcmpi(bk.retbno(),n)==0)
{
bk.show_book();
cout<<" Enter The New Details of book"< bk.modify_book();
int pos=-1*sizeof(bk);
fp.seekp(pos,ios::cur);
fp.write((char*)&bk,sizeof(book));
cout<<" Record Updated";
found=1;
}
}
fp.close();
if(found==0)
cout<<" Record Not Found ";
getch();
}
char* retbno()
{
return bno;
}
void report()
{cout<
}
Explanation / Answer
your all other classes are also wrong; though i am writting Library.cpp function as it is asked here but before running that.
#include <bits/stdc++.h>
#include <Library.h>
// Add Book function
void Library::addBook(Book* b){
holdings.push_back(b);
}
// Add Patron function
void Library::addPatron(Patron* p){
members.push_back(p);
}
std::string Library::checkOutBook(std::string pID, std::string bID){
Book* b = getBook(bID);
if (b == NULL)
return "book not found";
Patron* p = getPatron(pID);
if (p == NULL)
return "patron not found";
Patron* p1 = b->getCheckedOutBy();
if (p1 != NULL)
return "book already checked out";
Patron* p2 = b->getRequestedBy();
if (p2 != NULL)
return "book on hold by other patron";
b->setDateChecked(currentDate);
b->setLocation(WITH_SOMEONE);
b->setCheckedOutBy(p);
p->addBook(b);
return "check out successful";
}
std::string Library::returnBook(std::string bID){
Book* b = getBook(bID);
if (b == NULL)
return "book not found";
Patron* p = b->getCheckedOutBy();
if (p == NULL)
return "book already in library";
p->removeBook(b);
Patron* p1 = b->getRequestedBy();
if (p1 == NULL)
b->location = ON_SHELF;
else{
b->setDateChecked(currentDate);
b->setLocation(WITH_SOMEONE);
b->setCheckedOutBy(p1);
p1->addBook(b);
}
return "return successful";
}
std::string Libraray::requestBook(std::string pID, std::string bID){
Book* b = getBook(bID);
if (b == NULL)
return "book not found";
Patron* p = getPatron(pID);
if (p == NULL)
return "patron not found";
Patron* p1 = b->getRequestedBy();
if (p1 != NULL)
return "book on hold by other patron";
b->setRequestedBy(p1);
b->setLocation(ON_HOLD);
return "request successful";
}
std::string Library::payFine(std::string pID, double payment){
Patron* p = getPatron(pID);
if (p == NULL)
return "patron not found";
if (payment < 0)
return "Fine should be positive";
p->amendFine(payment);
return "payment successful";
}
void Library::incrementCurrentDate(){
currentDate++;
}
Patron* Library::getPatron(std::string pID){
for (int i = 0; i < members.size(); i++){
Patron* p = members[i];
if (p->getIdNum() == pID) return p;
}
return NULL;
}
Book* Library::getBook(std::string bID){
for (int i = 0; i < holdings.size(); i++){
Book* b = holdings[i];
if (b->getIdCode() == bID) return b;
}
return NULL;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.