Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <time.h>
- void printAll();
- int search();
- void issue(int, int);
- void returner(int,int);
- void reserve(int, int);
- void returner(int ,int);
- void add_new_book(int);
- int number_of_books();
- int student[1000];
- int rno;
- int number_of_books();
- struct library_records{
- char name[100];
- char author[100];
- int reserved;
- int issued;
- int no;
- //char date[1000][8];
- // int student[1000];
- int taker;
- int reserved_by;
- } record[1000];
- void main()
- {
- char again;
- do
- {
- int temp;
- printf("\nWhat would you like to do?");
- printf("\n1. Add new book. ");
- printf("\n2. Issue a book. ");
- printf("\n3. Return a book. ");
- printf("\n4. View all Books in Library.\n");
- int ch;
- scanf("%d", &ch);
- switch(ch)
- {
- case 1:
- add_new_book(number_of_books());
- break;
- case 2:
- printf("\n Enter Roll no.");
- scanf("%d",&rno);
- printf("Roll number: %d",rno);
- int temp1 = search();
- if(temp1>=0)
- {
- issue(temp1,rno);
- }
- break;
- case 3:
- printf("\n Enter book number: ");
- scanf("%d",&temp);
- printf("\n Enter Roll no.");
- scanf("%d",&rno);
- returner(temp,rno);
- break;
- case 4:
- printAll();
- break;
- default:
- printf("\n Try Again");
- }
- printf("\n\nWould you like to go again?[y/n]");
- scanf(" %c", &again);
- }while(again == 'y');
- }
- void printAll(){
- int i=0;
- while(i<number_of_books())
- {
- printf("\n %d. %s by %s",i+1,record[i].name,record[i].author);
- if(record[i].issued)
- {
- printf("\tIssued\t");
- if(record[i].reserved)
- {
- printf("Reserved");
- }
- else
- {
- printf("not Reserved");
- }
- }
- else
- {
- printf("\tnot Issued");
- }
- i++;
- }
- printf("\n");
- }
- int search()
- {
- char str[100];
- int n;
- // bool found = false;
- int i=0;
- printf("\nSelect search criteria: ");
- printf("\n1. Book Name.");
- printf("\n2. Author name. ");
- printf("\n3. Book number.\n");
- int ch;
- scanf("%d", &ch);
- switch(ch)
- {
- case 1:
- printf("\n Enter Book name:");
- //fgets(str,100, stdin);
- scanf("%s",&str);
- while(strcmp(record[i].name,""))
- {
- if(strcmp(record[i].name,str) == 0)
- return i;
- i++;
- }
- printf("Book doesn't exist. Try another one\n");
- //search();
- return -1;
- break;
- case 2:
- printf("\n Enter Author's name: ");
- // gets(str);
- scanf("%s",&str);
- while(strcmp(record[i].author,""))// != '\0')
- {
- if(strcmp(record[i].author,str) == 0)
- {
- return i;
- }
- i++;
- }
- printf("Book doesn't exist. Try another one\n");
- //search();
- return -1;
- break;
- case 3:
- printf("\n Enter Book Number: ");
- scanf("%d",&n);
- if(n-1< number_of_books())
- return n-1;
- else
- {
- printf("Book doesn't exist. Try another one");
- }
- break;
- default:
- printf("\n Make a proper Selection. Returning to Main Menu");
- // return -1;
- }
- return -1;
- }
- void issue(int n, int s)
- {
- if(!record[n].issued && !student[s])
- {
- record[n].issued = 1;
- record[n].taker = s;
- student[s] = 1;
- printf("Book no. %d: %s by author %s is being issued to Student %d",record[n].no+1,record[n].name,record[n].author, record[n].taker);
- }
- else if(!record[n].issued)
- {
- printf("Student needs to return pending books before issuing new ones!");
- }
- else
- reserve(n,s);
- }
- void reserve(int n, int s)
- {
- char ch;
- printf("\n The book you would like to Issue has already been issued to Someone else, would you like to: ");
- printf("1. reserve it? [y/n]");
- scanf(" %c", &ch);
- //int *p;
- if(ch == 'Y' || ch == 'y')
- {
- if(!record[n].reserved)
- {
- record[n].reserved = 1;
- record[n].reserved_by =s;
- printf("Book number %d successfully reserved by Student %d", record[n].no+1,record[n].reserved_by);
- }
- else
- printf("\n The book has already been reserved. Please Try another book");
- }
- else
- {
- if(!record[n].reserved)
- printf("You can try to claim it again later"); // %s", return_date(date[n]));
- else
- printf("This book has been reserved by someone else after the first issues, Try agan later");
- }
- }
- void returner(int x,int s)
- {
- int n = x-1;
- if(record[n].issued)
- {
- if(record[n].taker == s)
- {
- printf("Book no. %d: %s by %s has been successfully returned by %d",x,record[n].name, record[n].author,record[n].taker);
- student[s] = 0;
- if(!record[n].reserved)
- record[n].issued = 0;
- else
- {
- record[n].reserved=0;
- record[n].taker = record[n].reserved_by;
- student[record[n].reserved_by] = 1;
- }
- }
- else{
- printf("Invalid info.");
- }
- }
- else{
- printf("Wrong book number.");
- }
- }
- //char[8] availabilty
- void add_new_book(int n)
- {
- printf("\nPlease Enter the book's name: ");
- scanf("%s",&record[n].name);
- // scanf("%s", &name[n]);
- printf("Book's name is %s", record[n].name);
- printf("\nPlease Enter the book's Author's name: ");
- scanf("%s", record[n].author);
- // scanf("%s", author[n]);
- printf("Book's Author's name is %s", record[n].author);
- record[n].reserved = 0;
- record[n].issued = 0;
- record[n].no = n;
- }
- int number_of_books()
- {
- int x = 0;
- int i = 0;
- while(strcmp(record[i].name,"") != 0) // != '\0')
- {
- x++;
- i++;
- }
- // printf("No. of books in the library are: %d",x);
- return x;
- }
Add Comment
Please, Sign In to add comment