Advertisement
Guest User

book.h

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