The project ‘Library Book Info System (LBIS)’ is going to develop for College has a good library enriched with a lot of books. The prime objective of the project is to fulfill the requirements of college library. This project has been developed to replace the existing manual system for keeping books records with computerized automated books record processing system. This project will automatically reduce the human efforts, time and cost and increases efficiency and accuracy of storing books records. The library staffs can get the right information in time and make further planning.
Source code of Library Book Info System is given below:
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 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 |
//code to include necessary header files #include<stdio.h> #include<conio.h> #include<process.h> #include<string.h> //Code to declare function prototype void insertData(); void displayData(void); void updateData(int); void deleteData(int); void searchData(void); int checkBookNo(int); int findLastBookNo(void); //code to declare file pointer FILE *fp,*fp1; //code to design structure struct book { int bn; char title[200]; char sub[100]; float price; int nob; char author[100]; char publisher[100]; }; //code to declare structure variable struct book b; //code to declare main function main() { int choice; int bn; while(1) { //code to display menu clrscr(); printf("\n\t\t*************************************************"); printf("\n\t\t*************************************************"); printf("\n\t\t***WELCOME TO YOU IN LIBRARY BOOKS INFO SYSTEM***"); printf("\n\t\t*************************************************"); printf("\n\t\t*************************************************"); printf("\n\t\t*********************MENU************************"); printf("\n\t\t*************************************************"); printf("\n\t\t\t\t1. Insert Record "); printf("\n\t\t\t\t2. Display Record"); printf("\n\t\t\t\t3. Update Record"); printf("\n\t\t\t\t4. Delete Record"); printf("\n\t\t\t\t5. Search Record"); printf("\n\t\t\t\t6. Quit"); printf("\n\n\tEnter your choice between 1 to 6 : "); scanf("%d",&choice); switch (choice) { case 1: //code to call insertData function insertData(); break; case 2: //code to call displayData function displayData(); break; case 3: //code to call updateData function printf("\n Enter the book no. which you want to update "); scanf("%d",&bn); updateData(bn); break; case 4: //code to call deleteData function printf("\n Enter the book no. which you want to delete "); scanf("%d",&bn); deleteData(bn); break; case 5: //code to call searchdata function searchData(); break; case 6: exit(0); default: printf("\nSORRY!!! You entered an invalid choice "); printf("\n Please, enter the valid choice between 1 to 6 "); getch(); } } } //COde to declare function definition void insertData() { char next='y'; int duplicatebookno=0,lastbookno;; clrscr(); while(next=='y'||next=='Y') { aa: clrscr(); printf("\nEnter the book no "); scanf("%d",&b.bn); //code to call function to check the book no. has been repeated or not duplicatebookno=checkBookNo(b.bn); if(duplicatebookno==1) { printf("\n\nThe book no. which you typed just now, is already exists in the data file!!!!!"); printf("\n\nPlease, enter the unique book no.!!!"); lastbookno=findLastBookNo(); printf("\n\nThe last book no. is : %d",lastbookno); getch(); goto aa; } fflush(stdin); printf("\nEnter the title of the book "); gets(b.title); printf("\nEnter the subject of the book "); gets(b.sub); printf("Enter the price of the book "); scanf("%f",&b.price); printf("\nEnter the no. of book "); scanf("%d",&b.nob); fflush(stdin); printf("\nEnter the author of the book "); gets(b.author); printf("\nEnter the publisher of the book "); gets(b.publisher); fp=fopen("Book.dat","a"); if(fp==NULL) { printf("\nFile creation error has occurred!!!"); } else { fwrite(&b,sizeof(b),1,fp); fclose(fp); printf("\n\nDo you want to insert record of another book (Y/N)? "); next=getche(); } } } void displayData(void) { clrscr(); fp=fopen("Book.dat","r"); rewind(fp); if(fp==NULL) { printf("\n\nRead operation failure as the file file which you are searching does not exist!!!"); } else { printf("\n\tBook No.\tTitle\Subject\tPrice\tNo. of Books\tAuthor\tPublisher"); while(fread(&b,sizeof(b),1,fp)==1) { printf("\n\t%-8d\t%s\t%s\tRs. %.2f\t%d\t%s\t%s",b.bn,b.title,b.sub,b.price,b.nob,b.author,b.publisher); } fclose(fp); } getch(); } void updateData(int bn) { fp=fopen("Book.dat","r"); fp1=fopen("newBook.dat","w"); if(fp==NULL || fp1==NULL) { printf("\nFile Operation failed"); } else { //code to show the existing data printf("\n\nThe followings are the existing data!!!!!!"); while(fread(&b,sizeof(b),1,fp)==1) { if(b.bn==bn) { printf("\n\tBook No. : %d",b.bn); printf("\n\tTitle : %s",b.title); printf("\n\tSubject : %s",b.sub); printf("\n\tPrice : Rs. %.2f",b.price); printf("\n\tNo. of Books : %d",b.nob); printf("\n\tAuthor : %s",b.author); printf("\n\tPublisher : %s",b.publisher); } } //code to enter new data rewind(fp); printf("\n\nEnter the new correct data "); while(fread(&b,sizeof(b),1,fp)==1) { if(bn==b.bn) { printf("\n\n\nEnter the book no "); scanf("%d",&b.bn); fflush(stdin); printf("\nEnter the title of the book "); gets(b.title); printf("\nEnter the subject of the book "); gets(b.sub); printf("Enter the price of the book "); scanf("%f",&b.price); printf("\nEnter the no. of book "); scanf("%d",&b.nob); fflush(stdin); printf("\nEnter the author of the book "); gets(b.author); printf("\nEnter the publisher of the book "); gets(b.publisher); fwrite(&b,sizeof(b),1,fp1); } else { fwrite(&b,sizeof(b),1,fp1); } } fclose(fp); fclose(fp1); remove("Book.dat"); rename("newBook.dat","Book.dat"); printf("\n\nThe record has been successfully updated in the data file"); } getch(); } void deleteData(int bn) { fp=fopen("Book.dat","r"); fp1=fopen("newBook.dat","w"); if(fp==NULL || fp1==NULL) { printf("\nFile Operation failed"); } else { while(fread(&b,sizeof(b),1,fp)==1) { if(bn==b.bn) { continue; } else { fwrite(&b,sizeof(b),1,fp1); } } fclose(fp); fclose(fp1); remove("Book.dat"); rename("newBook.dat","Book.dat"); printf("\n\nThe record has been successfully deleted from the data file"); } getch(); } void searchData(void) { int bn,found=0; char bname[100],subject[100]; int ch; clrscr(); printf("\n\t\t*****************************************"); printf("\n\t\t********Search Menu**********************"); printf("\n\t\t*****************************************"); printf("\n\t\t1. Search by Book No. "); printf("\n\t\t2. Search by Book Title "); printf("\n\t\t3. Search by Book Subject "); printf("\n\t\t4. Quit Search"); printf("\n\nEnter your choice for search "); scanf("%d",&ch); switch(ch) { case 1: //search on the basis of book no. clrscr(); fp=fopen("Book.dat","r"); printf("\n\nEnter the book no. which you want to search "); scanf("%d",&bn); if(fp==NULL) { printf("\nFile search operation failed!!!!!!!!!!!!!!!!"); } else { while(fread(&b,sizeof(b),1,fp)==1) { if(b.bn==bn) { printf("\n\tBook No. : %d",b.bn); printf("\n\tTitle : %s",b.title); printf("\n\tSubject : %s",b.sub); printf("\n\tPrice : Rs. %.2f",b.price); printf("\n\tNo. of Books : %d",b.nob); printf("\n\tAuthor : %s",b.author); printf("\n\tPublisher : %s",b.publisher); found=1; } } if(found==0) { printf("\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); printf("\nThe book which you are searching is not found "); } fclose(fp); } break; case 2: //searh on the basis of book title clrscr(); fflush(stdin); printf("\n\nEnter the title of the book which you want to search "); gets(bname); fp=fopen("Book.dat","r"); if(fp==NULL) { printf("\nFile search operation failed!!!!!!!!!!!!!!!!"); } else { while(fread(&b,sizeof(b),1,fp)==1) { if(strcmpi(b.title,bname)==0) { printf("\n\tBook No. : %d",b.bn); printf("\n\tTitle : %s",b.title); printf("\n\tSubject : %s",b.sub); printf("\n\tPrice : Rs.%.2f",b.price); printf("\n\tNo. of Books : %d",b.nob); printf("\n\tAuthor : %s",b.author); printf("\n\tPublisher : %s",b.publisher); found=1; } } if(found==0) { printf("\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); printf("\nThe book which you are searching is not found "); } fclose(fp); } break; case 3: //search on the basis of subject clrscr(); fflush(stdin); printf("\n\nEnter the subject of the book which you want to search "); gets(subject); fp=fopen("Book.dat","r"); if(fp==NULL) { printf("\nFile search operation failed!!!!!!!!!!!!!!!!"); } else { while(fread(&b,sizeof(b),1,fp)==1) { if(strcmpi(b.sub,subject)==0) { printf("\n\tBook No. : %d",b.bn); printf("\n\tTitle : %s",b.title); printf("\n\tSubject : %s",b.sub); printf("\n\tPrice : Rs.%.2f",b.price); printf("\n\tNo. of Books : %d",b.nob); printf("\n\tAuthor : %s",b.author); printf("\n\tPublisher : %s",b.publisher); found=1; } } if(found==0) { printf("\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); printf("\nThe book which you are searching is not found "); } fclose(fp); } break; case 4: //code to close search window printf("\nPress any key to quit the search operation"); break; default: printf("\nYou entered invalid choice for search "); } getch(); } int checkBookNo(int bn) { int repeated=0,lastbookno; struct book b1; fp=fopen("Book.dat","r"); if(fp==NULL) { printf("\n\nRead operation failure as the file file which you are searching does not exist!!!"); } else { while(fread(&b1,sizeof(b1),1,fp)==1) { if(b1.bn==bn) { repeated=1; break; } } fclose(fp); } return(repeated); } int findLastBookNo() { int lastbookno; struct book b2; fp=fopen("Book.dat","r"); if(fp==NULL) { printf("\n\nFile open operation failure!!!"); } else { while(fread(&b2,sizeof(b2),1,fp)==1) { lastbookno=b2.bn; } fclose(fp); } return(lastbookno); } |
The output of the Program is shown below:
The menu facility  in order to select the required operations in the program:
The search menu option:
The input screen for inserting the record of new book in library is as follows:
The output of the display operations will be as follows:
The output of the search operation will be displayed as follows: