-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlibrary.cpp
More file actions
160 lines (154 loc) · 4.24 KB
/
library.cpp
File metadata and controls
160 lines (154 loc) · 4.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#include <string>
#include <deque>
#include <iostream>
using namespace std;
class Book
{
private:
string BookName;
int Book_ID;
string Book_Author;
public:
Book(string book_name, string book_author, int book_id)
{
BookName = book_name;
Book_Author = book_author;
Book_ID = book_id;
}
string getBookName() { return BookName; }
int getBook_ID() { return Book_ID; }
string getBook_Author() { return Book_Author; }
};
class patron
{
private:
string patronName;
int patron_SSN;
deque<Book> BorrowedBooks;
public:
patron(string patron_name, int patron_ssn)
{
patronName = patron_name;
patron_SSN = patron_ssn;
}
string getPatronName()
{
return patronName;
}
int getPatronSSN()
{
return patron_SSN;
}
void borrowBook(Book Wantedbook)
{
BorrowedBooks.push_back(Wantedbook);
}
bool isBorrowedBook(int BorrowbookID)
{
for (Book is_borrowed_Book : BorrowedBooks)
{
if (is_borrowed_Book.getBook_ID() == BorrowbookID)
{
return true;
}
}
return false;
}
};
class library
{
deque<Book> Available_books;
bool Is_borrowed_Book = false;
public:
library()
{
Available_books.push_back(Book("Amarita", "Omar AbdELhamid", 123));
Available_books.push_back(Book("Harry Potter", "Joanne Rowling", 456));
Available_books.push_back(Book("Sherlock Holmes", "Arthur Conan", 789));
Available_books.push_back(Book("Hoker", "Nicola Haddad", 101));
}
void ViewAvailableBooks()
{
cout << "The Available books are :" << endl;
for (auto showAvilabelBook : Available_books)
{
cout << "Book ID : " << showAvilabelBook.getBook_ID() << " , Title : " << showAvilabelBook.getBookName() << " , Author : " << showAvilabelBook.getBook_Author() << endl;
}
}
} library_object;
int main()
{
cout << "HELLO !! " << endl;
library_object.ViewAvailableBooks();
patron patorn_data("Asil", 13305);
cout << "Is this your first time? (y , n)" << endl;
bool is_first_time = false;
char theAnswer;
cin >> theAnswer;
if (theAnswer == 'y')
{
is_first_time = true;
}
bool end_programe = false;
char answer_to_end_program;
while (!end_programe)
{
if (is_first_time)
{
string bookName, bookAuthor;
int bookID;
cout << "Enter Book Name: ";
cin.ignore();
getline(cin, bookName);
cout << "Enter Book Author: ";
getline(cin, bookAuthor);
cout << "Enter Book ID: ";
cin >> bookID;
Book wantedBook(bookName, bookAuthor, bookID);
patorn_data.borrowBook(wantedBook);
cout << "\nBook borrowed successfully." << endl;
cout << "Do you want to save changes ? (y , n)" << endl;
cin >> answer_to_end_program;
if (answer_to_end_program == 'y')
{
cout << "saved successfully";
end_programe = true;
}
}
if (is_first_time)
{
cout << "Enter the Book ID you want to check:\n ";
int wanted_book_ID;
cin >> wanted_book_ID;
if (patorn_data.isBorrowedBook(wanted_book_ID))
{
cout << "The book is borrowed now ." << endl;
}
else
{
cout << "The book is available." << endl;
}
cout << "Do you want to save changes ? (y , n)" << endl;
cin >> answer_to_end_program;
if (answer_to_end_program == 'y')
{
cout << "saved successfully";
end_programe = true;
}
}
else
{
cout << "Enter the Book ID you want to check:\n ";
int wanted_book_ID;
cin >> wanted_book_ID;
if (patorn_data.isBorrowedBook(wanted_book_ID))
{
cout << "The book is borrowed." << endl;
}
else
{
cout << "The book is available." << endl;
}
}
}
}