Advertisement
robbydooby

book.h

Dec 3rd, 2016
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.53 KB | None | 0 0
  1. // File: book.h
  2.  
  3. // Programmer: Robert Doobay
  4.  
  5. // Class: COP 2931
  6.  
  7. // Description: This program simulates the checking out and checking in of books
  8. // from a library.  Book data and library card data is read in from books.txt
  9. // and cards.txt and stored in separate arrays of their respective object types.
  10. // When the program user is finished making changes to the database, the
  11. // existing text files are deleted and new ones are created to reflect all
  12. // changes made.
  13.  
  14. #ifndef BOOK_H
  15. #define BOOK_H
  16.  
  17. #include <iostream>
  18. #include <iomanip>
  19. #include <string>
  20. using namespace std;
  21.  
  22. class Book
  23. {
  24. public:
  25.    
  26.     // Constructors
  27.    
  28.     Book();
  29.     Book(string title, string author, int bookID);
  30.  
  31.     void changeHold(int holderID);  // Assign current holder
  32.     void resetHold();               // Reset hold status
  33.     void getInfo();                 // Print book information
  34.     string getTitle();              // Return title
  35.     string getAuthor();             // Return author
  36.     int whoHas();                   // Return holderID
  37.     int getID();                    // Return bookID
  38.     bool getStatus();               // Check if book is available for checkout
  39.     bool checkInit();               // Check if book is properly initialized
  40.    
  41.    
  42. private:
  43.     string title;
  44.     string author;
  45.     int bookID;
  46.     int holderID;
  47.     bool Checked;
  48. };
  49.  
  50. Book::Book()
  51. {
  52.     holderID = -1; // Sentinel value to indicate improper initialization
  53. }
  54.  
  55. Book::Book(string title, string author, int bookID)
  56. {
  57.     this->title = title;
  58.     this->author = author;
  59.     this->bookID = bookID;
  60.     holderID = 0;
  61.     Checked = false;
  62.  
  63. }
  64.  
  65. void Book::changeHold(int holderID)
  66. {
  67.     this->holderID = holderID;
  68.     Checked = true;
  69. }
  70.  
  71. void Book::resetHold()
  72. {
  73.     holderID = 0;
  74.     Checked = false;
  75. }
  76.  
  77. void Book::getInfo()
  78. {
  79.     cout.width(8); cout << "Title: " << title << endl;
  80.     cout.width(8); cout << "Author: " << author << endl;
  81.     cout.width(8); cout << "ID: " << bookID << endl;
  82.     cout.width(8); cout << "Status: ";
  83.     if (holderID == 0)
  84.     {
  85.         cout << "AVAILABLE" << endl;
  86.     }
  87.    
  88.     else
  89.     {
  90.         cout << "CHECKED OUT" << endl;
  91.     }
  92. }
  93.  
  94. string Book::getTitle()
  95. {
  96.     return title;
  97. }
  98.  
  99. string Book::getAuthor()
  100. {
  101.     return author;
  102. }
  103.  
  104. int Book::whoHas()
  105. {
  106.     return holderID;
  107. }
  108.  
  109. int Book::getID()
  110. {
  111.     return bookID;
  112. }
  113.  
  114. bool Book::getStatus()
  115. {
  116.     return Checked;
  117. }
  118.  
  119. bool Book::checkInit()
  120. {
  121.     if(holderID == -1) return 0;
  122.     else return 1;
  123. }
  124. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement