robbydooby

card.h

Dec 3rd, 2016
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.25 KB | None | 0 0
  1. // File: card.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 CARD_H
  15. #define CARD_H
  16.  
  17. #include <iostream>
  18. #include <string>
  19. using namespace std;
  20.  
  21. class Card
  22. {
  23. public:
  24.    
  25.     // Constructors
  26.     Card();
  27.     Card(string name, string phone, int holderID);
  28.    
  29.     void changeBook(int bookID);    // Assign current book
  30.     void resetHold();               // Reset hold status
  31.     void getInfo();                 // Print card information
  32.     string getName();               // Return name
  33.     string getPhone();              // Return phone
  34.     int getID();                    // Return holderID
  35.     int getBook();                  // Return bookID
  36.     bool getStatus();               // Check if card has a book checked out
  37.     bool checkInit();               // Check if card is properly initialized
  38.  
  39.    
  40. private:
  41.     string name;
  42.     string phone;
  43.     int holderID;
  44.     int bookID;
  45. };
  46.  
  47. Card::Card()
  48. {
  49.     bookID = -1; // Sentinel value to indicate improper initialization
  50. }
  51.  
  52. Card::Card(string name, string phone, int holderID)
  53. {
  54.     this->name = name;
  55.     this->phone = phone;
  56.     this->holderID = holderID;
  57.     bookID = 0;
  58. }
  59.  
  60. void Card::changeBook(int bookID)
  61. {
  62.     this->bookID = bookID;
  63. }
  64.  
  65. void Card::resetHold()
  66. {
  67.     bookID = 0;
  68. }
  69.  
  70. void Card::getInfo()
  71. {
  72.     cout.width(8); cout << "Name: " << name << endl;
  73.     cout.width(8); cout << "Phone: " << phone << endl;
  74.     cout.width(8); cout << "ID: " << holderID << endl;
  75. }
  76.  
  77. string Card::getName()
  78. {
  79.     return name;
  80. }
  81.  
  82. string Card::getPhone()
  83. {
  84.     return phone;
  85. }
  86.  
  87. int Card::getID()
  88. {
  89.     return holderID;
  90. }
  91.  
  92. int Card::getBook()
  93. {
  94.     return bookID;
  95. }
  96.  
  97. bool Card::getStatus()
  98. {
  99.     if (bookID == 0) return 0;
  100.     else return 1;
  101. }
  102.  
  103. bool Card::checkInit()
  104. {
  105.    
  106.     if(bookID == -1) return 0;
  107.     else return 1;
  108. }
  109. #endif
Add Comment
Please, Sign In to add comment