Page

Library Management System In C/C++

#include<stdio.h>
#include<conio.h>
#include<dos.h>
#include<string.h>
#include<graphics.h>
#include<stdlib.h>
void view();
void menu();
void add();
void list();
void issue();
void list_issued();
void main()
{
clrscr();
view();
setcolor(8);
setbkcolor(4);
settextstyle(1,0,4);
outtextxy(120,120,"Library Management System");
outtextxy(60,200,"Developed by sourcecodernp.blogspot.com");
outtextxy(150,300,"Please Wait a Movement");
delay(5000);
menu();
getch();
}
void view()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"..\\bgi");
}
void menu()
{
int ch;
clrscr();
view();
setbkcolor(4);
gotoxy(30,10);
printf("Main Menu");
gotoxy(30,12);
printf("1.Add New Records");
gotoxy(30,13);
printf("2.List of Books");
gotoxy(30,14);
printf("3.Book Issued");
gotoxy(30,15);
printf("4.List of issued book");
gotoxy(30,16);
printf("5.Search Book");
gotoxy(30,17);
printf("6.Exit");
gotoxy(30,18);
printf("Enter Your Choice");
scanf("%d",&ch);
switch(ch)
{
case 1:
add();
break;
case 2:
list();
break;
case 3:
issue();
break;
case 4:
list_issued();
break;
case 5:
printf("under construction");
break;
case 6:
exit(0);
break;
default:
menu();
break;
}
}
void add()
{
int another;
FILE *fp;
struct book
{
char book_name[40];
char author_name[40];
int book_id;
int stock;
};
struct book b;
clrscr();
view();
setbkcolor(4);
fp=fopen("book.dat","ab");
if(fp==NULL)
{
printf("File Cannot Open");
}
fseek(fp,0,SEEK_END);
another='Y';
while(another=='Y')
{
printf("\n\nEnter Book Id:");
scanf("%d",&b.book_id);
printf("\n\nEnter Book name:");
scanf("%s",b.book_name);
printf("\n\nAuthor Name:");
scanf("%s",b.author_name);
printf("\n\nStock In hand:");
scanf("%d",&b.stock);
fwrite(&b,sizeof(b),1,fp);
printf("\n\nRecords is Update");
printf("\n\nAdd Another Record(Y/N):");
fflush(stdin);
another=getche();
}
fclose(fp);
menu();
}
void list()
{
FILE *fp;
struct book
{
char book_name[40];
char author_name[40];
int book_id;
int stock;
};
struct book b;
clrscr();
view();
setbkcolor(4);
gotoxy(1,1);
printf("Book Id");
gotoxy(15,1);
printf("Book Name");
gotoxy(27,1);
printf("Author Name");
gotoxy(45,1);
printf("Stock");
fp=fopen("book.dat","rb");
if(fp==NULL)
{
printf("\n\nError-File Cannot Open");
}
rewind(fp);
while(fread(&b,sizeof(b),1,fp)==1)
{
printf("\n\n%d",b.book_id);
printf("\t\t%s",b.book_name);
printf("\t\t%s",b.author_name);
printf("\t\t%d",b.stock);
}
fclose(fp);
}
void issue()
{
char anothor='Y';
struct issue
{
char i_date;
char r_date;
int reg_no;
int book_id;
};
struct issue s;
FILE *ft;
clrscr();
view();
setbkcolor(4);
ft=fopen("issue","ab");
if(ft==NULL)
{
printf("\nFile Cannot open");
}
while(anothor=='Y')
{
printf("Enter Registration no:");
scanf("%d",&s.reg_no);
printf("Enter Book Id");
scanf("%d",&s.book_id);
printf("\Enter Issued Date:");
scanf("%s",s.i_date);
printf("Enter Return Date:");
scanf("%s",s.r_date);
fwrite(&s,sizeof(s),1,ft);
printf("\n\nRecords Updated");
printf("\n\nYou Wnat to another Record(Y/N):");
fflush(stdin);
anothor=getche();
}
}
void list_issued()
{
clrscr();
printf("Under construction");
}

No comments:

Post a Comment