Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<conio.h>
- #include<string.h>
- #include<stdlib.h>
- #include<windows.h>
- // profile structure
- struct profile {
- char name[100];
- char firstname[40];
- char lastname[40];
- char address[40];
- long long int phoneNumber;
- int userID ;
- };
- //books structure
- struct books
- { int userid;
- int issuemonth;
- int day,month,year;
- int issueday;
- int issueyear;
- int submitmonth;
- int submitday;
- int submityear;
- long long int isbn;
- char user[50];
- char bookname[50];
- int quantity;
- char category[30];
- char author[40];
- };
- int userid1;
- long long int isbn1;
- //Profjile Functions List
- void mainMenu();
- void adduser();
- void deluser();
- void edituser();
- void listuser();
- void searchuser();
- void adminlogin();
- //book functions list
- void booksection();
- void addbook();
- void listbook();
- void searchbook();
- void delbook();
- void editbook();
- void viewissuedbook();
- void issuemain();
- void borrowbook();
- void returnbook();
- void category();
- void searchissue();
- void delissuebook();
- int viewissuedbookofuser(int);
- //main function.
- int main()
- {
- system("color f"); //sets system color to bright white.
- adminlogin();
- return 0;
- }
- void adminlogin() //sets up admin login window.
- {
- int i=0;
- char aa[20],ch;
- char password[30];
- char username[30];
- start:
- printf("\t\t\t\t[LIBRARY MANAGEMENT SYSTEM]\n");
- printf("\t\t\t..............................................\n\n");
- printf("\t\t\t\t\t[ADMIN LOGIN] \n\n");
- printf("\t\t\tEnter your username: ");
- scanf("%s",username);
- printf("\t\t\tEnter your password: ");
- while(ch!=13)
- {
- ch=_getch();
- if(ch!=13){
- putch('*');
- password[i] = ch;
- i++;
- }
- }
- password[i] = '\0';
- if(strcmp(username,"a")==0){
- if(strcmp(password,"b")==0)
- {
- printf("\n\n");
- char loading[]="\t\t\t\tloading.....................................!!\n";
- while(loading[i]!='\0')
- {
- Sleep(15);
- printf("%c",loading[i]);
- i++;
- }
- printf("\n Login Success!!\n\n");
- printf("\n Enter any key to continue! \n\n");
- _getch();
- mainMenu();
- }
- else{
- printf("\n\n");
- printf("\t\t\t..............................................\n");
- printf("\n Wrong Password!!\n\n");
- remsk:
- printf("\n");
- printf("\t\t\tWould you like to try again?[yes?/no?]: ");
- scanf("%s",aa);
- if (strcmp(aa,"yes")==0)
- {
- system("cls"); //clears the screen before proceeding to the next step.
- adminlogin();
- }
- if (strcmp(aa,"no")==0)
- {
- exit(0);
- }
- else if(1)
- {
- system("cls");
- printf("\n");
- printf("\t\t\tInvalid choice. Enter [yes/no] only!");
- goto remsk;
- }
- }
- }else{
- printf("\n\n");
- printf("\t\t\t..............................................\n");
- printf("\n User doesn't exist!\n\n\n\n");
- goto remsk;
- }
- _getch();
- mainMenu();
- }
- //For Main Menu
- void mainMenu(){
- system("color E");//yellow
- system("cls");
- printf("\t\t\t\t[LIBRARY MANAGEMENT SYSTEM]\n\n");
- printf("\t\t\t...........................................\n");
- printf("\t\t\t:\t\t[MAIN MENU]\t :\n");
- printf("\t\t\t:.........................................:\n");
- printf("\n\n\n\t\t\t1.Register user\n\t\t\t2.List users\n\t\t\t3.Edit user\n\t\t\t4.Delete User\n\t\t\t5.Search user\n\t\t\t6.Book section\n\t\t\t7.Exit\n");
- printf("\t\t\tPress (1-7)\n");
- printf(" ..............................................\n");
- switch(_getch()){
- case '1': adduser();
- break;
- case '2': listuser();
- break;
- case '3': edituser();
- break;
- case '4': deluser();
- break;
- case '5': searchuser();
- break;
- case '6': booksection();
- break;
- case '7': exit(0);
- break;
- default:
- printf("\nEnter any key to try again.");
- _getch();
- system("cls");
- mainMenu();
- }
- }
- // For Adding New users
- void adduser(){
- struct profile b;
- struct profile g;
- int i,j;
- int o;
- int userID;
- FILE *f;
- FILE *another;
- f=fopen("frecord.txt","ab");
- f=fopen("frecord.txt","rb");
- system("cls");
- printf("\t\t\t\t[LIBRARY MANAGEMENT SYSTEM]\n\n");
- printf("\t\t\t...........................................\n");
- printf("\t\t\t:\t\t[USER REGISTER]\t :\n");
- printf("\t\t\t...........................................\n");
- printf("\t\t\t\tEnter first and last name: ");
- scanf("%s %s",b.firstname,b.lastname);
- fflush(stdin);
- name1:
- strcat(b.firstname," ");
- strcat(b.firstname,b.lastname);
- for (j=0;b.firstname[j]!='\0';++j)//copying
- {
- b.name[j]=b.firstname[j];
- }
- b.name[j]='\0';
- for (j=0;b.name[j]!='\0';++j)
- {
- if (b.name[j]>='0' && b.name[j]<='9')
- {
- printf("\n");
- printf("\t\t\t\tInvalid name\n");
- printf("\t\t\t\tEnter name again: ");
- scanf("%s %s",b.firstname,b.lastname);
- fflush(stdin);
- goto name1;
- break;
- }
- }
- printf("\t\t\t\tEnter address: ");
- scanf("%s",&b.address);
- fflush(stdin);
- printf("\t\t\t\tEnter phone number: ");
- scanf("%lld",&b.phoneNumber);
- fflush(stdin);
- chck:
- if (b.phoneNumber<=9999999999 && b.phoneNumber>=99999999)
- {
- printf("\t\t\t\tEnter UserID: ");
- while(scanf("%d", &userID)==0) //if scanf failed to scan an integer
- {
- printf("Invalid input. Try again\n");
- int c;
- while((c=getchar())!='\n' && c!=EOF); //clear the stdin
- }
- fwrite(&b, sizeof(b), 1, f);
- another=fopen("frecord.txt","ab");
- strcpy(g.name,b.name);
- strcpy(g.address,b.address);
- g.phoneNumber=b.phoneNumber;
- while (fread(&b,sizeof(b),1,f)==1)
- {
- if (userID==b.userID)
- {
- fclose(f);
- o=1;
- }
- }
- if (o!=1)
- {
- g.userID=userID;
- fwrite(&g, sizeof(g), 1, another);
- printf("\t\t\tThe user id is available\n");
- fclose(another);
- }
- else if (o==1){
- printf("\t\t\tThe user ID already exists!!\n");
- _getch();
- mainMenu();
- }
- }
- else
- {
- printf("\n\t\t\t\tInvalid phone number!\n");
- printf("\t\t\t\tEnter new phone number: ");
- scanf("%lld",&b.phoneNumber);
- fflush(stdin);
- goto chck;
- }
- printf(" ............................................\n");
- printf("\nRecord Saved!\n");
- printf("\n\n");
- printf("Would you like to add more user? [y/n]: ");
- readd:
- i=_getch();
- if (i=='y')
- {
- adduser();
- }
- if (i=='n')
- {
- printf("\nEnter any key to go back!");
- _getch();
- system("cls");
- mainMenu();
- }
- else if(1)
- {
- goto readd;
- }
- }
- //Listing users profile
- void listuser(){
- struct profile g;
- FILE *another;
- another=fopen("frecord.txt","rb"); //binary read mode
- system("cls");
- if (another==NULL){
- printf("\nERROR OPENING FILE, THE RECORD FILE DOES NOT EXIST!!!");
- getch();
- mainMenu();
- }
- printf("\t\t\t\t[LIBRARY MANAGEMENT SYSTEM]\n\n");
- printf("\t\t\t..................................................\n");
- printf("\t\t\t:\t\t[LIST USERS PROFILE] :\n");
- printf("\t\t\t:................................................:\n");
- while(fread(&g,sizeof(g),1,another)==1){
- printf("\nName: %s\nAddress: %s\nMobile no: %lld\nUser ID: %d\n\n",g.name,g.address,g.phoneNumber,g.userID);
- }
- printf("............................................\n");
- fclose(another);
- printf("\nEnter any key to go back!");
- _getch();
- system("cls");
- mainMenu();
- }
- //Editing profile
- void edituser(){
- int id;
- int found;
- int e,j;
- struct profile b;
- FILE *fp;
- FILE *ftemp;
- fp = fopen("frecord.txt","rb");
- ftemp = fopen("ftemprecord.txt","wb");
- system("cls");
- printf("\t\t\t\t[LIBRARY MANAGEMENT SYSTEM]\n\n");
- printf("\t\t\t..................................................\n");
- printf("\t\t\t:\t\t[EDIT USERS PROFILE] :\n");
- printf("\t\t\t:................................................:\n");
- printf("\t\t\tEnter Users ID to modify: ");
- scanf("%d",&id);
- fflush(stdin);
- printf("\n");
- while(fread(&b,sizeof(b),1,fp)==1){
- if(id!=b.userID)
- fwrite(&b,sizeof(b),1,ftemp);
- if(id==b.userID){
- found = 1;
- }
- }
- if (found == 1){
- printf("\t\t\t\tEnter first and last name: ");
- scanf("%s %s",b.firstname,b.lastname);
- fflush(stdin);
- name1:
- strcat(b.firstname," ");
- strcat(b.firstname,b.lastname);
- for (j=0;b.firstname[j]!='\0';++j)
- {
- b.name[j]=b.firstname[j];
- }
- b.name[j]='\0';
- for (j=0;b.name[j]!='\0';++j)
- {
- if (b.name[j]>='0' && b.name[j]<='9')
- {
- printf("\n");
- printf("\t\t\t\tInvalid name\n");
- printf("\t\t\t\tEnter name again: ");
- scanf("%s %s",b.firstname,b.lastname);
- fflush(stdin);
- goto name1;
- break;
- }
- }
- printf("\t\t\t\tEnter address: ");
- scanf("%s",&b.address);
- fflush(stdin);
- printf("\t\t\t\tEnter phone number: ");
- scanf("%lld",&b.phoneNumber);
- fflush(stdin);
- chck:
- if (b.phoneNumber<=9999999999 && b.phoneNumber>=9999999)
- {
- printf("\t\t\t\tEnter UserID: ");
- while(scanf("%d", &b.userID)==0) //if scanf failed to scan an integer
- {
- printf("\t\t\t\tInvalid input. Try again\n");
- int c;
- while((c=getchar())!='\n' && c!=EOF); //clear the stdin
- }
- }
- else
- {
- printf("\n\t\t\t\tInvalid phone number!\n");
- printf("\t\t\t\tEnter new phone number: ");
- scanf("%lld",&b.phoneNumber);
- fflush(stdin);
- goto chck;
- }
- fwrite(&b,sizeof(b),1,ftemp);
- }else if(found!=1){
- printf("The contact does not exist!");
- }
- fclose(fp);
- fclose(ftemp);
- remove("frecord.txt");
- rename("ftemprecord.txt","frecord.txt");
- printf("\n\nEnter any key to go back!");
- _getch();
- system("cls");
- mainMenu();
- }
- //Searching profile
- void searchuser(){
- int id;
- int de,c;
- struct profile b;
- FILE *fp;
- fp=fopen("frecord.txt","rb");
- system("cls");
- printf("\t\t\t\t[LIBRARY MANAGEMENT SYSTEM]\n\n");
- printf("\t\t\t...........................................\n");
- printf("\t\t\t:\t\t[SEARCH USER]\t :\n");
- printf("\t\t\t:.........................................:\n\n");
- printf("\t\t\tEnter Users ID to search: ");
- scanf("%d",&id);
- printf("\n\n");
- fflush(stdin);
- printf("\n");
- while (fread(&b,sizeof(b),1,fp)==1)
- {
- if (id==b.userID){
- printf("\n[%s Profile ID]\n",b.name);
- printf("\nName: %s\nAddress: %s\nMobile no: %lld\nUser ID: %d\n\n",b.name,b.address,b.phoneNumber,b.userID);
- de=1;
- }
- }
- if (de==1)
- {
- printf("\n\n");
- printf("Would you like to search another user?[y/n]: ");
- research:
- c=_getch();
- if (c=='y')
- {
- searchuser();
- }
- if (c=='n')
- {
- printf("\n\n");
- printf("\n\nEnter any key to go back!");
- _getch();
- system("cls");
- mainMenu();
- }
- }
- if (de!=1)
- {
- printf("\t\t\t\t\t*INVALID USER*");
- printf("\n\nEnter any key to go back!");
- _getch();
- system("cls");
- mainMenu();
- }
- fclose(fp);
- }
- //Deleting profile
- void deluser(){
- char name[20];
- int recordExists,id;
- system("cls");
- fflush(stdin);
- struct profile b;
- FILE *fp;
- FILE *ftemp;
- fp = fopen("frecord.txt","rb");
- ftemp = fopen("ftemprecord.txt","wb");
- printf("\t\t\t\t[LIBRARY MANAGEMENT SYSTEM]\n\n");
- printf("\t\t\t...........................................\n");
- printf("\t\t\t:\t\t[DELETE USER]\t :\n");
- printf("\t\t\t:.........................................:\n\n");
- printf("\t\t\tEnter Users ID to delete: ");
- scanf("%d",&id);
- fflush(stdin);
- printf("\n");
- while (fread( &b, sizeof(b), 1, fp) == 1) {
- if (id!=b.userID)
- fwrite(&b, sizeof(b), 1, ftemp);
- if (id==b.userID)
- recordExists = 1;
- }
- fclose(fp);
- fclose(ftemp);
- if(recordExists!=1){
- printf("The contact does not exist!");
- }else{
- remove("frecord.txt");
- rename("ftemprecord.txt", "frecord.txt");
- printf("\t\tRECORD DELETED SUCCESSFULLY.");
- }
- printf("\n\nEnter any key to go back!");
- _getch();
- system("cls");
- mainMenu();
- }
- void booksection()
- {
- system("cls");
- system("color A");
- printf("\t\t\t\t[LIBRARY MANAGEMENT SYSTEM]\n\n");
- printf("\t\t\t.............................................\n");
- printf("\t\t\t:\t\t[BOOK SECTION]\t :\n");
- printf("\t\t\t:...........................................:\n\n");
- printf("\t\t\t1.Add book\n\t\t\t2.List Book\n\t\t\t3.Edit book\n\t\t\t4.Delete Book\n\t\t\t5.Search Book\n\t\t\t6.Issue Book\n\t\t\t7.Exit\n\t\t\t8.Go back\n");
- printf("\t\t\tPress (1-8)\n");
- printf(" ..............................................\n");
- switch(_getch()){
- case '1': addbook();
- break;
- case '2':listbook();
- break;
- case '3':editbook();
- break;
- case '4':delbook();
- break;
- case '5':searchbook();
- break;
- case '6':issuemain();
- break;
- case '7':exit(0);
- break;
- case '8': mainMenu();
- break;
- default:
- printf("\nEnter any key to try again.");
- _getch();
- system("cls");
- booksection();
- }
- }
- //add books in the library
- void addbook()
- {
- char m[20];
- struct books d;
- FILE *fb;
- fb=fopen("booksection.txt","ab");
- char bookname[50];
- int s;
- system("cls");
- printf("\t\t\t...........................................\n");
- printf("\t\t\t:\t\t[ADD BOOKS]\t :\n");
- printf("\t\t\t:.........................................:\n\n");
- printf("\t\t\t\t[SELECT CATEGORY]\n\n");
- printf("\t\t 1. Computer\n");
- printf("\t\t 2. Science\n");
- printf("\t\t 3. Medical\n");
- printf("\t\t 4. Language\n");
- printf("\t\t 5. Arts and literature\n");
- printf("\t\t 6. History\n");
- printf("\t\t 7. Back \n");
- printf("\t\tEnter your choice: ");
- scanf("%d",&s);
- fflush(stdin);
- switch(s)
- {
- case 1: strcpy(d.category,"Computer");
- goto add;
- break;
- case 2:strcpy(d.category,"Science");
- goto add;
- break;
- case 3:strcpy(d.category,"Medical");
- goto add;
- break;
- case 4:strcpy(d.category,"Language");
- goto add;
- break;
- case 5:strcpy(d.category,"Arts and literature");
- goto add;
- break;
- case 6:strcpy(d.category,"History");
- goto add;
- break;
- case 7:
- booksection();
- break;
- default: printf("\t\tInvalid choice\n");
- booksection();
- break;
- }
- add:
- printf("\n\n");
- printf("\t\t\tEnter the name of the book to be added: ");
- scanf("%s",d.bookname);
- fflush(stdin);
- printf("\t\t\tEnter the name of the author: ");
- scanf("%s",d.author);
- fflush(stdin);
- printf("\t\t\t\tEnter issue date(dd/mm/yy):\n ");
- printf("\t\t\t\tEnter day: ");
- scanf("%d",&d.day);
- fflush(stdin);
- dete:
- if (d.day>0 && d.day<=30)
- {
- printf("\t\t\t\tEnter month: ");
- scanf("%d",&d.month);
- fflush(stdin);
- dete2:
- if (d.month>0 && d.month<=12)
- {
- printf("\t\t\t\tEnter year: ");
- scanf("%d",&d.year);
- fflush(stdin);
- dete3:
- if (d.year>2018 && d.year<2020)
- {
- printf("\t\t\t\tEnter Book ISBN(5 digits):");
- scanf("%lld",&d.isbn);
- fflush(stdin);
- dete4:
- if (d.isbn>9999 && d.isbn<100000)
- {
- printf("\t\t\t\tEnter quantity of book:");
- while(scanf("%d", &d.quantity)==0) //if scanf failed to scan an integer
- {
- printf("\t\t\tInvalid input. Try again\n");
- int c;
- while((c=getchar())!='\n' && c!=EOF); //clear the stdin
- }
- }
- else{
- printf("\n");
- printf("\t\t\t\tInvalid entry!!\n");
- printf("\t\t\t\tEnter ISBN again: ");
- scanf("%lld",&d.isbn);
- fflush(stdin);
- goto dete4;
- }
- }
- else
- {
- printf("\n");
- printf("\t\t\t\tInvalid entry!!\n");
- printf("\t\t\t\tEnter year again: ");
- scanf("%d",&d.year);
- fflush(stdin);
- goto dete3;
- }
- }
- else
- {
- printf("\n");
- printf("\t\t\t\tInvalid entry!!\n");
- printf("\t\t\t\tEnter month again: ");
- scanf("%d",&d.month);
- fflush(stdin);
- goto dete2;
- }
- }
- else{
- printf("\n");
- printf("\t\t\t\tInvalid entry!!\n");
- printf("\t\t\t\tEnter day again: ");
- scanf("%d",&d.day);
- fflush(stdin);
- goto dete;
- }
- printf(" ............................................\n");
- fwrite(&d,sizeof(d),1,fb);
- fclose(fb);
- printf("\n\t\t\tRecord Saved\n\n!");
- printf("\t\t\tEnter <main> to go to the main menu or press any key to go back: ");
- scanf("%s",m);
- if (strcmp(m,"main")==0)
- {
- system("cls");
- mainMenu();
- }
- else if (1)
- {
- system("cls");
- booksection();
- }
- }
- void listbook()
- {
- struct books d;
- FILE *fb;
- fb=fopen("booksection.txt","rb"); //binary read mode
- system("cls");
- if (fb==NULL){
- printf("\nERROR OPENING FILE, THE RECORD FILE DOES NOT EXIST!!!");
- getch();
- booksection();
- }
- printf("\t\t\t..................................................\n");
- printf("\t\t\t:\t\t [LIST BOOKS] :\n");
- printf("\t\t\t:................................................:\n");
- while(fread(&d,sizeof(d),1,fb)==1){
- printf("\nCategory: %s\nBook Name: %s\nAuthor: %s\nIssue date: %d/ %d/ %d\nBook ISBN: %lld\nBook Quantity: %d\n\n",d.category,d.bookname,d.author,d.day,d.month,d.year,d.isbn,d.quantity);
- }
- printf("............................................\n");
- fclose(fb);
- printf("\nEnter any key to go back!");
- _getch();
- system("cls");
- booksection();
- }
- //edit book information
- void editbook(){
- char m[20];
- long long int bookid;
- int bfound;
- int be;
- int s;
- struct books d;
- FILE *fb;
- FILE *fbtemp;
- fb=fopen("booksection.txt","rb"); //binary read mode
- fbtemp = fopen("fbtemprecord.txt","wb");
- system("cls");
- printf("\t\t\t..................................................\n");
- printf("\t\t\t:\t\t [EDIT BOOKS] :\n");
- printf("\t\t\t:................................................:\n");
- printf("\t\t\tEnter BOOK ISBN to modify: ");
- scanf("%lld",&bookid);
- fflush(stdin);
- printf("\n");
- while(fread(&d,sizeof(d),1,fb)==1){
- if(bookid!=d.isbn)
- fwrite(&d,sizeof(d),1,fbtemp);
- if(bookid==d.isbn){
- bfound = 1;
- }
- }
- if (bfound == 1){
- printf("\t\t\t\t[SELECT CATEGORY]\n\n");
- printf("\t\t 1. Computer\n");
- printf("\t\t 2. Science\n");
- printf("\t\t 3. Medical\n");
- printf("\t\t 4. Language\n");
- printf("\t\t 5. Arts and literature\n");
- printf("\t\t 6. History\n");
- printf("\t\t 7. Back \n");
- printf("\t\tEnter your choice: ");
- scanf("%d",&s);
- fflush(stdin);
- switch(s)
- {
- case 1: strcpy(d.category,"Computer");
- goto add;
- break;
- case 2:strcpy(d.category,"Science");
- goto add;
- break;
- case 3:strcpy(d.category,"Medical");
- goto add;
- break;
- case 4:strcpy(d.category,"Language");
- goto add;
- break;
- case 5:strcpy(d.category,"Arts and literature");
- goto add;
- break;
- case 6:strcpy(d.category,"History");
- goto add;
- break;
- case 7:
- booksection();
- break;
- default: printf("\t\tInvalid choice\n");
- booksection();
- break;
- }
- add:
- printf("\t\t\tEnter the name of the book to be added: ");
- scanf("%s",d.bookname);
- fflush(stdin);
- printf("\t\t\tEnter the name of the author: ");
- scanf("%s",d.author);
- fflush(stdin);
- printf("\t\t\t\tEnter issue date(dd/mm/yy):\n");
- printf("\t\t\t\tEnter day: ");
- scanf("%d",&d.day);
- fflush(stdin);
- dete:
- if (d.day>0 && d.day<=30)
- {
- printf("\t\t\t\tEnter month: ");
- scanf("%d",&d.month);
- fflush(stdin);
- dete2:
- if (d.month>0 && d.month<=12)
- {
- printf("\t\t\t\tEnter year: ");
- scanf("%d",&d.year);
- fflush(stdin);
- dete3:
- if (d.year>2018 && d.day<2020)
- {
- printf("\t\t\t\tEnter Book ISBN(5 digits):");
- scanf("%lld",&d.isbn);
- fflush(stdin);
- dete4:
- if (d.isbn>9999 && d.isbn<100000)
- {
- printf("\t\t\t\tEnter quantity of book:");
- while(scanf("%d", &d.quantity)==0) //if scanf failed to scan an integer
- {
- printf("\t\t\t\tInvalid input. Try again\n");
- int c;
- while((c=getchar())!='\n' && c!=EOF); //clear the stdin
- }
- }
- else{
- printf("\n");
- printf("\t\t\t\tInvalid entry!!\n");
- printf("\t\t\t\tEnter ISBN again: ");
- scanf("%lld",&d.isbn);
- fflush(stdin);
- goto dete4;
- }
- }
- else
- {
- printf("\n");
- printf("\t\t\t\tInvalid entry!!\n");
- printf("\t\t\t\tEnter year again: ");
- scanf("%d",&d.year);
- fflush(stdin);
- goto dete3;
- }
- }
- else
- {
- printf("\n");
- printf("\t\t\t\tInvalid entry!!\n");
- printf("\t\t\t\tEnter month again: ");
- scanf("%d",&d.month);
- fflush(stdin);
- goto dete2;
- }
- }
- else{
- printf("\n");
- printf("\t\t\t\tInvalid entry!!\n");
- printf("\t\t\t\tEnter day again: ");
- scanf("%d",&d.day);
- fflush(stdin);
- goto dete;
- }
- fwrite(&d,sizeof(d),1,fbtemp);
- }else if(bfound!=1){
- printf("\t\t\tThe book ID does not exist!");
- }
- fclose(fb);
- fclose(fbtemp);
- remove("booksection.txt");
- rename("fbtemprecord.txt","booksection.txt");
- printf("\n\n");
- printf("\t\t\tEnter <main> to go to the main menu or press any key to go back: ");
- scanf("%s",m);
- if (strcmp(m,"main")==0)
- {
- system("cls");
- mainMenu();
- }
- else if (1)
- {
- system("cls");
- booksection();
- }
- }
- void searchbook(){
- char m[20];
- long long int bid;
- int bde,bc;
- struct books d;
- int s;
- FILE *fb;
- fb=fopen("booksection.txt","rb");
- system("cls");
- printf("\t\t\t\t[LIBRARY MANAGEMENT SYSTEM]\n\n");
- printf("\t\t\t...........................................\n");
- printf("\t\t\t:\t\t[SEARCH BOOK]\t :\n");
- printf("\t\t\t:.........................................:\n\n");
- printf("\t\t\tSearch by category or ISBN?\n");
- printf("\n\t\t\t1.Category\n\t\t\t2.ISBN\n");
- printf("\t\t\tEnter you choice: ");
- scanf("%d",&s);
- switch(s)
- {
- case 1: category();
- break;
- case 2:goto srch;
- break;
- default:printf("\t\t\tInvalid choice!!");
- _getch();
- booksection();
- break;
- }
- srch:
- system("cls");
- printf("\t\t\tEnter BOOK ID to search: ");
- scanf("%lld",&bid);
- printf("\n\n");
- fflush(stdin);
- printf("\n");
- while (fread(&d,sizeof(d),1,fb)==1)
- {
- if (bid==d.isbn){
- printf("\n\t\t\t[%s Book Info]\n",d.bookname);
- printf("\n\t\t\tBook Name: %s\n\t\t\tAuthor: %s\n\t\t\tDate(dd/mm/yy): %d/ %d/ %d\n\t\t\tBook ISBN: %lld\n\t\t\tBook Quantity: %d\n\n",d.bookname,d.author,d.day,d.month,d.year,d.isbn,d.quantity);
- bde=1;
- }
- }
- if (bde==1)
- {
- printf("\n\n");
- printf("\t\t\tWould you like to search another book?[y/n]: ");
- research:
- bc=_getch();
- if (bc=='y')
- {
- searchbook();
- }
- if (bc=='n')
- {
- printf("\n\n");
- printf("\n\nEnter any key to go back!");
- _getch();
- system("cls");
- booksection();
- }
- else if(1)
- {
- goto research;
- }
- }
- if (bde!=1)
- {
- printf("\t\t\t\t\t*INVALID BOOK ISBN*");
- printf("\n\n");
- printf("\t\t\tEnter <main> to go to the main menu or press any key to go back: ");
- scanf("%s",m);
- if (strcmp(m,"main")==0)
- {
- system("cls");
- mainMenu();
- }
- else if (1)
- {
- system("cls");
- booksection();
- }
- }
- fclose(fb);
- }
- void category()
- {
- char m[20];
- char cat[30];
- long long int bid;
- int bde,bc;
- struct books d;
- int s;
- FILE *fb;
- fb=fopen("booksection.txt","rb");
- system("cls");
- printf("\t\t\t\t[LIBRARY MANAGEMENT SYSTEM]\n\n");
- printf("\t\t\t...........................................\n");
- printf("\t\t\t:\t\t[SEARCH BOOK]\t :\n");
- printf("\t\t\t:.........................................:\n\n");
- printf("\t\t\t\t[SELECT CATEGORY]\n\n");
- printf("\t\t 1. Computer\n");
- printf("\t\t 2. Science\n");
- printf("\t\t 3. Medical\n");
- printf("\t\t 4. Language\n");
- printf("\t\t 5. Arts and literature\n");
- printf("\t\t 6. History\n");
- printf("\t\t 7. Back \n");
- printf("\t\tEnter category to search: ");
- scanf("%s",cat);
- fflush(stdin);
- printf("\n");
- while (fread(&d,sizeof(d),1,fb)==1)
- {
- if (strcmp(cat,d.category)==0){
- printf("\n\t\t\t[%s Book Info]\n",d.bookname);
- printf("\n\t\t\tBook Name: %s\n\t\t\tAuthor: %s\n\t\t\tDate(dd/mm/yy): %d/ %d/ %d\n\t\t\tBook ISBN: %lld\n\t\t\tBook Quantity: %d\n\n",d.bookname,d.author,d.day,d.month,d.year,d.isbn,d.quantity);
- bde=1;
- }
- }
- if (bde==1)
- {
- printf("\n\n");
- printf("\t\t\tWould you like to search another book?[y/n]: ");
- research:
- bc=_getch();
- if (bc=='y')
- {
- searchbook();
- }
- if (bc=='n')
- {
- printf("\n\n");
- printf("\n\nEnter any key to go back!");
- _getch();
- system("cls");
- booksection();
- }
- else if(1)
- {
- goto research;
- }
- }
- if (bde!=1)
- {
- printf("\t\t\t\t\t*Book Not Found!!");
- printf("\n\n");
- printf("\t\t\tEnter <main> to go to the main menu or press any key to go back: ");
- scanf("%s",m);
- if (strcmp(m,"main")==0)
- {
- system("cls");
- mainMenu();
- }
- else if (1)
- {
- system("cls");
- booksection();
- }
- }
- fclose(fb);
- }
- void delbook(){
- char m[20];
- char bname[20];
- int brecordExists;
- long long int bid;
- system("cls");
- fflush(stdin);
- struct books d;
- FILE *fb;
- FILE *fbtemp;
- fb=fopen("booksection.txt","rb");
- fbtemp = fopen("fbtemprecord.txt","wb");
- printf("\t\t\t\t[LIBRARY MANAGEMENT SYSTEM]\n\n");
- printf("\t\t\t...........................................\n");
- printf("\t\t\t:\t\t[DELETE BOOK]\t :\n");
- printf("\t\t\t:.........................................:\n\n");
- printf("\t\t\tEnter Book ISBN to delete: ");
- scanf("%lld",&bid);
- fflush(stdin);
- printf("\n");
- while (fread( &d, sizeof(d), 1, fb) == 1) {
- if (bid!=d.isbn)
- fwrite(&d, sizeof(d), 1, fbtemp);
- if (bid==d.isbn)
- brecordExists = 1;
- }
- fclose(fb);
- fclose(fbtemp);
- if(brecordExists!=1){
- printf("\t\t\tThe book does not exist!");
- }else{
- remove("booksection.txt");
- rename("fbtemprecord.txt", "booksection.txt");
- printf("\t\tRECORD DELETED SUCCESSFULLY.");
- }
- printf("\n\n");
- printf("\t\t\tEnter <main> to go to the main menu or press any key to go back: ");
- scanf("%s",m);
- if (strcmp(m,"main")==0)
- {
- system("cls");
- mainMenu();
- }
- else if (1)
- {
- system("cls");
- booksection();
- }
- }
- void issuemain()
- {
- system("color E");//yellow
- system("cls");
- printf("\t\t\t\t[LIBRARY MANAGEMENT SYSTEM]\n\n");
- printf("\t\t\t...........................................\n");
- printf("\t\t\t:\t\t[ISSUE BOOKS]\t :\n");
- printf("\t\t\t:.........................................:\n");
- printf("\n\n\n\t\t\t1.Borrow book\n\t\t\t2.View Issued Books\n\t\t\t3.Search Book\n\t\t\t4.Return book\n\t\t\t5.Remove Issued Books\n\t\t\t6.Exit\n\t\t\t7.Go back\n");
- printf("\t\t\tPress (1-6)\n");
- printf(" ..............................................\n");
- switch(_getch()){
- case '1': borrowbook();
- break;
- case '2':viewissuedbook();
- break;
- case '3':searchissue();
- break;
- case '4':returnbook();
- break;
- case '5':delissuebook();
- break;
- case '6': exit(0);
- break;
- case '7':booksection();
- break;
- default:
- printf("\nEnter any key to try again.");
- _getch();
- system("cls");
- mainMenu();
- }
- }
- void borrowbook()
- {
- struct profile g;
- struct books e;
- struct books d;
- char borrow[20];
- int quantity,quantity1,n1;
- FILE *another,*fb;
- FILE *issue;
- int m,k,j,i,n;
- issue=fopen("issuebook.txt","ab");
- another=fopen("frecord.txt","rb");
- fb=fopen("booksection.txt","rb");
- system("cls");
- printf("\t\t\t\t[LIBRARY MANAGEMENT SYSTEM]\n\n");
- printf("\t\t\t...........................................\n");
- printf("\t\t\t:\t\t[BORROW BOOKS]\t :\n");
- printf("\t\t\t:.........................................:\n");
- printf("\t\t\tEnter reader's ID: ");
- scanf("%d",&userid1);
- fflush(stdin);
- while(fread(&g,sizeof(g),1,another)==1)
- {
- if (userid1==g.userID)
- {
- e.userid=userid1;
- m=1;
- }
- }
- if (m!=1)
- {
- printf("\t\t\tNot found");
- _getch();
- issuemain();
- }
- else
- {
- printf("\t\t\tHave you borrowed the book previously?: ");
- scanf("%s",borrow);
- fflush(stdin);
- if (strcmp(borrow,"yes")==0)
- {
- viewissuedbookofuser(userid1);
- printf("\t\t\tHow many books did you borrow?: ");
- while(scanf("%d", &n1)==0) //if scanf failed to scan an integer
- {
- printf("Invalid input. Try again\n");
- int c;
- while((c=getchar())!='\n' && c!=EOF); //clear the stdin
- }
- if (n1>3)
- {
- printf("\t\t\tError! Cant borrow more than 3 books!!");
- _getch();
- issuemain();
- }
- else if (n1==0)
- {
- printf("\t\t\t0 books can't be borrowed!!\n");
- _getch();
- issuemain();
- }
- else
- {
- printf("\t\t\tEnter the number of books you want to borrow: ");
- while(scanf("%d", &quantity)==0) //if scanf failed to scan an integer
- {
- printf("Invalid input. Try again\n");
- int c;
- while((c=getchar())!='\n' && c!=EOF); //clear the stdin
- }
- quantity1=quantity+n1;
- if (quantity==0)
- {
- printf("\t\t\t0 books can't be borrowed!!\n");
- _getch();
- issuemain();
- }
- }
- }
- else if (strcmp(borrow,"no")==0)
- {
- printf("\t\t\tEnter the number of books you want to borrow: ");
- while(scanf("%d", &quantity)==0) //if scanf failed to scan an integer
- {
- printf("\t\t\t\tInvalid input. Try again\n");
- int c;
- while((c=getchar())!='\n' && c!=EOF); //clear the stdin
- }
- quantity1=quantity;
- if (quantity==0)
- {
- printf("\t\t\t0 books can't be borrowed!!\n");
- _getch();
- issuemain();
- }
- }
- else if (1)
- {
- printf("\t\t\tInvalid entry!\n");
- _getch();
- issuemain();
- }
- if (quantity1>0 && quantity1<4)
- {
- e.quantity=quantity;
- start1:
- for (i=0;i<quantity;i++)
- {
- printf("\t\t\tEnter ISBN of the book(5 digits): ");
- scanf("%d", &isbn1); //if scanf failed to scan an integer
- while(fread(&d,sizeof(d),1,fb)==1)
- {
- if (isbn1==d.isbn)
- {
- e.isbn=isbn1;
- k=1;
- }
- }
- if (k!=1)
- {
- printf("\t\t\tBook ISBN not found!!");
- _getch();
- issuemain();
- }
- else if (k==1)
- {
- printf("\t\t\tHow many books of this ISBN do you want to borrow?: ");
- while(scanf("%d", &n)==0) //if scanf failed to scan an integer
- {
- printf("\t\t\tInvalid input. Try again\n");
- int c;
- while((c=getchar())!='\n' && c!=EOF); //clear the stdin
- }
- if (n>d.quantity)
- {
- printf("\t\t\tInvalid entry!!\n");
- _getch();
- issuemain();
- }
- if (n==quantity)
- {
- goto start;
- }
- if (n==1)
- {
- quantity=quantity-1;
- goto start1;
- }
- else{
- printf("\t\t\tInvalid entry!!\n");
- _getch();
- issuemain();
- }
- }
- }
- }
- else
- {
- printf("\t\t\tYou can't have more than three books!!\n");
- _getch();
- issuemain();
- }
- start:
- printf("\t\t\tEnter the issue date:\n ");
- printf("\t\t\t\tEnter day: ");
- scanf("%d",&e.issueday);
- dete:
- if (e.issueday>0 && e.issueday<=30)
- {
- printf("\t\t\t\tEnter month: ");
- scanf("%d",&e.issuemonth);
- fflush(stdin);
- dete2:
- if (e.issuemonth>0 && e.issuemonth<=12)
- {
- printf("\t\t\t\tEnter year: ");
- scanf("%d",&e.issueyear);
- fflush(stdin);
- dete3:
- if (e.issueyear>2018 && e.issueyear <2020)
- {
- e.submitday=e.issueday;
- e.submitmonth=e.issuemonth+1;
- if (e.submitmonth>12)
- {
- e.submityear=e.issueyear+1;
- e.submitmonth=e.submitmonth-12;
- }
- else{
- e.submityear=e.issueyear;
- }
- printf("\t\t\t\tReturn date:%d/ %d/ %d ",e.submitday,e.submitmonth,e.submityear );
- fwrite(&e,sizeof(e),1,issue);
- fclose(issue);
- _getch();
- issuemain();
- }
- else
- {
- printf("\n");
- printf("\t\t\t\tInvalid entry!!\n");
- printf("\t\t\t\tEnter year again: ");
- scanf("%d",&e.issueyear);
- goto dete3;
- }
- }
- else
- {
- printf("\n");
- printf("\t\t\t\tInvalid entry!!\n");
- printf("\t\t\t\tEnter month again: ");
- scanf("%d",&e.issuemonth);
- goto dete2;
- }
- }
- else{
- printf("\n");
- printf("\t\t\t\tInvalid entry!!\n");
- printf("\t\t\t\tEnter day again: ");
- scanf("%d",&e.issueday);
- goto dete;
- }
- }
- fclose(fb);
- fclose(another);
- }
- int viewissuedbookofuser(userid1)
- {
- struct books e;
- FILE *issue;
- issue=fopen("issuebook.txt","rb");
- if (issue==NULL){
- printf("\nERROR OPENING FILE, THE RECORD FILE DOES NOT EXIST!!!");
- getch();
- issuemain();
- }
- while(fread(&e,sizeof(e),1,issue)==1){
- printf("\n\t\t\tUser ID: %d\n\t\t\tBook Quantity: %d\n\t\t\tIssue Date [dd/mm/yy]: %d/ %d/ %d\n\t\t\tReturn Date[dd/mm/yy]: %d/ %d/ %d\n\n",e.userid,e.quantity,e.issueday,e.issuemonth,e.issueyear,e.submitday,e.submitmonth,e.submityear);
- }
- fclose(issue);
- return 0;
- }
- void viewissuedbook()
- {
- struct books e;
- FILE *issue;
- issue=fopen("issuebook.txt","rb");
- system("cls");
- if (issue==NULL){
- printf("\nERROR OPENING FILE, THE RECORD FILE DOES NOT EXIST!!!");
- getch();
- issuemain();
- }
- printf("\t\t\t\t[LIBRARY MANAGEMENT SYSTEM]\n\n");
- printf("\t\t\t..................................................\n");
- printf("\t\t\t:\t\t[LIST ISSUED BOOKS] :\n");
- printf("\t\t\t:................................................:\n");
- while(fread(&e,sizeof(e),1,issue)==1){
- printf("\nUser ID: %d\nBook Quantity: %d\nIssue Date [dd/mm/yy]: %d/ %d/ %d\nReturn Date[dd/mm/yy]: %d/ %d/ %d\n\n",e.userid,e.quantity,e.issueday,e.issuemonth,e.issueyear,e.submitday,e.submitmonth,e.submityear);
- }
- printf("............................................\n");
- fclose(issue);
- printf("\nEnter any key to go back!");
- _getch();
- system("cls");
- issuemain();
- }
- void returnbook()
- {
- struct books e;
- FILE *issue;
- int i,j;
- int quantity,quantity1;
- int day,month,year;
- int fine1;
- issue=fopen("issuebook.txt","rb");
- if (issue==NULL){
- printf("\nERROR OPENING FILE, THE RECORD FILE DOES NOT EXIST!!!");
- getch();
- issuemain();
- }
- system("cls");
- printf("\t\t\t\t[LIBRARY MANAGEMENT SYSTEM]\n\n");
- printf("\t\t\t..................................................\n");
- printf("\t\t\t:\t\t[RETURN BOOKS] :\n");
- printf("\t\t\t:................................................:\n");
- printf("\t\t\tEnter USER ID: ");
- scanf("%d",&userid1);
- while(fread(&e,sizeof(e),1,issue)==1){
- if (userid1==e.userid)
- {
- i=1;
- }
- }
- if (i==1)
- {
- printf("\n\t\t\t\tBook Quantity: %d\n\t\t\t\tIssue Date [dd/mm/yy]: %d/ %d/ %d\n\t\t\t\tReturn Date[dd/mm/yy]: %d/ %d/ %d\n\n",e.quantity,e.issueday,e.issuemonth,e.issueyear,e.submitday,e.submitmonth,e.submityear);
- printf("\t\t\t\tEnter the quantity of book returned: ");
- while(scanf("%d", &quantity)==0) //if scanf failed to scan an integer
- {
- printf("\t\t\t\tInvalid input. Try again\n");
- int c;
- while((c=getchar())!='\n' && c!=EOF); //clear the stdin
- }
- if (quantity<e.quantity)
- {
- quantity1=e.quantity-quantity;
- printf("\t\t\t\t%d books not returned!!\n",quantity1);
- quantity=quantity1*200;
- goto start;
- }
- else if (quantity==e.quantity)
- {
- printf("\t\t\t\tAll the books are returned!!\n");
- quantity=0;
- goto start;
- }
- else if (quantity>e.quantity)
- {
- printf("\t\t\t\tInvalid quantity!!\n");
- _getch();
- issuemain();
- }
- start:
- printf("\t\t\t\tEnter the date on which the user returned the book:\n");
- printf("\t\t\t\tEnter day: ");
- scanf("%d",&day);
- dete:
- if (day>0 && day<=30)
- {
- printf("\t\t\t\tEnter month: ");
- scanf("%d",&month);
- fflush(stdin);
- if (e.submitmonth==12)
- {
- month=12+month;
- goto start1;
- }
- dete2:
- if (month>0 && month<=12)
- {
- printf("\t\t\t\tEnter year: ");
- scanf("%d",&year);
- fflush(stdin);
- dete3:
- if (year>2018 && day<2021)
- {
- if (((month==e.issuemonth)||(month==e.submitmonth))&&((year==e.issueyear)||(year==e.submityear)))
- {
- printf("\t\t\t\tBook is returned on time!!\n");
- _getch();
- issuemain();
- }
- start1:
- if ((month>e.submitmonth)||(year>e.submityear))
- {
- j=day-e.submitday;
- year=year-e.submityear;
- day=365*year;
- month=month-e.submitmonth;
- day=day+30*month+j;
- fine1=2*day+quantity;
- printf("\t\t\t\tThe user has to pay Rs %d.",fine1);
- _getch();
- issuemain();
- }
- }
- else
- {
- printf("\n");
- printf("\t\t\t\tInvalid entry!!\n");
- printf("\t\t\t\tEnter year again: ");
- scanf("%d",&year);
- goto dete3;
- }
- }
- else
- {
- printf("\n");
- printf("\t\t\t\tInvalid entry!!\n");
- printf("\t\t\t\tEnter month again: ");
- scanf("%d",&month);
- goto dete2;
- }
- }
- else{
- printf("\n");
- printf("\t\t\t\tInvalid entry!!\n");
- printf("\t\t\t\tEnter day again: ");
- scanf("%d",&day);
- goto dete;
- }
- }
- else
- {
- printf("\t\t\tUser not found!\n");
- _getch();
- issuemain();
- }
- fclose(issue);
- }
- void searchissue(){
- int id;
- int de,c;
- struct books e;
- FILE *issue;
- int i,j;
- int quantity,quantity1;
- int day,month,year;
- int fine1;
- issue=fopen("issuebook.txt","rb");
- if (issue==NULL){
- printf("\nERROR OPENING FILE, THE RECORD FILE DOES NOT EXIST!!!");
- getch();
- issuemain();
- }
- system("cls");
- printf("\t\t\t\t[LIBRARY MANAGEMENT SYSTEM]\n\n");
- printf("\t\t\t...........................................\n");
- printf("\t\t\t:\t\t[SEARCH USER]\t :\n");
- printf("\t\t\t:.........................................:\n\n");
- printf("\t\t\tEnter Users ID to search: ");
- scanf("%d",&id);
- printf("\n\n");
- fflush(stdin);
- printf("\n");
- while (fread(&e,sizeof(e),1,issue)==1)
- {
- if (id==e.userid){
- printf("\n\t\t\t\tBook Quantity: %d\n\t\t\t\tIssue Date [dd/mm/yy]: %d/ %d/ %d\n\t\t\t\tReturn Date[dd/mm/yy]: %d/ %d/ %d\n\n",e.quantity,e.issueday,e.issuemonth,e.issueyear,e.submitday,e.submitmonth,e.submityear);
- de=1;
- }
- }
- if (de==1)
- {
- printf("\n\n");
- printf("Would you like to search another user?[y/n]: ");
- research:
- c=_getch();
- if (c=='y')
- {
- searchuser();
- }
- if (c=='n')
- {
- printf("\n\n");
- printf("\n\nEnter any key to go back!");
- _getch();
- system("cls");
- mainMenu();
- }
- }
- if (de!=1)
- {
- printf("\t\t\t\t\t*INVALID USER*");
- printf("\n\nEnter any key to go back!");
- _getch();
- system("cls");
- mainMenu();
- }
- fclose(issue);
- }
- void delissuebook(){
- char m[20];
- char bname[20];
- int brecordExists;
- long long int bid;
- system("cls");
- fflush(stdin);
- struct books e;
- FILE *fb;
- FILE *fbtemp;
- fb=fopen("issuebook.txt","r");
- fbtemp = fopen("fbtempissue.txt","w");
- printf("\t\t\t\t[LIBRARY MANAGEMENT SYSTEM]\n\n");
- printf("\t\t\t...........................................\n");
- printf("\t\t\t:\t\t[DELETE BOOK]\t :\n");
- printf("\t\t\t:.........................................:\n\n");
- printf("\t\t\tEnter UserID to delete: ");
- scanf("%lld",&bid);
- fflush(stdin);
- printf("\n");
- while (fread( &e, sizeof(e), 1, fb) == 1) {
- if (bid!=e.userid)
- fwrite(&e, sizeof(e), 1, fbtemp);
- if (bid==e.userid)
- brecordExists = 1;
- }
- fclose(fb);
- fclose(fbtemp);
- if(brecordExists!=1){
- printf("\t\t\tThe user does not exist!");
- }else{
- remove("issuebook.txt");
- rename("fbtempissue.txt", "issuebook.txt");
- printf("\t\tRECORD DELETED SUCCESSFULLY.");
- }
- printf("\n\n");
- printf("\t\t\tEnter <main> to go to the main menu or press any key to go back: ");
- scanf("%s",m);
- if (strcmp(m,"main")==0)
- {
- system("cls");
- issuemain();
- }
- else if (1)
- {
- system("cls");
- issuemain();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement