0% found this document useful (0 votes)
34 views

Library Coding

This C++ program defines structures and functions to create a library management system. The key functions include adding, updating, deleting book records, searching records by roll number, generating a report of all records, and issuing books to students by recording the book ID and status. The main menu allows selecting these options. Box drawing functions are used to create borders around input/output screens.

Uploaded by

Hitesh Garg
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views

Library Coding

This C++ program defines structures and functions to create a library management system. The key functions include adding, updating, deleting book records, searching records by roll number, generating a report of all records, and issuing books to students by recording the book ID and status. The main menu allows selecting these options. Box drawing functions are used to create borders around input/output screens.

Uploaded by

Hitesh Garg
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 12

#include<iostream.

h>
#include<conio.h>
#include<fstream.h>
#include<string.h>
#include<process.h>
#include<stdio.h>
#include<dos.h>

struct library
{
char name[50];
int bid,roll;
char bname[45];
char status[10];
};
library lib,lib1;
struct book
{
int bid;
char bname[50];
char pub[50];
char status;
}b1;
void introduction();
void get_data();
void add_object();
void update();
void delete1();
void search();
void report();
void menu();
void issue();
void show_data();
void get_lib();
void show_lib();
int status1(void);
void box(int,int,int,int);
fstream file,file1;
char rr[10];
char *pp="yes";
//introduction//
void introduction()
{
clrscr();
gotoxy(22,5);
cout<<" ******************* WELCOME ******************";
gotoxy(26,10);
cprintf("::::::::::BOOK LIBRARY:::::::::::");
gotoxy(12,13);
cout<<"THIS PROJECT HAS FACILITY OF MAINTAINING RECORDS";
gotoxy(12,14);
cout<<"OF BOOKS";
gotoxy(12,17);
cout<<"THIS PROJECT CAN HOLD MORE THAN 10,000 BOOK'S";
gotoxy(12,18);
cout<<"RECORDS";
gotoxy(12,21);
cout<<"ONE MEMBER CAN ISSUE ONE BOOK AT A TIME. IF HE/SHE";
gotoxy(12,22);
cout<<"DOES NOT RETURN BOOK UPTO 15 DAYS HE/SHE HAVE TO";
gotoxy(12,23);
cout<<"PAY FINE OF RS.2/- PER DAY.";
gotoxy(27,29);
cprintf("PRESS ANY KEY TO CONTINUE");
textcolor(WHITE);
getch();
}
void issue()
{
char yn='y';
char permission='n';
file.open("libr.txt",ios::in);
file1.open("book.txt",ios::app);
do
{ int f=0;
clrscr();
//bbox();
gotoxy(5,6);
cprintf("Issue Book to Student:::::");
gotoxy(8,8);
cprintf("Book ID : ");
cin>>b1.bid;
gotoxy(8,10);
cprintf("Book Name : ");
cin>>b1.bname;
gotoxy(8,12);
cprintf("Book Publisher : ");
cin>>b1.pub;
gotoxy(8,14);
cprintf("Status : ");
cin>>b1.status;
gotoxy(8,16);
file.read((char *)&lib,sizeof(lib));
while(!file.eof())
{
cout<<"\n bookid= "<<lib.bid;

if(lib.bid==b1.bid)
{
f++;
cprintf(" Book Name : %s",lib.bname);
break;
}

}
if(f<1)
{
printf("Book not Found!!");
}

gotoxy(6,19);
if(f==1)
{
cprintf("You want to issue Book ? (y/n) ");
cin>>permission;
gotoxy(6,21);
if(permission=='y')
{

file1.write((char *)&b1,sizeof(b1));
cprintf("Enter More Book : (y/n) ");
cin>>yn;
}

}
else
{yn='n';}
}while(yn!='n');
file.close();
file1.close();
status1();
gotoxy(10,21);
cprintf("Press any key....");
getche();
}
int status1(void)
{

file.open("libr.txt",ios::app);
file.seekg(0,ios::beg);
int i=0;
do
{
if(lib.bid==b1.bid)
{
strcpy(lib.status, pp);
file.write((char *)&lib,sizeof(lib));
break;
i++;
}
} while(!file.eof());
file.close();
}

