0% found this document useful (0 votes)
25 views11 pages

Library Manage Ment System

This document contains code for a C program that implements a basic library management system using file handling. The program allows the user to perform operations like adding and deleting book records, viewing all records, searching for a specific book, and calculating late return fines. The code includes functions for initializing a menu, adding/deleting/viewing records, searching by ID, and calculating fines based on return date and due days. Sample outputs are provided for adding data, deleting a record, displaying all data, and calculating fines.

Uploaded by

Anurag Gautam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views11 pages

Library Manage Ment System

This document contains code for a C program that implements a basic library management system using file handling. The program allows the user to perform operations like adding and deleting book records, viewing all records, searching for a specific book, and calculating late return fines. The code includes functions for initializing a menu, adding/deleting/viewing records, searching by ID, and calculating fines based on return date and due days. Sample outputs are provided for adding data, deleting a record, displaying all data, and calculating fines.

Uploaded by

Anurag Gautam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

CSB 202: DATABASE MANAGEMENT SYSTEM

Submitted By:
Name: Anurag Gautam

Roll No: 211210013


Branch: CSE (3rd sem)
(DEPARTMENT OF COMPUTER SCIENCE
AND ENGINEERING)

Submitted To: Dr. Shelly Sachdeva


Lab assignment :1

NATIONAL INSTITUTE OF TECNOLOGY


DELHI
Project on library management
system based on file handling

Content:
 Problem Statement
 Input Code
 Output Code

PROBLEM STATEMENT
Write a menu-driven program in C that uses a file to store the above-
mentioned component of library management system and perform
the listed operations.
• To display all the records in the system.
• To add/drop record from the system.
• Search any book within the system. i• Fine calculation if book is
deposited after due date.

1.input Code
#include<stdio.h>
#include<stdlib.h>
typedef struct date
{
 int dd;
 int mm;
 int yyyy;
} date;
struct bookinfo
{
 int bookid;
 char bookname[50];
 char authorname[50];
 char studentname[50];
 date issuedate;
 date returndate;
 int duedays;
 int fine;
};
int initialization()
{
 int i;
 for (int i=0; i<50; i++)
 {
 printf("*-");
 }
 printf("*\n");
 printf("\t\t\t\tLibrary Database Management System\n");
 for (int i=0; i<50; i++)
 {
 printf("*-");
 }
 printf("*\n");
 menu();
 }
int menu()
{
 int i;
printf("\n");
 printf("Press any key to continue\n");
 fflush(stdin);
getchar();
printf("\t\t\t\tEnter your choice to proceed further\n");
 printf("\t\t 1-Add Records\n\t\t 2-View Records\n\t\t 3-Delete Records\n\t\t
4-SearchRecords\n\t\t 5-Evaluate Fine\n\t \t 0-Exit");
 getchar();
printf("Your choice:");
scanf("%d",&i);
 printf("Your choice is %d\n",i);
 switch(i)
 {
case 0:
 exitcord();
 break;
 case 1:
 addrecord();
 break;
 case 2:
 viewrecords();
 break;
 case 3:
 deleterecords();
 break;
 case 4:
 searchrecord();
 break;
 case 5:
 finecalculator();
 break;
 }
}
int addrecord()
{
 FILE *ptr;
 ptr = fopen("Database.bin","ab+");
 int days;
struct bookinfo book= {0};
printf("\n\n Enter Book ID\n");
 scanf("%d", &book.bookid);
 printf("Enter Book name\n ");
fflush(stdin);
 gets(book.bookname);
 printf("Enter Author Name\n ");
 gets(book.authorname);
 printf("Enter Student Name\n");
 gets(book.studentname);
 printf("Enter Issue date\n");
 scanf("%d/%d/%d",
&book.issuedate.dd,&book.issuedate.mm,&book.issuedate.yyyy);
 printf("Enter Return date\n");
 scanf("%d/%d/%d",
&book.returndate.dd,&book.returndate.mm,&book.returndate.yyyy);
 fwrite(&book, sizeof(book), 1, ptr);
 menu();
}
int deleterecords()
{
 int deltbookid;
 struct bookinfo book= {0};
 int found=0;
 FILE *ptr;
 FILE *tmpfileptr;
 ptr= fopen("Database.bin","rb");
 tmpfileptr=fopen("tmpdata.bin","wb");
 printf("Enter the book ID to be deleted:");
 scanf("%d", &deltbookid);
 fflush(stdin);
 while(fread(&book, sizeof(book), 1, ptr))
 {
 if(deltbookid!= book.bookid)
 {
 fwrite(&book, sizeof(book), 1, tmpfileptr);
 }
 else
 {
 found=1;
 }
 }
 (found) ? printf("record deleted"): printf("No record found");
 fclose(ptr);
 fclose(tmpfileptr);
 remove("Database.bin");
 rename("tmpdata.bin","Database.bin");
 menu();
}
int viewrecords()
{
 FILE *ptr;
 ptr = fopen("Database.bin","rb");
 struct bookinfo book= {0};
 while(fread(&book, sizeof(book), 1, ptr))
 {
 printf("\n");
 printf("Book ID: %d\n", book.bookid);
 printf("Book Name : %s\n",book.bookname);
 printf("Author Name : %s\n", book.authorname);
 printf("Student Name : %s\n",book.studentname);
 printf("Issue Date :%d/%d/%d\
n",book.issuedate.dd,book.issuedate.mm,book.issuedate.yyyy );
 printf("Return Date :%d/%d/%d\
n",book.returndate.dd,book.returndate.mm,book.returndate.yyyy);
 printf("\n");
 }
 menu();
}
int searchrecord()
{
 struct bookinfo book= {0};
int id;
 FILE *ptr;
 ptr= fopen ("Database.bin","rb");
 printf("Enter the Book ID you want to search");
scanf("%d", & id);
 int found=0;
while(fread(&book, sizeof(book), 1, ptr))
 {
 if(book.bookid== id)
 {
 printf("\n");
 printf("Book ID: %d\n", book.bookid);
 printf("Book Name : %s\n",book.bookname);
 printf("Author Name : %s\n", book.authorname);
 printf("Student Name : %s\n",book.studentname);
 printf("Issue date : %d/%d/%d\
n",book.issuedate.dd,book.issuedate.mm,book.issuedate.yyyy );
 printf("Return date : %d/%d/%d\
n",book.returndate.dd,book.returndate.mm,book.returndate.yyyy);
 printf("\n");
 found=1;
 }
 }
 (found)? printf("\n"): printf("BookID not available");
 menu();
}
int finecalculator()
{
 FILE *ptr;
 ptr= fopen("Database.bin", "rb");
 struct bookinfo book= {0};
 int id, found=0;
 int duedays;
 int fine, fineamt;
 printf("Enter the fine amt per day:\n");
 scanf("%d", &fineamt);
 fflush(stdin);
 printf("Enter the book ID\n");
 scanf("%d", &id);
 printf("Enter the due days:\n");
 scanf("%d", &duedays);
 while(fread(&book, sizeof(book), 1, ptr))
 {
 if(book.bookid== id)
 {
 fine =fineamt* duedays;
 printf("\n");
 printf("Book ID: %d\n", book.bookid);
 printf("Book Name : %s\n",book.bookname);
 printf ("Author Name : %s \n", book.authorname);
 printf ("Student Name : %s\n",book.studentname);
 printf ("Issue date : %d/%d/%d\
n",book.issuedate.dd,book.issuedate.mm,book.issuedate.yyyy );
 printf("Return date : %d/%d/%d\
n",book.returndate.dd,book.returndate.mm,book.returndate.yyyy);
 printf("\n");
 printf("Fine: %d",fine);
 found=1;
 }
 }
 (found)? printf("\n"): printf("BookID not available");
 menu();
}
int exitcord()
{
 int i;
for (int i=0; i<100; i++)
 {
 printf("#");
 }
 printf("#\n");
 printf("\t\t\t\t\t\tThank You!\n");
 for (int i=0; i<100; i++)
 {
 printf(".");
 }
 printf(".\n");
}
int main()
{
 initialization();
return 0;
}
3.Output Code
1.Add data

2.Delete record
3.Display Data
4.fine calculation

5.Search Book
*******THANKYOU*****
*

You might also like