Thursday, July 21, 2011

Library Management System (Sample)

#include<iostream.h>

#include<conio.h>

#include<stdio.h>

#include<fstream.h>

#include<string.h>

#include<dos.h>

void book_menu();

void member_menu();

void issue_menu();

class book

{

public:

int bkno;

char bkna[30];

char auth[30];

char edi[20];

char pags[10];

char pblis[40];

void add();

void search();

void del();

void modify();

void show();

void exit();

};

void book::add()

{

cout<<"\n Enter book no. : ";

cin>>bkno;

cout<<"\n Enter book name : ";

gets(bkna);

cout<<"\n Enter author name : ";

gets(auth);

cout<<"\n Enter book edition : ";

gets(edi);

cout<<"\n Enter pages : ";

gets(pags);

cout<<"\n Enter book Publisher : ";

gets(pblis);

}

void book::search()

{

book b;

int d;

int f=0;

ifstream ob1;

ob1.open("book.txt",ios::in);

cout<<"\n Enter book no. to search : ";

cin>>d;

ob1.read((char*)&b,sizeof(b));

while(ob1)

{

if(b.bkno==d)

{

b.show();

cout<<"\n Book found.";

f=1;

break;

}

else

{

f=0;

}

ob1.read((char*)&b,sizeof(b));

}

if(f==0)

{

cout<<"\n Book not found.";

}

ob1.close();

getch();

}

void book::del()

{

book b;

int d;

ifstream ob2;

ofstream ob3;

ob2.open("book.txt",ios::in);

ob3.open("temp.txt",ios::app);

cout<<"\n Enter book no. to delete : ";

cin>>d;

ob2.read((char*)&b,sizeof(b));

while(ob2)

{

if(b.bkno==d)

{

b.show();

cout<<"\n Record deleted.";

}

else

{

ob3.write((char*)&b,sizeof(b));

}

ob2.read((char*)&b,sizeof(b));

}

remove("book.txt");

rename("temp.txt","book.txt");

ob2.close();

ob3.close();

getch();

}

void book::modify()

{

book b;

int d;

ifstream ob4;

ofstream ob5;

ob4.open("book.txt",ios::in);

ob5.open("temp.txt",ios::app);

cout<<"\n Enter book no. to modify record : ";

cin>>d;

ob4.read((char*)&b,sizeof(b));

while(ob4)

{

if(b.bkno==d)

{

b.show();

cout<<"\n Enter new values for record";

b.add();

ob5.write((char*)&b,sizeof(b));

}

else

{

ob5.write((char*)&b,sizeof(b));

}

ob4.read((char*)&b,sizeof(b));

}

remove("book.txt");

rename("temp.txt","book.txt");

ob4.close();

ob5.close();

getch();

}

void book::show()

{

cout<<"\n Book no. : "<<bkno;

cout<<"\n Book name : "<<bkna;

cout<<"\n Author's name : "<<auth;

cout<<"\n Book Edition : "<<edi;

cout<<"\n Book Pages : "<<pags;

cout<<"\n Book publisher : "<<pblis;

}

void book::exit()

{

getch();

}

class member

{

char nm[50];

char pno[40];

char val[30];

int idno;

char ad[100];

char mems[30];

public:

void add();

void search();

void del();

void modify();

void show();

void exit();

};

void member::add()

{

cout<<"\n Enter member name : ";

gets(nm);

cout<<"\n Enter id no. : ";

cin>>idno;

cout<<"\n Enter member address : ";

gets(ad);

cout<<"\n Enter phone no. : ";

gets(pno);

cout<<"\n Membership started on : ";

gets(mems);

cout<<"\n Membership valid upto : ";

gets(val);

}

void member::search()

{

member mem;

int d;

ifstream ob6;

int f=0;

ob6.open("meb.txt",ios::in);

cout<<"\n Enter id no. to search member : ";

cin>>d;

ob6.read((char*)&mem,sizeof(mem));

while(ob6)

{

if(mem.idno==d)

{

mem.show();

cout<<"\n Record found.";

f=1;

break;

}

else

{

f=0;

}

ob6.read((char*)&mem,sizeof(mem));

}

if(f==0)

{

cout<<"\n Record not found.";

}

ob6.close();

getch();

}

void member::del()

{

member mem;

int d;

ifstream ob7;

ofstream ob8;

ob7.open("meb.txt",ios::in);

ob8.open("temp.txt",ios::app);

cout<<"\n Enter id no. to delete a member : ";

cin>>d;

ob7.read((char*)&mem,sizeof(mem));

while(ob7)

{

if(mem.idno==d)

{

mem.show();

cout<<"\n Record deleted.";

}

else

{

ob8.write((char*)&mem,sizeof(mem));

}

ob7.read((char*)&mem,sizeof(mem));

}

remove("meb.txt");

rename("temp.txt","meb.txt");

ob7.close();

ob8.close();

getch();

}

void member::modify()

{

member mem;

int d;

ifstream ob9;

ofstream ob10;

ob9.open("meb.txt",ios::in);

ob10.open("temp.txt",ios::app);

cout<<"\n Enter id no. to modify record : ";

cin>>d;

ob9.read((char*)&mem,sizeof(mem));

while(ob9)

{

if(mem.idno==d)

{

mem.show();

cout<<"\n Enter new values for record";

mem.add();

ob10.write((char*)&mem,sizeof(mem));

}

else

{

ob10.write((char*)&mem,sizeof(mem));

}

ob9.read((char*)&mem,sizeof(mem));

}

remove("meb.txt");

rename("temp.txt","meb.txt");

ob9.close();

ob10.close();

getch();

}

void member::show()

{

cout<<"\n Id no. : "<<idno;

cout<<"\n Member name : "<<nm;

cout<<"\n Address of member : "<<ad;

cout<<"\n Phone no : "<<pno;

cout<<"\n Membership started on : "<<mems;

cout<<"\n Membership valid upto : "<<val;

}

void member::exit()

{

getch();

}

class issue

{

public:

char baa[50];

char buka[50];

char editi[59];

char doi[50];

char bi[50];

char mno[50];

char tik[40];

int bn;

issue()

{

strcpy(baa,"");

bn=0;

}

void add();

void search();

void del();

void modify();

void show();

void exit();

};



void issue::add()

{

cout<<("\n Enter book name : ");

gets(baa);

cout<<("\n Enter book author : ");

gets(buka);

cout<<("\n Enter edition : ");

gets(editi);

cout<<"\n Enter date of issue(Enter date without spaces) : ";

gets(doi);

cout<<"\n Book issued to : ";

gets(bi);

cout<<"\n Member id no. : ";

gets(mno);

cout<<"\n Ticket no. : ";

gets(tik);

}



void issue::search()

{

issue iss;

int d;

ifstream ob11;

int f=0;

ob11.open("isu.txt",ios::in);

cout<<"\n Enter book no. to search : ";

cin>>d;

ob11.read((char*)&iss,sizeof(iss));

while(ob11)

{

if(iss.bn==d)

{

iss.show();

cout<<"\n Book found.";

f=1;

break;

}

else

{

f=0;

}

ob11.read((char*)&iss,sizeof(iss));

}

if(f==0)

{

cout<<"\n Book is already issued.";

}

ob11.close();

getch();

}

void issue::del()

{

issue iss;

int d;

ifstream ob12;

ofstream ob13;

ob12.open("isu.txt",ios::in);

ob13.open("temp.txt",ios::app);

cout<<"\n Enter book no. to search : ";

cin>>d;

ob12.read((char*)&iss,sizeof(iss));

while(ob12)

{

if(iss.bn==d)

{

iss.show();

cout<<"\n Record deleted.";

}

else

{

ob13.write((char*)&iss,sizeof(iss));

}

ob12.read((char*)&iss,sizeof(iss));

}

remove("isu.txt");

rename("temp.txt","isu.txt");

ob12.close();

ob13.close();

getch();

}

void issue::modify()

{

issue iss;

int d;

ifstream ob14;

ofstream ob15;

ob14.open("isu.txt",ios::in);

ob15.open("temp.txt",ios::app);

cout<<"\n Enter book no. to modify record :";

cin>>d;

ob14.read((char*)&iss,sizeof(iss));

while(ob14)

{

if(iss.bn==d)

{

iss.show();

cout<<"\n Enter new values for record";

iss.add();

ob15.write((char*)&iss,sizeof(iss));

}

else

{

ob15.write((char*)&iss,sizeof(iss));

}

ob14.read((char*)&iss,sizeof(iss));

}

remove("isu.txt");

rename("temp.txt","isu.txt");

ob14.close();

ob15.close();

getch();

}

void issue::show()

{

cout<<"\n Book no : "<<bn;

cout<<"\n Book name : "<<baa;

cout<<"\n Book author : "<<buka;

cout<<"\n Book edition : "<<editi;

cout<<"\n Date of issue : "<<doi;

cout<<"\n Book issued to : "<<mno;

cout<<"\n Member id no. : "<<bi;

cout<<"\n Ticket no. : "<<tik;

}

void issue::exit()

{

getch();

}

class retrn

{

int bnn;

char ba[30];

char dor[20];

public:

void add();

void search();

void del();

void modify();

void show();

void exit();

};

void retrn::add()

{

issue iss;

retrn ret;

char ch='y';

ifstream ob16;

int d;

while(ch=='y'||ch=='Y')

{

ob16.open("file.txt",ios::in);

cout<<"\n Enter book no.";

cin>>bnn;

ob16.read((char*)&ret,sizeof(ret));

while(ob16)

{

if(iss.bn==bnn)

{

cout<<"\n Enter the date of return(Enter date without spaces) : ";

cin>>dor;

}

else

{

exit();

}

}

cout<<"\n Enter 'y' to continue : ";

cin>>ch;

}

}

void retrn::search()

{

retrn ret;

int d;

ifstream ob17;

int f=0;

ob17.open("file.txt",ios::in);

cout<<"Enter book no. to search : ";

cin>>d;

ob17.read((char*)&ret,sizeof(ret));

while(ob17)

{

if(ret.bnn==d)

{

ret.show();

cout<<"\n Book returned.";

f=1;

break;

}

else

{

f=0;

}

}

if(f==0)

{

cout<<"\n Book not returned.";

}

ob17.close();

}

void retrn::del()

{

retrn ret;

int d;

ifstream ob18;

ofstream ob19;

ob18.open("file.txt",ios::in);

ob19.open("temp.txt",ios::app);

cout<<"\n Enter book no. to search : ";

cin>>d;

ob18.read((char*)&ret,sizeof(ret));

while(ob18)

{

if(ret.bnn==d)

{

ret.show();

cout<<"\n Record deleted.";

}

else

{

ob19.write((char*)&ret,sizeof(ret));

}

ob18.read((char*)&ret,sizeof(ret));

}

remove("file.txt");

rename("temp.txt","file.txt");

ob18.close();

ob19.close();

}

void retrn::modify()

{

retrn ret;

int d;

ifstream ob20;

ofstream ob21;

ob20.open("file.txt",ios::in);

ob21.open("temp.txt",ios::app);

cout<<"Enter book no. to modify a record.";

cin>>d;

ob20.read((char*)&ret,sizeof(ret));

while(ob20)

{

if(ret.bnn==d)

{

ret.show();

cout<<"\n Enter new values for this record.";

ret.add();

ob21.write((char*)&ret,sizeof(ret));

}

else

{

ob21.write((char*)&ret,sizeof(ret));

}

ob20.read((char*)&ret,sizeof(ret));

}

remove("file.txt");

rename("temp.txt","file.txt");

ob20.close();

ob21.close();

getch();

}

void retrn::show()

{

cout<<"\n Book no. : "<<bnn;

cout<<"\n Book name : "<<ba;

cout<<"\n Date of issue : "<<dor;

}

void retrn::exit()

{

getch();

}

void book_menu()

{

char c='y';

ifstream ob1;

ofstream ob;

book b;

int ch;

clrscr();

cout<<"\n 1. Add new record";

cout<<"\n 2. Search record";

cout<<"\n 3. Delete record";

cout<<"\n 4. Modify record";

cout<<"\n 5. Show record";

cout<<"\n 6. Back to menu";

cout<<"\n Enter your choice : ";

cin>>ch;

switch(ch)

{

case 1:

clrscr();

ob.open("book.txt",ios::app);

while(c=='y'||c=='Y')

{

b.add();

ob.write((char*)&b,sizeof(b));

cout<<"\n Press y to Continue : ";

cin>>c;

}

ob.close();

break;

case 2:

clrscr();

b.search();

break;

case 3:

clrscr();

b.del();

break;

case 4:

clrscr();

b.modify();

break;

case 5:

clrscr();

ob1.open("book.txt",ios::in);

ob1.read((char*)&b,sizeof(b));

while(ob1)

{

b.show();

ob1.read((char*)&b,sizeof(b));

}

ob1.close();

getch();

break;

case 6:

clrscr();

b.exit();

break;

}

}