//*GETDATA FUNCTION//
void get_data()
{
clrscr();
box(18,2,72,40);
gotoxy(20,5);
textcolor(CYAN);

cprintf("###################################################
");
gotoxy(23,8);
textbackground(BLACK);
textcolor(GREEN+BLINK);
cprintf(" ::::::::ADD BOOK RECORD::::::: ");
gotoxy(20,11);
textcolor(CYAN);

cprintf("###################################################
");
gotoxy(30,12);
cout<<"INFORMATION OF STUDENT";
gotoxy(32,14);
cout<<"Enter roll no .... : ";
cin>>lib.roll;
gotoxy(32,16);
cout<<"Enter student name : ";
cin>>lib.name;
gotoxy(32,18);
cout<<"Enter Book Id : ";
cin>>lib.bid;
gotoxy(30,20);
cout<<"Book Name : ";
cin>>lib.bname;
gotoxy(32,22);
cout<<"Book Status : ";
cin>>lib.status;
getch();
}
//show data
void get_lib()
{
clrscr();
box(18,2,72,40);
gotoxy(20,5);
textcolor(CYAN);

cprintf("###################################################
");
gotoxy(23,8);
textbackground(BLACK);
textcolor(GREEN+BLINK);
cprintf(" ::::::::ADD BOOk RECORD::::::: ");
gotoxy(20,11);
textcolor(CYAN);

cprintf("###################################################
");
gotoxy(30,12);
cout<<"INFORMATION OF Books";
gotoxy(32,14);
cout<<"Enter Book Id .... : ";
cin>>b1.bid;
gotoxy(32,16);
cout<<"Enter Book name : ";
cin>>b1.bname;
gotoxy(32,18);
cout<<"Enter Publisher : ";
cin>>b1.pub;
gotoxy(30,20);
cout<<"Book Status : ";
cin>>b1.status;
getch();
}
void show_data()
{
clrscr();
box(18,2,72,40);
gotoxy(20,5);
textcolor(CYAN);
cprintf("###################################################
");
gotoxy(23,8);
textbackground(BLACK);
textcolor(GREEN+BLINK);
cprintf(" ::::::::Record of Students ::::::: ");
gotoxy(20,11);
textcolor(CYAN);

cprintf("###################################################
");
gotoxy(30,12);
cout<<"INFORMATION OF STUDENT";
gotoxy(32,14);
cout<<"Roll no : "<<lib.roll;
gotoxy(32,16);
cout<<"Student name : "<<lib.name;
gotoxy(30,18);
cout<<"Book Id : "<<lib.bid;
gotoxy(32,20);
cout<<"ABOUT BOOK ISSUED : "<<lib.status;
getch();

void show_lib()
{
clrscr();
box(18,2,72,40);
gotoxy(20,5);
textcolor(CYAN);

cprintf("###################################################
");
gotoxy(23,8);
textbackground(BLACK);
textcolor(GREEN+BLINK);
cprintf(" ::::::::Record of Books ::::::: ");
gotoxy(20,11);
textcolor(CYAN);

cprintf("###################################################
");
gotoxy(30,12);
cout<<"INFORMATION OF Books";
gotoxy(32,14);
cout<<"Book ID : "<<b1.bid;
gotoxy(32,16);
cout<<"Book name : "<<b1.bname;
gotoxy(30,18);
cout<<"Publisher : "<<b1.pub;
gotoxy(32,20);
cout<<"Status of Book : "<<b1.status;
getch();

}
//ADD FUNCTION//
void add_object()
{
char c1='y';
while(c1=='y'||c1=='Y')
{
file.open("libr.txt",ios::app);
get_data();
file.write((char*)&lib,sizeof(lib));
file.flush();
file.close();
gotoxy(32,32);
cout<<"WANT TO ADD MORE RECORD(y/n)...";
cin>>c1;
}
if(c1=='n'||c1=='N')
{
menu();
}
}
//UPDATE FUNCTION//
void update()
{
int book_code,temp;
fstream file1,file2;
clrscr();
file1.open("libr.txt",ios::in);
file2.open("temp.txt",ios::app);
file1.seekg(0,ios::beg);
file1.read((char *)&lib,sizeof(lib));
box(11,4,72,40);
gotoxy(25,15);
cout<<"ENTER THE BOOK CODE....";
cin>>book_code;
while(!file1.eof())
{
if(book_code!=lib.bid)
file2.write((char *)&lib,sizeof(lib));
else
{
show_data();
}
file2.flush();
file1.read((char *)&lib,sizeof(lib));
}
gotoxy(23,32);
cout<<"WANT TO UPDATE THE RECORDS y/n.....";
char ans;
cin>>ans;
if(ans=='y'||ans=='Y')
{
clrscr();
get_data();
file2.write((char *)&lib,sizeof(lib));
getch();
}
else if(ans=='n'||ans=='N')
{
menu();
}
file1.close();
file2.close();
remove("libr.txt");
rename("temp.txt","libr.txt");
gotoxy(23,32);
cout<<"YOUR RECORD HAS BEEN UPDATE.....";
getch();
}
//SEARCH RECORDS//
void search()
{
clrscr();
int rec;
int count=0;
box(15,2,67,35);
gotoxy(30,15);
cout<<"ENTER roll no.......";
cin>>rec;
file.open("libr.txt",ios::in);
file.seekg(0,ios::beg);
file.read((char *)&lib, sizeof(lib));
while(!file.eof())
{
if(lib.roll==rec)
{count++;
show_data();
getch();
}
file.read((char *)&lib,sizeof(lib));
}
file.close();
gotoxy(24,30);
cout<<"RECORDS FOUND="<<count;
getch();
}
//DELETE FUNCTION//
void delete1()
{
int rec_no;
fstream file1,file2;
clrscr();
file1.open("libr.txt",ios::in);
file2.open("temp.txt",ios::app);
box(11,4,72,40);
gotoxy(25,15);
cout<<"ENTER THE BOOK CODE";
cin>>rec_no;
while(!file1.eof())
{
if(rec_no!=lib.bid)
file2.write((char *)&lib,sizeof(lib));
else
{
show_data();
}
file2.flush();
file1.read((char *)&lib,sizeof(lib));
}
gotoxy(25,32);
cout<<"WANT TO DELETE THE RECORD y/n.......";
char ans;
cin>>ans;
if(ans=='n'||ans=='N')
{
return;
}
file1.close();
file2.close();
remove("libr.txt");
rename("temp.txt","libr.txt");
gotoxy(25,32);
cout<<"YOUR RECORD HAS BEEN DELETED.........";
getch();
}
//REPORT//
void report()
{
clrscr();
file.open("libr.txt",ios::in);
file.seekg(0,ios::beg);
file.read((char *)&lib,sizeof(lib));
cout<<endl;
while(!file.eof())
{
show_data();
file.read((char *)&lib,sizeof(lib));
}
file.close();
gotoxy(25,32);
cout<<"PRESS ANY KEY TO CONTINUE......";
getch();
}
//BOX FUNCTION//
void box(int x1,int y1,int x2,int y2)
{
int col,row;
for(col=x1;col<x2;col++)
{
gotoxy(col,y1);
cprintf("%c",'*');
gotoxy(col,y2);
cprintf("%c",'*');
}
for(row=y1;row<y2;row++)
{
gotoxy(x1,row);
cprintf("%c",'*');
gotoxy(x2,row);
cprintf("%c",'*');
}
gotoxy(x1,y1);
cprintf("%c",228);
gotoxy(x1,y2);
cprintf("%c",192);
gotoxy(x2,y1);
cprintf("%c",191);
gotoxy(x2,y2);
cprintf("%c",217);
}
void menu()
{
int ch;
clrscr();
box(11,4,72,40);
gotoxy(18,6);
textbackground(BLACK);
textcolor(CYAN);
cprintf("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
gotoxy(18,9);
textcolor(RED);
cprintf(":::::::::::::SUKHAM MEMORIAL LIBRARY ::::::::::");
gotoxy(18,12);
textcolor(CYAN);
cprintf("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
gotoxy(22,15);
cout<<"1. ADD_OBJECT :";
gotoxy(22,18);
cout<<"2. UPDATE :";
gotoxy(22,21);
cout<<"3. DELETE1 :";
gotoxy(22,24);
cout<<"4. SEARCH :";
gotoxy(22,27);
cout<<"5. REPORT :";
gotoxy(65,3);
cout<<"QUIT=0";
gotoxy(22,26);
cout<<"5. ISUUE BOOK ";
gotoxy(30,37);
cout<<"ENTER YOUR CHOICE.......";
cin>>ch;
switch(ch)
{
case 1:
add_object();
break;
case 2:
update();
menu();
break;
case 3:
delete1();
menu();
break;
case 4:
search();
menu();
break;
case 5:
report();
menu();
break;
case 6:
issue();
menu();
break;
case 0:
exit(0);
break;
}
}
void main()
{
clrscr();
introduction();
menu();
getch();
}

You might also like