0% found this document useful (0 votes)
30 views13 pages

PROJECT

The document describes a C++ program for a library management system that can add, modify, search and delete books and student records from data files. It allows issuing and returning books to students and calculates late return fines. The program uses classes, file handling and object-oriented concepts.

Uploaded by

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

PROJECT

The document describes a C++ program for a library management system that can add, modify, search and delete books and student records from data files. It allows issuing and returning books to students and calculates late return fines. The program uses classes, file handling and object-oriented concepts.

Uploaded by

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

#include<iostream.

h>
#include<conio.h>
#include<fstream.h>
#include<string.h>
#include<stdio.h>
#include<process.h>
#include<iomanip.h>
void menu();
class book
{
char bno[6];
char bname[25],aname[25];
public:
void insbook()
{
clrscr();
cout<<"\nenter book no:";
cin>>bno;
cout<<"\nenter book name:";
gets(bname);
cout<<"\nenter author name:";
gets(aname);
cout<<"\nbook inserted";
}
void showbook()
{
clrscr();
cout<<"\n bookno:"<<bno<<endl<<"book name:";
puts(bname);
cout<<endl;
cout<<"author name:";
puts(aname);
cout<<endl;
}
void modifybook()
{
char x[25],y[25];
char a[25],b[25];
strcpy(b,bname);
strcpy(a,aname);
cout<<"\nbookno:"<<bno;
cout<<"\nenter new bookname: or press space for retain first one:";
gets(x);
cout<<"\nenter new authorname or press space for retain first one:";
gets(y);
if(strcmpi(x," ")==0)
strcpy(bname,b);
else
strcpy(bname,x);
if(strcmpi(y," ")==0)
strcpy(aname,a);
else
strcpy(aname,y);
cout<<endl<<"book modified successfully";
}
char* getbno()
{
return bno;
}
void report()
{
cout<<bno<<setw(30)<<bname<<setw(30)<<aname;
}
};
class student
{
char admno[6];
int token;
char sname[25];
int cls;
public:
void insstudent()
{
clrscr();
cout<<"enter student admission no:";
cin>>admno;
cout<<"\nenter student name:";
gets(sname);
cout<<"\nenter student class:";
cin>>cls;
token=0;
}
void showstudent()
{
cout<<"\nadmission no:"<<admno;
cout<<"\nstudent name:";
puts(sname);
cout<<"\nno. of book issued:"<<token;
cout<<"\nclass:"<<cls;
}
void modifystudent()
{
clrscr();
char x[25],a[25];
strcpy(a,sname);
cout<<"\nadmission no:"<<admno;
cout<<"\nenter student class:";
cin>>cls;
cout<<"\nenter new student name or press space to retain first one:";
gets(x);
if(strcmpi(x," ")==0)
strcpy(sname,a);
else
strcpy(sname,x);
}
char* retadmno()
{
return admno;
}
int rettoken()
{
return token;
}
void addtoken()
{
token=1;
}
void resettoken()
{
token=0;
}
void report()
{
cout<<admno<<setw(20)<<sname<<setw(20)<<cls<<setw(20)<<token<<endl;
}
};
fstream fp,fp1;
student s;
book b;
void writebook()
{
clrscr();
char ch;
fp.open("book.dat",ios::out|ios::app);
x:
clrscr();
b.insbook();
fp.write((char*)&b,sizeof(book));
cout<<"\ndo you want to add more book(y/n):";
cin>>ch;
if(ch=='y'|| ch=='Y')
goto x;
else
{
fp.close();
menu();
}
}
void writestudent()
{
char ch;
fp1.open("student.dat",ios::out|ios::app);
p:
s.insstudent();
fp1.write((char*)&s,sizeof(student));
cout<<"\ndo you want to add more student(y/n):";
cin>>ch;
if(ch=='y' || ch=='Y')
goto p;
else
{
fp1.close();
menu();
}
}
void searchb(char x[])
{
int flag=0;
cout<<setw(50)<<"\nbook details\n"<<endl;
fp.open("book.dat",ios::in);
while(fp.read((char*)&b,sizeof(book)))
{
if(strcmpi(b.getbno(),x)==0)
{
cout<<endl;
b.showbook();
flag=1;
char ch1;
cout<<"\n want to return to menu(y/n):";
cin>>ch1;
if(ch1=='y'|| ch1=='Y')
menu();
}
}
fp.close();
if(flag==0)
{
cout<<"\nbook not found \n try again later";
char ch;
cout<<"\n want to return to menu(y/n):";
cin>>ch;
if(ch=='y'|| ch=='Y')
menu();
}
}
void searchs(char x[])
{
int flag=0;
cout<<setw(50)<<"\nstudent details\n"<<endl;
fp1.open("student.dat",ios::in|ios::out);
while(fp1.read((char*)&s,sizeof(student)))
{
if(strcmpi(s.retadmno(),x)==0)
{
cout<<endl;
s.showstudent();
flag=1;
char ch1;
cout<<"\n want to return to menu(y/n):";
cin>>ch1;
if(ch1=='y'|| ch1=='Y')
menu();
}
}
fp1.close();
if(flag==0)
{
cout<<"\nstudent not found \n try again later";
char ch;
cout<<"\n want to return to menu(y/n):";
cin>>ch;
if(ch=='y'|| ch=='Y')
menu();
}
}
void modifybook()
{
int found=0;
char x[6];
clrscr();
cout<<setw(50)<<"modify book detail"<<endl;
cout<<"\nenter book no of book to be modified:";
cin>>x;
fp.open("book.dat",ios::in|ios::out);
while(fp.read((char*)&b,sizeof(book)) && found==0)
{
if(strcmpi(b.getbno(),x)==0)
{
found=1;
b.showbook();
cout<<"\nenter new book details \n";
b.modifybook();
int pos=-1*sizeof(b);
fp.seekp(pos,ios::cur);
fp.write((char*)&b,sizeof(book));
cout<<"\nrecord updated";
fp.close();
char ch1;
cout<<"\n want to return to menu(y/n):";
cin>>ch1;
if(ch1=='y'|| ch1=='Y')
menu();
}
}
if(found==0)
{
fp.close();
cout<<"\nrecord not found";
char ch;
cout<<"\n want to return to menu(y/n):";
cin>>ch;
if(ch=='y'|| ch=='Y')
menu();
}
}
void modifystudent()
{
int found=0;
char x[6];
clrscr();
cout<<setw(50)<<"modify student detail";
cout<<"\nenter admission of student to modify:";
cin>>x;
fp1.open("student.dat",ios::in|ios::out);
while(fp1.read((char*)&s,sizeof(student)) && found==0)
{
if(strcmpi(s.retadmno(),x)==0)
{
s.showstudent();
cout<<"\nenter the new details of student\n"<<endl;
s.modifystudent();
int pos=-1*sizeof(s);
fp1.seekp(pos,ios::cur);
fp1.write((char*)&s,sizeof(student));
cout<<"\n record updated"<<endl;
found=1;
fp1.close();
char ch;
cout<<"\n want to return to menu(y/n):";
cin>>ch;
if(ch=='y'|| ch=='Y')
menu();
}
}
if(found==0)
{
fp1.close();
cout<<"\nstudent not found";
char ch1;
cout<<"\n want to return to menu(y/n):";
cin>>ch1;
if(ch1=='y'|| ch1=='Y')
menu();
}
}
void delstudent()
{
int flag=0;
char x[6];
clrscr();
cout<<setw(50)<<"DELETE STUDENT"<<endl;
cout<<"\nenter admission no of student to be deleted:";
cin>>x;
fp.open("student.dat",ios::in|ios::out);
fstream fp2("temp1.dat",ios::out);
fp.seekp(0,ios::beg);
while(fp.read((char*)&s,sizeof(student)))
{
if(strcmpi(s.retadmno(),x)!=0)
{
fp2.write((char*)&s,sizeof(student));
flag=1;
}
}
fp.close();
fp2.close();
remove("student.dat");
rename("temp1.dat","student.dat");
if(flag==1)
{
cout<<"\nstudent record deleted";
char ch;
cout<<"\n want to return to menu(y/n):";
cin>>ch;
if(ch=='y'|| ch=='Y')
menu();
}
else
{
cout<<"\nstudent record not found";
char ch1;
cout<<"\n want to return to menu(y/n):";
cin>>ch1;
if(ch1=='y'|| ch1=='Y')
menu();
}
}
void delbook()
{
int flag=0;
char x[6];
clrscr();
cout<<setw(30)<<"DELETE BOOK"<<endl;
cout<<"\nenter book no to be deleted:";
cin>>x;
fp.open("book.dat",ios::in|ios::out);
fstream fp2("temp.dat",ios::out);
fp.seekp(0,ios::beg);
while(fp.read((char*)&b,sizeof(book)))
{
if(strcmpi(b.getbno(),x)!=0)
fp2.write((char*)&b,sizeof(book));
else
flag=1;
}
fp.close();
fp2.close();
remove("book.dat");
rename("temp.dat","book.dat");
if(flag==1)
{
cout<<"\nbook has been deleted successfully!!!";
char ch;
cout<<"\n want to return to menu(y/n):";
cin>>ch;
if(ch=='y'|| ch=='Y')
menu();
}
else
{
cout<<"\nbook not found";
char ch1;
cout<<"\n want to return to menu(y/n):";
cin>>ch1;
if(ch1=='y'|| ch1=='Y')
menu();
}
}
void blist()
{
clrscr();
fp.open("book.dat",ios::in);
if(!fp)
{
cout<<"\nERROR!! FILE NOT OPEN";
getch();
return;
}
else
{
cout<<endl<<setw(50)<<"BOOK LIST"<<endl;
cout<<"\n=============================================================\n";
cout<<"book number"<<setw(30)<<"book name"<<setw(30)<<"author name";
cout<<"\n================================================================\n";
while(fp.read((char*)&b,sizeof(book)))
{
cout<<endl;
b.report();
}
}
fp.close();
char ch;
cout<<"\n want to return to menu(y/n):";
cin>>ch;
if(ch=='y'|| ch=='Y')
menu();
}
void slist()
{
clrscr();
fp1.open("student.dat",ios::in|ios::out);
if(!fp1)
{
cout<<"\nERROR!! FILE NOT FOUND";
getch();
return;
}
else
{
cout<<setw(50)<<"STUDENT LIST"<<endl;
cout<<"\n===================================================================\n";
cout<<"admission no"<<setw(20)<<"student name"<<setw(20)<<"class"<<setw(20)<<"book
issued"<<endl;
while(fp1.read((char*)&s,sizeof(student)))
{
cout<<endl;
s.report();
}
}
fp1.close();
char ch;
cout<<"\n want to return to menu(y/n):";
cin>>ch;
if(ch=='y'|| ch=='Y')
menu();
}
void delb1(char x[])
{
clrscr();
fp.open("book.dat",ios::in,ios::out);
fstream fp2("temp.dat",ios::out);
fp.seekp(0,ios::beg);
while(fp.read((char*)&b,sizeof(book)))
{
if(strcmpi(b.getbno(),x)!=0)
fp2.write((char*)&b,sizeof(book));
}
fp.close();
fp2.close();
remove("book.dat");
rename("temp.dat","book.dat");
}
void issuebook()
{
clrscr();
char sn[25],bn[25];
int found=0,flag=0;
cout<<setw(50)<<"BOOK ISSUE..."<<endl;
cout<<"enter admission no of student to whom book is issued:";
cin>>sn;
fp.open("student.dat",ios::in|ios::out);
fp1.open("book.dat",ios::in|ios::out);
while(fp.read((char*)&s,sizeof(student)) && found==0)
{
if(strcmpi(s.retadmno(),sn)==0)
{
found=1;
if(s.rettoken()==0)
{
cout<<endl<<"enter the book no.";
cin>>bn;
while(fp1.read((char*)&b,sizeof(book)) && flag==0)
{
if(strcmpi(b.getbno(),bn)==0)
{
flag=1;
b.showbook();
s.addtoken();
int pos=-1*sizeof(s);
fp.seekp(pos,ios::cur);
fp.write((char*)&s,sizeof(student));
cout<<"\n\n book issued successfully";
fp.close();
fp1.close();
char ch;
cout<<"\n want to return to menu(y/n):";
cin>>ch;
if(ch=='y'|| ch=='Y')
menu();
}
}
if(flag==0)
{
cout<<"book does not exist";
fp.close();
fp1.close();
char ch1;
cout<<"\n want to return to menu(y/n):";
cin>>ch1;
if(ch1=='y'|| ch1=='Y')
menu();
}
}
else
{
fp.close();
fp1.close();
cout<<"you have not returned the last book\n";
char ch2;
cout<<"\n want to return to menu(y/n):";
cin>>ch2;
if(ch2=='y'|| ch2=='Y')
menu();
}
}
}
if(found==0)
{
cout<<"\n student does not exist";
fp.close();
fp1.close();
char ch3;
cout<<"\n want to return to menu(y/n):";
cin>>ch3;
if(ch3=='y'|| ch3=='Y')
menu();
}
}
void deposit()
{
char sn[25],bn[25];
int flag=0,found=0,day,fine;
clrscr();
cout<<"\n\n BOOK DEPOSIT \n";
cout<<"\nenter student admission no.:";
cin>>sn;
cout<<endl<<"\nenter book no.:";
cin>>bn;
fp.open("student.dat",ios::in,ios::out);
fp1.open("book.dat",ios::in,ios::out);
while(fp.read((char*)&s,sizeof(student)) && flag==0)
{
if(strcmpi(s.retadmno(),sn)==0)
{
found=1;
if(s.rettoken()==1)
{
while(fp1.read((char*)&b,sizeof(book)) && flag==0)
{
if(strcmpi(b.getbno(),bn)==0)
{
b.showbook();
flag=1;
cout<<"\nbook deposited in no.of days:";
cin>>day;
if(day>15)
{
fine=(day-15)*3;
cout<<"\nfine has to be deposited rs."<<fine;
}
s.resettoken();
int pos=-1*sizeof(s);
fp.seekp(pos,ios::cur);
fp.write((char*)&s,sizeof(student));
cout<<"\n\nbook deposited successfully!!!";
char ch;
cout<<"\n want to return to menu(y/n):";
cin>>ch;
if(ch=='y'|| ch=='Y')
menu();
}
}
if(flag==0)
{
cout<<"\nbook does not exist\n";
char ch1;
cout<<"\n want to return to menu(y/n):";
cin>>ch1;
if(ch1=='y'|| ch1=='Y')
menu();
}
}
else
{
cout<<"\nno book is issued please check!!!\n";
char ch2;
cout<<"\n want to return to menu(y/n):";
cin>>ch2;
if(ch2=='y'|| ch2=='Y')
menu();
}
}
}
fp.close();
fp1.close();
if(found==0)
{
cout<<"\nstudent record not exist...\n";
char ch3;
cout<<"\n want to return to menu(y/n):";
cin>>ch3;
if(ch3=='y'|| ch3=='Y')
menu();
}
}
void menu()
{
clrscr();
int x;
cout<<"\n =================================================================\n";
cout<<setw(50)<<"WELCOME TO LIBRARY MANAGEMENT";
cout<<"\n =================================================================\n";
cout<<endl;
cout<<"ADMIN MENU";
cout<<"\n =================================================================\n";
cout<<"\n1.add book\n2.book issue \n3.deposit book\n4.display all books\n";
cout<<"5.add student\n6.display all student list\n7.search for a student\n";
cout<<"8.search for a book\n9.delete book\n10.delete student\n11.modify book\n";
cout<<"12.modify student\n13.exit\n14.delete all books\n15.delete all students\n";
cin>>x;
switch(x)
{
case 1:
writebook();
break;
case 2:
issuebook();
break;
case 3:
deposit();
break;
case 4:
blist();
break;
case 5:
writestudent();
break;
case 6:
slist();
break;
case 7:
char num[6];
clrscr();
cout<<"enter admission number of student to be display:";
cin>>num;
searchs(num);
break;
case 8:
char num1[6];
clrscr();
cout<<"enter book no to be display:";
cin>>num1;
searchb(num1);
break;
case 9:
delbook();
break;
case 10:
delstudent();
break;
case 11:
modifybook();
break;
case 12:
modifystudent();
break;
case 13:
exit(0);
case 14:
remove("book.dat");
fp.open("book.dat",ios::in|ios::out);
menu();
break;
case 15:
remove("student.dat");
fp1.open("student.dat",ios::in|ios::out);
menu();
break;
default:
cout<<"enter valid choice!!!";
menu();
}
}
void main()
{
clrscr();
char x[10];
int attempt=3;
fstream f1("book.dat",ios::in,ios::out);
fstream f2("student.dat",ios::in,ios::out);
fstream f3("issue.dat",ios::in,ios::out);
cout<<"\n ================================================================";
cout<<"\n WELCOME TO LIBRARY MANAGEMENT- -K.M.P.S.\n";
cout<<"\n ================================================================";
p:
cout<<"\n enter admin password:";
gets(x);
if(strcmpi(x,"libman112")==0)
{
menu();
}
else
{
cout<<"\nyou enter wrong password!!!! please try again \n"<<attempt<<" attempts
left";
attempt--;
if(attempt!=-1)
{
goto p;
}
else
{
cout<<"you are out of attempts!!";
getch();
}
}
getch();
}

You might also like