void member_menu()

{

ofstream ob;

ifstream ob1;

int ch;

int days;

member mem;

char c='y';

clrscr();

cout<<"\n 1. Add new record";

cout<<"\n 2. Search record";

cout<<"\n 3. Delete record";

cout<<"\n 4. Modify record";

cout<<"\n 5. Show record";

cout<<"\n 6. Back to menu";

cout<<"\n Enter your choice : ";

cin>>ch;

switch(ch)

{

case 1:

clrscr();

ob.open("meb.txt",ios::app);

while(c=='y'||c=='Y')

{

mem.add();

ob.write((char*)&mem,sizeof(mem));

cout<<"\n Press y to continue : ";

cin>>c;

}

ob.close();

break;

case 2:

clrscr();

mem.search();

break;

case 3:

clrscr();

mem.del();

break;

case 4:

clrscr();

mem.modify();

break;

case 5:

clrscr();

ob1.open("meb.txt",ios::in);

ob1.read((char*)&mem,sizeof(mem));

while(ob1)

{

mem.show();

ob1.read((char*)&mem,sizeof(mem));

}

ob1.close();

getch();

break;

case 6:

clrscr();

mem.exit();

break;

}

}

void issue_menu()

{

ofstream ob;

ifstream ob1;

int ch;

issue iss;

textcolor(RED);

cprintf("Warning : Book must be returned within a week or there is a fine of Rs.
2 / day.");

cout<<"\n 1. Add new record";

cout<<"\n 2. Search record";

cout<<"\n 3. Delete record";

cout<<"\n 4. Modify record";

cout<<"\n 5. Show record";

cout<<"\n 6. Back to menu";

cout<<"\n Enter your choice : ";

cin>>ch;

switch(ch)

{

case 1:

clrscr();

book b;

int bn1;

int f=0;

ifstream ob11;

ofstream ob12;



ob12.open("isu.txt",ios::app);

ob11.open("book.txt",ios::in);

cout<<"\n Enter book no. you want to Issue : ";

cin>>bn1;

ob11.read((char*)&b,sizeof(b));

while(ob11)

{

if(b.bkno==bn1)

{

iss.bn=bn1;

iss.add();

f=1;

break;

}

else

{

f=0;

}

ob11.read((char*)&b,sizeof(b));

}



if(f==0)

cout<<"\n Book not available.";

else

ob12.write((char*)&iss,sizeof(iss));



ob11.close();

ob12.close();

getch();

getch();

break;

case 2:

iss.search();

break;

case 3:

iss.del();

break;

case 4:

iss.modify();

break;

case 5:

ob1.open("isu.txt",ios::in);

ob1.read((char*)&iss,sizeof(iss));

while(ob1)

{

iss.show();

ob1.read((char*)&iss,sizeof(iss));

cout<<"\n Press any key to continue.";

getch();

}

ob1.close();

getch();

break;

case 6:

iss.exit();

break;

}

}

void main()

{

int ch;

clrscr();

while(ch!=4)

{

clrscr();

textcolor(MAGENTA+BLINK);

cprintf("..........********** Welcome to 'Library Management
Project'**********..........");

textcolor(MAGENTA);

cprintf("................................................................................");

textcolor(YELLOW);

cprintf("\n\nSubmitted To : Prem Saini Sir Submitted by : Inderjeet Singh");

textcolor(YELLOW);

cprintf("\n................................................................................");

cout<<"\n 1. Book Menu";

cout<<"\n 2. Member Menu";

cout<<"\n 3. Issue Menu";

cout<<"\n 4. Exit";

cout<<"\n Enter your choice : ";

cin>>ch;

switch(ch)

{

case 1:

clrscr();

book_menu();

break;

case 2:

clrscr();

member_menu();

break;

case 3:

clrscr();

issue_menu();

break;

case 4:

textcolor(MAGENTA);

cprintf("\n\n \n\n\n\n\n\n\n\n\n\n\n\n\n Thanks for using it!!!");

getch();

}

}

};




No comments:

Post a Comment