-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinput_action.cpp
248 lines (242 loc) · 8.9 KB
/
input_action.cpp
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
int verify_user(STUDENT_TREE* root,int id,char* password)
{
if(root==NULL)
{
return 0;
}
if(root->s_key->stu_id==id)
{
if(strcmp(root->s_key->stu_adm_num,password)==0)
{
return 1;
}
return 0;
}
if(root->s_key->stu_id>id)
return verify_user(root->left,id,password);
return verify_user(root->right,id,password);
}
int verify_emp(EMPLOYEE* root,int id,char* password)
{
if(root==NULL)
{
return 0;
}
if(root->emp_id==id)
{
if(strcmp(root->emp_password,password)==0)
return 1;
return 0;
}
return verify_emp(root->next,id,password);
}
char sname[NAME_LEN];
void login_display()
{
int user_action;
int user;
login:
cout<<"*******LOGIN*********\n";
cout<<"user_id"<<endl;
cin>>userID;
cout<<"password(Adm_Number)"<<endl;
cin>>password;
cout<<"enter 1.Student and 2.Library Employee"<<endl;
cin>>user;
switch(user)
{
case 1:
status_user=verify_user(student_root,userID,password);
if(status_user==0)
{
cout<<"Invalid username or Password\n";
goto login;
}
while(true)
{
cout<<"*********STUDENT FUNCTIONS**********"<<endl;
cout<<"* CHOOSE NUMBER ACCORDINGLY *"<<endl;
cout<<"* 1.search books by book_id *"<<endl;
cout<<"* 2.search books by book_name *"<<endl;
cout<<"* 3.search books by author_name *"<<endl;
cout<<"* 4.view all the books available *"<<endl;
cout<<"* 5.books issued by the student *"<<endl;
cout<<"* 6.Calculate Fine *"<<endl;
cout<<"* 7.Exit *"<<endl;
cout<<"************************************"<<endl;
cin>>user_action;
switch(user_action)
{
case 1:
int bid;
cout<<"Book id\n";
cin>>bid;
search_book_by_book_id(books_root_node,bid);
break;
case 2:
char book_name[70];
cout<<"Enter book name(spelling and spaces should be proper)\n";
fflush(stdin);
scanf("%[^\n]s",book_name);
if(search_book_by_bname(books_root_node,book_name)==0)
cout<<"No books with this name are available\n";
break;
case 3:
char a_name[NAME_LEN];
cout<<"Enter author name(spelling and spaces should be proper)\n";
fflush(stdin);
scanf("%[^\n]s",a_name);
if(search_book_by_aname(books_root_node,a_name)==0)
cout<<"No book by the given author name are available\n";
break;
case 4:
show_books(books_root_node);
break;
case 5:
int id;
cout<<"student id"<<endl;
cin>>id;
show_issued_books(issue_root,id);
break;
case 6:
int sids;
int bids;
cout<<"student id"<<endl;
cin>>sids;
cout<<"book id\n";
cin>>bids;
calculate_fine(issue_root,sids,bids);
break;
case 7:
exit(1);
break;
default:
cout<<"choose appropriate Number\n";
break;
}
}
break;
case 2:
status_emp=verify_emp(emp_root,userID,password);
if(status_emp==0)
{
cout<<"Invalid username or Password\n";
goto login;
}
while(true)
{
cout<<"*********LIBRARIAN FUNCTIONS********"<<endl;
cout<<"* CHOOSE NUMBER ACCORDINGLY *"<<endl;
cout<<"* 1.Add new students *"<<endl;
cout<<"* 2.Add new books *"<<endl;
cout<<"* 3.Issue the book *"<<endl;
cout<<"* 4.Return the book *"<<endl;
cout<<"* 5.Renew the book *"<<endl;
cout<<"* 6.Delete student record *"<<endl;
cout<<"* 7.Show Students(Users) *"<<endl;
cout<<"* 8.Exit *"<<endl;
cout<<"************************************"<<endl;
cin>>user_action;
switch(user_action)
{
case 1:
char adm[8];
int id;
cout<<"Enter Student Details"<<endl;
cout<<"Student name"<<endl;
fflush(stdin);
scanf("%[^\n]s",sname);
cout<<"Student id"<<endl;
cin>>id;
cout<<"Admission Number"<<endl;
fflush(stdin);
scanf("%[^\n]s",adm);
student_root=add_user(sname,id,adm);
if(stu_dup_flag==0)
cout<<"User Added Successfully"<<endl;
break;
case 2:
int book_id;
char book_name[BOOK_NAME_LEN];
char author_name[NAME_LEN];
int rack;
int quantity;
cout<<"BOOK DETAILS"<<endl;
cout<<"book id\n";
cin>>book_id;
cout<<"Book name\n";
fflush(stdin);
scanf("%[^\n]s",book_name);
cout<<"author name\n";
fflush(stdin);
scanf("%[^\n]s",author_name);
cout<<"rack Number\n";
cin>>rack;
cout<<"quantity"<<endl;
cin>>quantity;
books_root_node=insert_new_book(book_id,book_name,author_name,rack,quantity);
if(book_dup_flag==0)
cout<<"New book added successfully"<<endl;
break;
case 3:
int id_book;
char name_of_book[BOOK_NAME_LEN];
int id_stu;
char pw[10];
cout<<"enter student id"<<endl;
cin>>id_stu;
cout<<"Enter book id"<<endl;
cin>>id_book;
cout<<"Book name"<<endl;
fflush(stdin);
scanf("%[^\n]s",name_of_book);
cout<<"Password of student"<<endl;
fflush(stdin);
scanf("%[^\n]s",pw);
issue_book(id_book,name_of_book,id_stu,pw);
break;
case 4:
int book_id_;
int stu_id;
cout<<"Enter id of book you want to return \n";
cin>>book_id_;
cout<<"Enter student id\n";
cin>>stu_id;
return_book(issue_root,book_id_,stu_id);
break;
case 5:
int book_ids;
int student_id;
cout<<"Enter id of book you want to renew\n";
cin>>book_ids;
cout<<"Enter student id\n";
cin>>student_id;
renew_book(issue_root,book_ids,student_id);
break;
case 6:
int stud_id;
char password[9];
cout<<"student id\n";
cin>>stud_id;
cout<<"Password\n";
fflush(stdin);
scanf("%[^\n]s",password);
student_root=delete_student_rec(student_root,stud_id,password);
break;
case 7:
show_students(student_root);
break;
case 8:
exit(1);
break;
default:
cout<<"choose appropriate Number\n";
break;
}
}
break;
default:
cout<<"Choose the action appropriately\n";
break;
}
}