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
- {
- char yourname[40];
- char bookname[40];
- int issuemonth;
- long long int day,month,year;
- int issueday;
- int issueyear;
- int bookID;
- int submitmonth;
- int submitday;
- int submityear;
- };
- //Functions List
- void mainMenu();
- void adduser();
- void deluser();
- void edituser();
- void listuser();
- void searchuser();
- void adminlogin();
- void booksection();
- void addbook();
- void listbook();
- void searchbook();
- void delbook();
- void editbook();
- void issuebook();
- //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..............................................\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(50);
- 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...........................................\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;
- int i,g,j;
- FILE *f;
- f=fopen("frecord.txt","ab");
- system("cls");
- 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)
- {
- 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: ");
- scanf("%d",&b.userID);
- fflush(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;
- }
- printf(" ............................................\n");
- fwrite(&b, sizeof(b), 1, f);
- fclose(f);
- 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 b;
- FILE *f;
- f=fopen("frecord.txt","rb"); //binary read mode
- system("cls");
- if (f==NULL){
- printf("\nERROR OPENING FILE, THE RECORD FILE DOES NOT EXIST!!!");
- getch();
- mainMenu();
- }
- printf("\t\t\t..................................................\n");
- printf("\t\t\t:\t\t[LIST USERS PROFILE] :\n");
- printf("\t\t\t:................................................:\n");
- while(fread(&b,sizeof(b),1,f)==1){
- printf("\nName: %s\nAddress: %s\nMobile no: %lld\nUser ID: %d\n\n",b.name,b.address,b.phoneNumber,b.userID);
- }
- printf("............................................\n");
- fclose(f);
- printf("\nEnter any key to go back!");
- _getch();
- system("cls");
- mainMenu();
- }
- //Editing profile
- void edituser(){
- int id;
- int found;
- int e,j;
- printf(" ............................................\n");
- printf("\t\t\t\t\t [EDIT USER]\n\n");
- struct profile b;
- FILE *fp;
- FILE *ftemp;
- fp = fopen("frecord.txt","rb");
- ftemp = fopen("ftemprecord.txt","wb");
- system("cls");
- 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: ");
- scanf("%d",&b.userID);
- fflush(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\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();
- }
- else if(1)
- {
- goto research;
- }
- }
- 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","r");
- ftemp = fopen("ftemprecord.txt","w");
- 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.............................................\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.Search Book\n\t\t\t4.Delete book\n\t\t\t5.Edit 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 '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");
- 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\tEnter the name of the book to be added: ");
- scanf("%s",d.bookname);
- fflush(stdin);
- printf("\t\t\t\tEnter issue date(dd/mm/yy):\n");
- printf("\t\t\t\tEnter day: ");
- scanf("%lld",&d.day);
- dete:
- if (d.day>=0 && d.day<=32)
- {
- printf("\t\t\t\tEnter month: ");
- scanf("%lld",&d.month);
- fflush(stdin);
- dete2:
- if (d.month>=0 && d.month<=12)
- {
- printf("\t\t\t\tEnter year: ");
- scanf("%lld",&d.year);
- fflush(stdin);
- dete3:
- if (d.year>2018 && d.day<2020)
- {
- printf("\t\t\t\tEnter Book Id:");
- scanf("%d",&d.bookID);
- }
- else
- {
- printf("\n");
- printf("\t\t\t\tInvalid entry!!\n");
- printf("\t\t\t\tEnter year again: ");
- scanf("%lld",&d.year);
- goto dete3;
- }
- }
- else
- {
- printf("\n");
- printf("\t\t\t\tInvalid entry!!\n");
- printf("\t\t\t\tEnter month again: ");
- scanf("%lld",&d.month);
- goto dete2;
- }
- }
- else{
- printf("\n");
- printf("\t\t\t\tInvalid entry!!\n");
- printf("\t\t\t\tEnter day again: ");
- scanf("%lld",&d.day);
- 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","r"); //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("\nBook Name: %s\nIssue date: %lld/ %lld/ %lld\nBook ID: %d\n\n",d.bookname,d.day,d.month,d.year,d.bookID);
- }
- printf("............................................\n");
- fclose(fb);
- printf("\nEnter any key to go back!");
- _getch();
- system("cls");
- booksection();
- }
- //edit book information
- void editbook(){
- char m[20];
- int bookid;
- int bfound;
- int be;
- printf(" ............................................\n");
- printf("\t\t\t\t\t [EDIT BOOK]\n\n");
- struct books d;
- FILE *fb;
- FILE *fbtemp;
- fb=fopen("booksection.txt","r"); //binary read mode
- fbtemp = fopen("fbtemprecord.txt","w");
- system("cls");
- printf("\t\t\tEnter BOOK ID to modify: ");
- scanf("%d",&bookid);
- fflush(stdin);
- printf("\n");
- while(fread(&d,sizeof(d),1,fb)==1){
- if(bookid!=d.bookID)
- fwrite(&d,sizeof(d),1,fbtemp);
- if(bookid==d.bookID){
- bfound = 1;
- }
- }
- if (bfound == 1){
- printf("\t\t\tEnter the name of the book to be added: ");
- scanf("%s",d.bookname);
- fflush(stdin);
- printf("\t\t\t\tEnter date(dd/mm/yy):\n");
- printf("\t\t\t\tEnter day: ");
- scanf("%lld",&d.day);
- dete:
- if (d.day>=0 && d.day<=32)
- {
- printf("\t\t\t\tEnter month: ");
- scanf("%lld",&d.month);
- fflush(stdin);
- dete2:
- if (d.month>=0 && d.month<=12)
- {
- printf("\t\t\t\tEnter year: ");
- scanf("%lld",&d.year);
- fflush(stdin);
- dete3:
- if (d.year>2018 && d.year <2020)
- {
- printf("\t\t\t\tEnter Book Id:");
- scanf("%d",&d.bookID);
- }
- else
- {
- printf("\n");
- printf("\t\t\t\tInvalid entry!!\n");
- printf("\t\t\t\tEnter year again: ");
- scanf("%lld",&d.year);
- goto dete3;
- }
- }
- else
- {
- printf("\n");
- printf("\t\t\t\tInvalid entry!!\n");
- printf("\t\t\t\tEnter month again: ");
- scanf("%lld",&d.month);
- goto dete2;
- }
- }
- else{
- printf("\n");
- printf("\t\t\t\tInvalid entry!!\n");
- printf("\t\t\t\tEnter day again: ");
- scanf("%lld",&d.day);
- 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];
- int bid;
- int bde,bc;
- struct books d;
- FILE *fb;
- fb=fopen("booksection.txt","r");
- system("cls");
- printf("\t\t\t\t LIBRARY MANAGEMENT SYSTEM\n\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\tEnter BOOK ID to search: ");
- scanf("%d",&bid);
- printf("\n\n");
- fflush(stdin);
- printf("\n");
- while (fread(&d,sizeof(d),1,fb)==1)
- {
- if (bid==d.bookID){
- printf("\n[%s Book Info]\n",d.bookname);
- printf("\nBook Name: %s\nDate(dd/mm/yy): %lld/ %lld/ %lld\nBook ID: %d\n\n",d.bookname,d.day,d.month,d.year,d.bookID);
- bde=1;
- }
- }
- if (bde==1)
- {
- printf("\n\n");
- printf("Would you like to search another book?[y/n]: ");
- research:
- bc=_getch();
- if (bc=='y')
- {
- searchuser();
- }
- 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 ID*");
- 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,bid;
- system("cls");
- fflush(stdin);
- struct books d;
- FILE *fb;
- FILE *fbtemp;
- fb=fopen("booksection.txt","r");
- fbtemp = fopen("fbtemprecord.txt","w");
- 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 ID to delete: ");
- scanf("%d",&bid);
- fflush(stdin);
- printf("\n");
- while (fread( &d, sizeof(d), 1, fb) == 1) {
- if (bid!=d.bookID)
- fwrite(&d, sizeof(d), 1, fbtemp);
- if (bid==d.bookID)
- 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();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement