Vous êtes sur la page 1sur 11

/* LIBRARY MANAGEMENT SYSTEM

SOURCE CODE IN C++ */


#include<conio.h>
#include<string.h>
#include<stdio.h>
#include<iostream.h>
#include<process.h>
#include<fstream.h>
#include<dos.h>
//design function declaration//
int design();
//This class define the member variable and member function//
class library
{
char title[20], author[30],publisher[30];
char mem_name[40],mem_address[50];
int mem_code,access_code,sub_code,issue_flag;
public:
library()
{
mem_code=0;
access_code=0;
sub_code=0;
issue_flag=0;
}
void get_book_info();
void get_member();
void book_display();
void member_display();
int get_sub_code();
int get_mem_code();
void issue_book();
void issue_book_display();
void return_book();
void return_book_display();
}book;
//Definition of get_book_info function.It accepts the detail about books//
void library::get_book_info()
{
clrscr();
fstream file;
file.open("test.dat",ios::out|ios::app);
file.seekg(0);
int code=book.get_sub_code();
code++;
cout<<" É============================================»\n";
cout<<" ºENTER DETAIL ABOUT BOOK IN THE LIBRARY FILE º\n";
cout<<" È============================================¼";
gotoxy(26,9);
cout<<"THE SUBJECT CODE ->"<<code;
book.sub_code=code;
gotoxy(26,11);
cout<<"ENTER BOOK TITLE ->";
gets(title);
gotoxy(26,13);
cout<<"ENTER AUTHOR NAME ->";
gets(author);
file.write((char *)&book,sizeof(book));
file.close();
}
//This function display the detail about books in the library//
void library::book_display()
{
gotoxy(2,3);
cout<<"SUBJECT CODE";
gotoxy(2,4);
cout<<"--------------------------------------------------------------";
gotoxy(20,3);
cout<<"TITLE";
gotoxy(50,3);
cout<<"AUTHOR NAME";
int y=5;
fstream file;
file.open("test.dat",ios::in);
file.seekg(0);
file.read((char *)&book,sizeof(book));
if(book.sub_code>0)
{
while(!file.eof())
{
gotoxy(3,y);
cout<<book.sub_code;
gotoxy(21,y);
cout<<book.title;
gotoxy(51,y);
cout<<book.author;
y=y+2;
if(y>23)
{
y=5;
getch();
clrscr();
gotoxy(2,3);
cout<<"SUBJECT CODE";
gotoxy(2,4);
cout<<"--------------------------------------------------------------";
gotoxy(20,3);
cout<<"TITLE";
gotoxy(50,3);
cout<<"AUTHOR NAME";
}
file.read((char *)&book,sizeof(book));
}
}
file.close();
}
// Automatic generation of subject code//
int library::get_sub_code()
{
int temp=0;
fstream file;
file.open("test.dat",ios::in);
file.seekg(0);
file.read((char *)&book,sizeof(book));
while(!file.eof())
{
temp=book.sub_code;
file.read((char *)&book,sizeof(book));
}
return temp;
}
// Automatic generation of member code//
int library::get_mem_code()
{
int temp=0;
fstream file;
file.open("member.dat",ios::in);
file.seekg(0);
file.read((char *)&book,sizeof(book));
while(!file.eof())
{
temp=book.mem_code;
file.read((char *)&book,sizeof(book));
}
return temp;
}
//This function accepts the detail about member//
void library::get_member()
{
fstream file;
file.open("member.dat",ios::out|ios::app);
file.seekg(0);
int code=book.get_mem_code();
code++;
book.mem_code=code;
cout<<" É===============================================»\n";
cout<<" ºENTER DETAIL ABOUT MEMBERS IN THE LIBRARY FILE º\n";
cout<<" È===============================================¼";
gotoxy(20,11);
cout<<"ENTER MEMEBER NAME FOR CODE ["<<code<<"]->";
gets(mem_name);
gotoxy(20,13);
cout<<"ENTER MEMBER ADDRESS->";
gets(mem_address);
file.write((char *)&book,sizeof(book));
file.close();
}
//Display the detail about member//
void library::member_display()
{
gotoxy(2,3);
cout<<"MEMBER CODE";
gotoxy(2,4);
cout<<"--------------------------------------------------------------------
-";
gotoxy(15,3);
cout<<"NAME";
gotoxy(40,3);
cout<<"ADDRESS";
int y=5;
fstream file;
file.open("member.dat",ios::in);
file.seekg(0);
file.read((char *)&book,sizeof(book));
if(book.mem_code>0)
{
while(!file.eof())
{
gotoxy(3,y);
cout<<book.mem_code;
gotoxy(16,y);
cout<<book.mem_name;
gotoxy(41,y);
cout<<book.mem_address;
y=y+2;
if(y>23)
{ y=5;
getch();
clrscr();
gotoxy(2,3);
cout<<"MEMBER CODE";
gotoxy(2,4);
cout<<"-------------------------------------------------------------------
--";
gotoxy(15,3);
cout<<"NAME";
gotoxy(40,3);
cout<<"ADDRESS";
}
file.read((char *)&book,sizeof(book));
} }
file.close();
}
//This function accepts the detail for issue the books//
void library::issue_book()
{
int no,code,flag1=0,flag2=0;
fstream file,ofile,myfile;
file.open("member.dat",ios::in|ios::app);
file.seekg(0);
myfile.open("issue.dat",ios::in|ios::app);
myfile.seekg(0);
cout<<" É============================================»\n";
cout<<" º ENTER DETAIL FOR ISSUE THE BOOK º\n";
cout<<" È============================================¼";
gotoxy(26,9);
cout<<"ENTER YOUR MEMBER CODE->";
cin>>no;
file.read((char *)&book,sizeof(book));
while(!file.eof())
{
if(no==book.mem_code)
{
flag1=1;
myfile.read((char *)&book,sizeof(book));
while(!myfile.eof())
{
if(no==book.mem_code)
{
flag1=2;
break;
}
myfile.read((char *)&book,sizeof(book));
}
myfile.close();
}
file.read((char *)&book,sizeof(book));
}
if(flag1==1)
{
gotoxy(26,11);
cout<<"ENTER THE BOOK CODE->";
cin>>code;
ofile.open("test.dat",ios::in|ios::app);
ofile.seekg(0);
ofile.read((char *)&book,sizeof(book));
while(!ofile.eof())
{
if(code==book.sub_code)
{
flag2=1;
break;
}
ofile.read((char *)&book,sizeof(book));
}
if(flag2==1)
{
gotoxy(26,18);
cout<<"******ISSUED*****";
book.mem_code=no;
book.issue_flag=1;
myfile.open("issue.dat",ios::app);
myfile.seekg(0);
myfile.write((char *)&book,sizeof(book));
getch();
}
else
{
gotoxy(26,18);
cout<<"SORRY!BOOK IS NOT IN THE LIBRARY";
getch();
}
}
else if(flag1==2)
{
gotoxy(26,18);
cout<<"YOU CAN'T ISSUE THE BOOK(MAX LIMIT=1)";
getch();
}
else
{
gotoxy(26,18);
cout<<"******INVALID MEMBER*****";
getch();
}
file.close();
ofile.close();
myfile.close();
}

//Display the detail about issued books//


void library::issue_book_display()
{
gotoxy(5,3);
cout<<"MEMBER CODE";
gotoxy(5,4);
cout<<"----------------------------------------------------------------------";
gotoxy(20,3);
cout<<"SUBJECT CODE";
gotoxy(40,3);
cout<<"TITLE";
int y=5;
ifstream file1;
file1.open("issue.dat",ios::in);
file1.seekg(0);
file1.read((char *)this,sizeof(book));
if(book.issue_flag==1)
{
while(!file1.eof())
{
gotoxy(6,y);
cout<<book.mem_code;
gotoxy(21,y);
cout<<book.sub_code;
gotoxy(41,y);
cout<<book.title;
y=y+2;
if(y>23)
{
y=5;
getch();
clrscr();
gotoxy(5,3);
cout<<"MEMBER CODE";
gotoxy(5,4);
cout<<"----------------------------------------------------------------
------";
gotoxy(20,3);
cout<<"SUBJECT CODE";
gotoxy(40,3);
cout<<"BOOK TITLE";
}
file1.read((char *)this,sizeof(book));
}}
file1.close();
}
//It accepts the detail for return the book to the library//
void library::return_book()
{
fstream file1,file2;
int code;
file1.open("issue.dat",ios::in);
file1.seekg(0);
file2.open("temp.dat",ios::app|ios::in);
file2.seekg(0);
cout<<" É============================================»\n";
cout<<" º ENTER DETAIL FOR RETURN THE BOOK º\n";
cout<<" È============================================¼";
gotoxy(22,14);
cout<<"ENTER THE MEMBER CODE TO RETURN THE BOOK->";
cin>>code;
file1.read((char *)&book,sizeof(book));
while(!file1.eof())
{
if(code!=book.mem_code)
file2.write((char *)&book,sizeof(book));
file1.read((char *)&book,sizeof(book));
}
file1.close();
file2.close();
remove("issue.dat");
rename("temp.dat","issue.dat");
gotoxy(26,20);
cout<<"PRESS ENTER TO CONTINUE.........";
}
//This is the main function of programe i.e execution gate
void main()
{ clrscr();
//design();
textcolor(110);
int ch;
char tt[] = {"WELCOME TO SAVLEEN BOOK LIBRARY"};
do
{ clrscr();
gotoxy(1,1);
for(int i=0;i<=79;i++)
{
cout<<"";
sound(1000);
delay(4);
}
gotoxy(1,24);
for(i=0;i<=79;i++)
{
cout<<"";
sound(2000);
delay(4);
}
for(i=1;i<24;i++)
{
gotoxy(1,i);
cout<<"";
sound(3000);
delay(4);
}
for(i=1;i<24;i++)
{
gotoxy(80,i);
cout<<"";
sound(4000);
delay(4);
}
for(i=1;i<24;i++)
{
gotoxy(20,i);
cout<<"";
sound(5000);
delay(4);
}
for(i=1;i<24;i++)
{
gotoxy(60,i);
cout<<"";
sound(6000);
delay(4);
}
nosound();
gotoxy(22,4);
for(i=0;i<=37;i++)
{
cout<<tt[i];
delay(80);
}
gotoxy(26,8);
cout<<"É=====================»";
gotoxy(26,9);
cout<<"º ADD NEW BOOK_____1 º";
gotoxy(26,10);
cout<<"º º";
gotoxy(26,11);
cout<<"º ADD NEW MEMBER___2 º";
gotoxy(26,12);
cout<<"º º";
gotoxy(26,13);
cout<<"º ISSUE BOOKS______3 º";
gotoxy(26,14);
cout<<"º º";
gotoxy(26,15);
cout<<"º RETURN BOOKS_____4 º";
gotoxy(26,16);
cout<<"º º";
gotoxy(26,17);
cout<<"º REPORTS__________5 º";
gotoxy(26,18);
cout<<"º º";
gotoxy(26,19);
cout<<"º EXIT_____________6 º";
gotoxy(26,20);
cout<<"È=====================¼";
gotoxy(29,22);
cout<<"ENTER YOUR CHOICE->";
cin>>ch;
switch(ch)
{
case 1: clrscr();
book.get_book_info();
break;
case 3: clrscr();
book.issue_book();
break;
case 4: clrscr();
book.return_book();getch();
break;
case 5: clrscr();
int ans;
do
{ clrscr();
gotoxy(26,4);
cout<<" *******REPORTS*******";
gotoxy(26,8);
cout<<"É=======================»";
gotoxy(26,9);
cout<<"º BOOK'S LIST_________1 º";
gotoxy(26,10);
cout<<"º º";
gotoxy(26,11);
cout<<"º MEMBER'S LIST_______2 º";
gotoxy(26,12);
cout<<"º º";
gotoxy(26,13);
cout<<"º BOOK ISSUED_________3 º";
gotoxy(26,14);
cout<<"º º";
gotoxy(26,15);
cout<<"º EXIT________________4 º";
gotoxy(26,16);
cout<<"È=======================¼";
gotoxy(26,20);
cout<<"ENTER YOUR CHOICE ->";
cin>>ans;
switch(ans)
{
case 1: clrscr();
book.book_display();
getch();break;
case 2: clrscr();
book.member_display();
getch();
break;
case 3: clrscr();
book.issue_book_display();
getch();
case 4: break;
}
}while(ans!=4);
break;
case 2: clrscr();
book.get_member();
break;
case 6: sound(1000);
delay(1000);
sound(2000);
delay(1000);
nosound();
for (i=80;i>=1;i--)
{
gotoxy(i,11);
cout<<"THANK YOU FOR USING THIS PROGRAM";
sound(1000);
delay(100);
clrscr();
}
nosound();
sound(1000);
delay(1000);
sound(2000);
delay(1000);
nosound();
for(i=80;i>=1;i--)
{
textcolor(110+BLINK);
gotoxy(24,9);
cout<<"Program Author : Savleen Kaur";
sound(1000);
delay(100);
clrscr();
}
nosound();
exit(0);
}
}while(ch!=6);
getch();
}

Vous aimerez peut-être aussi