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

Please help me Exercises #5 5.This exercise and the next few require you to desi

ID: 3773615 • Letter: P

Question

Please help me Exercises #5

5.This exercise and the next few require you to design and implement a Book class, such as you can imagine as part of software for a library. Class Book should have members for the ISBN, title, author, and copyright date. Also store data on wheter or not the book is checked out. Create functions for returning those data values. Create functions for checking a book in and out. Do simple validation of data entered into a Book; for example, accept ISBNs only of the form n-n-n-x where n is an integer and x is a digit or a letter. Store an ISBN as a string. Add operators for the Book class. Have the ==operator check whether the ISBN numbers are the samefor two books. Have != also compare the ISBN numbers. Have a <<print out the title, author, and ISBN on separate lines. Create an enumerated type for the Book class called Genre. Have the types the fiction, nonfiction, periodical, biography, and children. Give each book a Genre and make appropriate changes to the Book constructor and member functions. Create a Patron class for the library. The class will have a user's name, library card number, and library fees.(if owed). Have functions that access this data, as well as a function to set the fee of the user. Have a helper function that returns a Bookean (bool) depending on whether or not the user owes a fee. Creat a Library class. Include Vectors of Books and Patrons. Include a struct called Transaction. Have it include a Book, a Patron. and a Date from the chapter. Make a vector of Transcactions. Create functions to add books to the library, add patrons to the library, and check out books. Whenever a user checks out a book, have the library make sure that both the user and the book are in the library. If they aren't, report an error. Then check to make sure that the user owes no fees. If the user does, report an error. If not, create a Transaction, and place it in the vector of report an error. If not, creat a Transaction, and place it in the vector of Transactions. Also write a function that will return a vector that contains the names of all Patrons who owe fees.

Explanation / Answer

#include <iostream>
class Book
{
   string ISBN;
   string title;
   string author;
   string copyright_date;
   /* store data on wheter or not the book is checked out.*/
   bool checked_out;
   /*genere*/
   enum Genere {fiction, nonfiction, periodical, biography,children};
   Genere genere;
   public:
       Book(string isbn,string t,string a,string date, Genere g, bool status)
       {
           ISBN=isbn;
           title=t;
           author=a;
           copyright_date=date;
           genere=g;
           checked_out=status;
       }
       Genere getGenere()
       {
           return genere;
       }
       string getISBN()
       {
           return ISBN;
       }
       string getTitle()
       {
           return title;
       }
       string getAuthor()
       {
           return author;
       }
       string getCopyright_Date()
       {
           return copyright_date;
       }
       bool getStatus()
       {
           return checked_out;
       }
       void setStatus(bool stat)
       {
           checked_out=stat;
       }
       void checkStatus()
       {
           if(checked_out==true)
               cout<<endl<<"Book is checked out";
           else
               cout<<endl<<"Book is on-shelf";
       }
       /*overloading <<, to print out the title, author, and ISBN on separate lines. */
       ostream& operator<<(ostream& out, const Book& bk)
       {
   out <<endl<<"Title: "<<bk.title<<endl<<"Author: "<<bk.author<<endl<<"ISBN: "<<bk.ISBN;
       return out;
       }
       bool operator!=(string isbn )
{
bool equal=true;
  
return status;
}
       bool operator==(const Book &B )
{
bool status=true;
if(ISBN!=B.ISBN)
    status=false;
return status;
}
};
/*Create a Patron class for the library. The class will have a user's name, library card number, and library fees.(if owed)*/
class Patron
{
   string user_name;
   int library_card;
   double fees;  
   public:
       Patron(string name,int card)
       {
           user_name=name;
           library_card=card;
           fees=0;
       }
       string getUserName()
       {
           return user_name;
       }
       int getCardNumber()
       {
           return library_card;
       }
       /*function to set the fees*/
       double getFees()
       {
           return fees;
       }
       /*helper function that returns a Boolean (bool) depending on whether or not the user owes a fee.*/
      
       void setFees(double amt)
       {
           fees=amt;
       }
};
/* Include a struct called Transaction. Have it include a Book, a Patron. and a Date from the chapter.*/
struct Transaction
{
   Book book;
   Patron patron;
   string Date; // from chapter
};

// library class
class Library
{
   /*Include Vectors of Books and Patrons*/
   Book books[10];
   Patron patrons[10];
   /*Make a vector of Transcactions.*/
   Transaction transactions[10];
   public:
       static int numOfBooks;
       static int numOfPatrons;
       static int numOfTransactions;
       void returnBook(Book b)
       {
           b.setStatus(false);
       }
       void CheckedOut(Book b, string user,string date)
       {
           int flag=0;
           for(int i=0;i<numOfBooks;i++)
           {
               if(b.getTitle()==books[i].getTitle())
               {
                   flag=1;
                   break;
               }
           }
           if(flag==1)
           {
               int flag2=0;
               for(int j=0;i<numOfPatrons;i++)
               {
               if(user==patrons[i].getUserName()
               {
                   flag2=1;
                   break;
               }
               }
               if(flag2==1)
               {
                   b.setStatus(true);
           addTransaction(b.getTitle(), user, date);
               }
          
           }
          
       }
       void addBook(string isbn,string t,string a,string date, Genere g, bool status)
       {
           Book b(isbn,t,a,date,g,status);
           books[++numOfBooks]=b;
       }
       void addPatron(string name,int card)
       {
           Patron p(name,card);
           patrons[++numOfPatrons]=p;
       }
       void addTransaction(string bookname, string username, string date)
       {
           struct Transaction t;
           t.book=bookname;
           t.patron=username;
           t.Date=date;
           transactions[++numOfTransactions]=t;
       }
      
       string[] getPatronsToPayfees()
       {
           string p[10];
           int k=0;
           for(int i=0;i<numOfPatrons;i++)
           {
               if(patrons[i].getFees()>0)
               p[k++]=patrons[i].getUserName();
           }
           return p;
       }
      
};

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