-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathLibraryManagementSystem.c
214 lines (194 loc) · 8.1 KB
/
LibraryManagementSystem.c
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
#include <stdio.h>
#include <stdlib.h>
int main()
{
struct reader{ //Define structure reader
int id; //id stores reader id
char name[20]; //name stores reader's name
char due; //due stores y/n for if any book is due by particular leader
int dbid; //dbid stores due book's id
} rdr[10]={0}; //rdr array is initialised with structure of reader
struct book{ //structure book defined
int id; //id here stores book id
char name[30]; //name stores name of the book
char author[20]; //author stores name of the author
char avbl; //avbl stores availability of the book as y/n
int rid; //rid stores reader id having the book
} bk[20]={0}; //bk array is initialised with structure of book
int choice, searchid, searchid1, n, m; //some integer variables are declared to be used for performing different functions in program
printf("\n\t\tWELCOME!\n"); //Welcome message
do{ //do-while loop is used to return to main menu after every case is over.i.e.task is done
printf("\n\tLibrary Management System\n\t=========================\n1. Add new book\t\t2. Search book\n3. Add new reader\t4. Search reader\n5. Issue book\t\t6. Submit book\n7. Delete book\t\t8. Delete reader\n9. List of books\t10. Exit\n\nEnter your choice: ");
scanf("%d", &choice);
switch(choice){
case 1: //Add a book
for(int i=0; i<20; i++){
if (bk[i].id==0){ //to find empty space in bk array
printf("Enter name of the book: ");
scanf("%s", bk[i].name);
printf("Enter name of the author: ");
scanf("%s", bk[i].author);
printf("Enter book ID: ");
scanf("%d", &bk[i].id);
bk[i].avbl='y'; //set availability to y
bk[i].rid=0; //set readers id to 0 as default
i=20; //to exit from for loop
printf("Book added successfully.\n\n");
}
}
break;
case 2:
printf("Enter book ID: ");
scanf("%d", &searchid);
n=0;
for(int i=0; i<20; i++){
if (searchid == bk[i].id){
printf("\n\tBook Information\nBook ID: %d\tBook Name: %s\nAuthor Name: %s\nAvailable: %c\tDue by Reader ID: %d\n", bk[i].id, bk[i].name, bk[i].author, bk[i].avbl, bk[i].rid);
n++;
}
}
if(n==0){
printf("Book not found.\n\n");
}
break;
case 3:
for(int i=0; i<10; i++){
if (rdr[i].id==0){ // to search empty space in rdr array
printf("Enter Reader's name: ");
scanf("%s", rdr[i].name);
printf("Enter Reader id: ");
scanf("%d", &rdr[i].id);
rdr[i].due='n';
rdr[i].dbid=0;
i=10;
printf("Reader added successfully.\n\n");
}
}
break;
case 4:
printf("Enter Reader ID: ");
scanf("%d", &searchid);
n=0;
for(int i=0; i<10; i++){
if (searchid==rdr[i].id){
printf("\n\tReader Information\nReader ID: %d\tReader Name: %s\nDue: %c\t\tDue book ID: %d\n", rdr[i].id, rdr[i].name, rdr[i].due, rdr[i].dbid);
n++;
}
}
if(n==0){
printf("Reader not found.\n\n");
}
break;
case 5:
printf("Enter book ID: ");
scanf("%d", &searchid);
printf("Enter reader ID: ");
scanf("%d", &searchid1);
n=0;
m=0;
for(int i=0; i<20; i++){
if (searchid==bk[i].id && bk[i].avbl=='y'){
bk[i].avbl='n';
bk[i].rid=searchid1;
n++;
i=20;
}
}
for(int i=0; i<10; i++){
if (searchid1==rdr[i].id && rdr[i].due=='n'){
rdr[i].due='y';
rdr[i].dbid=searchid;
m++;
i=10;
}
}
if(n==1 && m==1){
printf("Book issued successfully.\n\n");
}
else if(n==1 && m==0){
for(int i=0; i<20; i++){
if (searchid==bk[i].id){
bk[i].avbl='y';
bk[i].rid=0;
i=20;
}
}
printf("Book not issued.\nReader has a due book.\n\n");
}
break;
case 6:
printf("Enter book ID: ");
scanf("%d", &searchid);
for(int i=0; i<20; i++){
if (searchid==bk[i].id){
bk[i].avbl='y';
searchid1=bk[i].rid;
bk[i].rid=0;
}
}
for(int i=0; i<10; i++){
if (searchid1==rdr[i].id){
rdr[i].due='n';
rdr[i].dbid=0;
}
}
printf("Book ID %d submitted successfully.\n\n", searchid);
break;
case 7:
printf("Enter book ID to be deleted: ");
scanf("%d", &searchid);
n=0;
for(int i=0; i<20; i++){
if (searchid==bk[i].id){
for(i=i; i<20; i++){
bk[i]=bk[i+1];
}
n++;
}
}
if(n!=0){
printf("Book ID %d deleted.\n\n", searchid);
}
else
printf("Book not found.\n\n");
break;
case 8:
printf("Enter reader ID to be deleted: ");
scanf("%d", &searchid);
n=0;
for(int i=0; i<10; i++){
if (searchid==rdr[i].id){
for(i=i; i<10; i++){
rdr[i]=rdr[i+1];
}
n++;
}
}
if(n!=0){
printf("Reader ID %d deleted.\n\n", searchid);
}
else
printf("Reader not found.\n\n");
break;
case 9:
n=0;
for(int i=0; i<20; i++){
if(bk[i].id != 0){
n++;
}
}
printf("\n\t\tBook list\tTotal books: %d\n\nID\tName\t\t\tAuthor\t\t\tAvailable\tReader ID\n\n", n);
for(int i=0; i<20; i++){
if(bk[i].id != 0){
printf("%d\t%s\t\t%s\t\t%c\t\t%d\n", bk[i].id, bk[i].name, bk[i].author, bk[i].avbl, bk[i].rid);
}
}
break;
case 10:
printf("\n\t\tTHANK YOU!");
exit(0);
break;
}
}while(choice!=10);
return 0;
}