Computer Science Project
Computer Science Project
PROJECT ON
LIBRARY
MANAGEMENT
SYSTEM
NAME- Om Tiwari
CLASS- XII
ROLL NUMBER-9181111
CERTIFICATE
This is to certify that Om Tiwari of XII-A
studying in Kendriya Vidyalaya Pushp Vihar
has successfully completed his project
entitled STUDY OF DIFFUSION OF SOLIDS
IN LIQUIDS, under the guidance of Mr.
Ramesh in the year of 2016-2017
Signature
Acknowledgement
I would like to express my special thanks of gratitude to my
teacher Mr. Ramesh who gave me the golden opportunity to
do this wonderful project on the topic LIBRARY
MANAGEMENT SYSTEM, which also helped me in doing a lot
of Research and I came to know about so many new things I
am really thankful to them.
Secondly I would also like to thank my parents and friends
who helped me a lot in finalizing this project within the limited
time frame.
SYNOPSIS
3. DATA ENCAPSULATION: -
Data encapsulation,
sometimes referred to as data hiding, is the mechanism
whereby the implementation details of a class are kept
hidden from the user.
fstream (fstream.h)
Declares the C++ classes that support file I/O.
string (string.h)
This library enables you to manipulate C strings that end in the char '\0', the null
char
iomanip (iomanip.h)
The manipulation in this library affect the format of steam operations. Note that
iostream contains additional manipulators.
conio.h :This header declares several useful library functions for performing
"console input and output" from a program .
process.h :process.h is a C header file which contains function declarations and macros used in working
with threads and processes.
dos.h :dos.h header file of c language contains functions for handling interrupts, producing sound,
date and time functions etc.
Coding:#include<fstream>
#include<iostream>
#include<conio.h>
#include<stdio.h>
#include<process.h>
#include<string.h>
# include<dos.h>
#include<iomanip>
//***************************************************************
// CLASS USED IN PROJECT
//****************************************************************
class book
{
char bno[6];
char bname[50];
char aname[20];
public:
void create_book()
{
std::cout<<"\nNEW BOOK ENTRY...\n";
std::cout<<"\nEnter The book no.";
std::cin>>bno;
std::cout<<"\n\nEnter The Name of The Book ";
gets(bname);
std::cout<<"\n\nEnter The Author's Name ";
gets(aname);
std::cout<<"\n\n\nBook Created..";
}
void show_book()
{
std::cout<<"\nBook no. : "<<bno;
std::cout<<"\nBook Name : ";
puts(bname);
std::cout<<"Author Name : ";
puts(aname);
}
void modify_book()
{
std::cout<<"\nBook no. : "<<bno;
std::cout<<"\nModify Book Name : ";
gets(bname);
std::cout<<"\nModify Author's Name of Book : ";
gets(aname);
}
char* retbno()
{
return bno;
}
void report()
{
std::cout<<bno<<
std::setw(30)<<bname<<std::setw(30)<<aname;
}
}; //class ends here
class student
{
char admno[6];
char name[20];
char stbno[6];
int token;
public:
void create_student()
{
//clrscr();
std::cout<<"\nNEW STUDENT ENTRY...\n";
std::cout<<"\nEnter The admission no. ";
std::cin>>admno;
std::cout<<"\n\nEnter The Name of The Student ";
gets(name);
token=0;
stbno[0]='/0';
std::cout<<"\n\nStudent Record Created..";
}
void show_student()
{
std::cout<<"\nAdmission no. : "<<admno;
std::cout<<"\nStudent Name : ";
puts(name);
std::cout<<"\nNo of Book issued : "<<token;
if(token==1)
std::cout<<"\nBook No "<<stbno;
}
void modify_student()
{
std::cout<<"\nAdmission no. : "<<admno;
std::cout<<"\nModify Student Name : ";
gets(name);
}
char* retadmno()
{
return admno;
}
char* retstbno()
{
return stbno;
}
int rettoken()
{
return token;
}
void addtoken()
{
token=1;
}
void resettoken()
{
token=0;
}
void getstbno(char t[])
{
strcpy(stbno,t);
}
void report()
{
std::cout<<"\t"<<admno<<std::setw(20)<<name<<std::setw(10)<<token;
}
}; //class ends here
//***************************************************************
// global declaration for stream object, object
//***********************************************************
book bk;
student st;
//***************************************************************
// function to write in file
//****************************************************************
void write_book()
{
system("cls");
char ch;
std::fstream file;
file.open("book.dat",std::ios::out|std::ios::app);
do{
system("cls");
bk.create_book();
file.write((char*)&bk,sizeof(book));
std::cout<<"\n\nDo you want to add more record..(y/n?)";
std::cin>>ch;
}while(ch=='y'||ch=='Y');
file.close();
}
void write_student()
{
system("cls");
char ch;
std::fstream file1;
file1.open("student.dat",std::ios::out|std::ios::app);
do{
st.create_student();
file1.write((char*)&st,sizeof(student));
std::cout<<"\n\ndo you want to add more record..(y/n?)";
std::cin>>ch;
}while(ch=='y'||ch=='Y');
file1.close();
}
//***************************************************************
// function to read specific record from file
//****************************************************************
{
system("cls");
std::cout<<"\nBOOK DETAILS\n";
int flag=0;
std::fstream file2;
file2.open("book.dat",std::ios::in);
while(file2.read((char*)&bk,sizeof(book)))
{
if(strcmpi(bk.retbno(),n)==0)
{
bk.show_book();
flag=1;
}
}
file2.close();
if(flag==0)
std::cout<<"\n\nBook does not exist";
getch();
}
if((strcmpi(st.retadmno(),n)==0))
{
st.show_student();
flag=1;
}
}
file3.close();
if(flag==0)
std::cout<<"\n\nStudent does not exist";
getch();
}
//***************************************************************
// function to modify record of file
//****************************************************************
void modify_book()
{
system("cls");
char n[6];
int found=0;
std::cout<<"\n\n\tMODIFY BOOK REOCORD.... ";
std::cout<<"\n\n\tEnter The book no. of The book";
std::cin>>n;
std::fstream file4;
file4.open("book.dat",std::ios::in|std::ios::out);
while(file4.read((char*)&bk,sizeof(book)) && found==0)
{
if(strcmpi(bk.retbno(),n)==0)
{
bk.show_book();
std::cout<<"\nEnter The New Details of book";
bk.modify_book();
int pos=-1*sizeof(bk);
file4.seekp(pos,std::ios::cur);
file4.write((char*)&bk,sizeof(book));
std::cout<<"\n\n\t Record Updated";
found=1;
}
}
file4.close();
if(found==0)
std::cout<<"\n\n Record Not Found ";
getch();
}
void modify_student()
{
system("cls");
char n[6];
int found=0;
file5.open("student.dat",std::ios::in|std::ios::out);
while(file5.read((char*)&st,sizeof(student)) && found==0)
{
if(strcmpi(st.retadmno(),n)==0)
{
st.show_student();
std::cout<<"\nEnter The New Details of student";
st.modify_student();
int pos=-1*sizeof(st);
file5.seekp(pos,std::ios::cur);
file5.write((char*)&st,sizeof(student));
std::cout<<"\n\n\t Record Updated";
found=1;
}
}
file5.close();
if(found==0)
std::cout<<"\n\n Record Not Found ";
getch();
}
//***************************************************************
// function to delete record of file
//****************************************************************
void delete_student()
{
system("cls");
char n[6];
int flag=0;
std::cout<<"\n\n\n\tDELETE STUDENT...";
std::cout<<"\n\nEnter The admission no. of the Student You Want To
Delete : ";
std::cin>>n;
std::fstream file6;
file6.open("student.dat",std::ios::in|std::ios::out);
std::fstream fp2;
fp2.open("Temp.dat",std::ios::out);
file6.seekg(0,std::ios::beg);
while(file6.read((char*)&st,sizeof(student)))
{
if(strcmpi(st.retadmno(),n)!=0)
fp2.write((char*)&st,sizeof(student));
else
flag=1;
}
fp2.close();
file6.close();
remove("student.dat");
rename("Temp.dat","student.dat");
if(flag==1)
std::cout<<"\n\n\tRecord Deleted ..";
else
std::cout<<"\n\nRecord not found";
getch();
}
void delete_book()
{
system("cls");
char n[6];
std::cout<<"\n\n\n\tDELETE BOOK ...";
std::cout<<"\n\nEnter The Book no. of the Book You Want To Delete : ";
std::cin>>n;
std::fstream file7;
file7.open("book.dat",std::ios::in|std::ios::out);
std::fstream fp2;
fp2.open("Temp.dat",std::ios::out);
file7.seekg(0,std::ios::beg);
while(file7.read((char*)&bk,sizeof(book)))
{
if(strcmpi(bk.retbno(),n)!=0) //change later
fp2.write((char*)&bk,sizeof(book));
}
fp2.close();
file7.close();
remove("book.dat");
rename("Temp.dat","book.dat");
std::cout<<"\n\n\tRecord Deleted ..";
getch();
}
//***************************************************************
// function to display all students list
//****************************************************************
void display_alls()
{
system("cls");
std::fstream file8;
file8.open("student.dat",std::ios::in);
if(!file8)
{
std::cout<<"ERROR!!! FILE COULD NOT BE OPEN ";
getch();
return;
}
std::cout<<"\n\n\t\tSTUDENT LIST\n\n";
std::cout<<"=========================================
=========================\n";
std::cout<<"\tAdmission
No."<<std::setw(10)<<"Name"<<std::setw(20)<<"Book Issued\n";
std::cout<<"=========================================
=========================\n";
while(file8.read((char*)&st,sizeof(student)))
st.report();
file8.close();
getch();
}
//***************************************************************
// function to display Books list
//****************************************************************
void display_allb()
{
system("cls");
std::fstream file9;
file9.open("book.dat",std::ios::in);
if(!file9)
{
std::cout<<"ERROR!!! FILE COULD NOT BE OPEN ";
getch();
return;
}
std::cout<<"\n\n\t\tBook LIST\n\n";
std::cout<<"=========================================
================================\n";
std::cout<<"Book Number"<<std::setw(20)<<"Book
Name"<<std::setw(25)<<"Author\n";
std::cout<<"=========================================
================================\n";
while(file9.read((char*)&bk,sizeof(book)))
bk.report();
file9.close();
getch();
}
//***************************************************************
// function to issue book
//****************************************************************
void book_issue()
{
system("cls");
char sn[6],bn[6];
int found=0,flag=0;
std::cout<<"\n\nBOOK ISSUE ...";
std::cout<<"\n\n\tEnter The student's admission no.";
std::cin>>sn;
std::fstream file10;
file10.open("student.dat",std::ios::in|std::ios::out);
std::fstream fp1;
fp1.open("book.dat",std::ios::in|std::ios::out);
while(file10.read((char*)&st,sizeof(student)) && found==0)
{
if(strcmpi(st.retadmno(),sn)==0)
{
found=1;
if(st.rettoken()==0)
{
std::cout<<"\n\n\tEnter the book no. ";
std::cin>>bn;
while(fp1.read((char*)&bk,sizeof(book))&& flag==0)
{
if(strcmpi(bk.retbno(),bn)==0)
{
bk.show_book();
flag=1;
st.addtoken();
st.getstbno(bk.retbno());
int pos=-1*sizeof(st);
file10.seekp(pos,std::ios::cur);
file10.write((char*)&st,sizeof(student));
std::cout<<"\n\n\t Book issued
successfully\n\nPlease Note: Write the current date in backside of your book and
submit within 15 days, fine Rs. 1 for each day after 15 days period";
}
}
if(flag==0)
std::cout<<"Book no does not exist";
}
else
std::cout<<"You have not returned the last book ";
}
}
if(found==0)
std::cout<<"Student record not exist...";
getch();
file10.close();
fp1.close();
}
//***************************************************************
// function to deposit book
//****************************************************************
void book_deposit()
{
system("cls");
char sn[6],bn[6];
int found=0,flag=0,day,fine;
system("cls");
std::cout<<"\n\nBOOK DEPOSIT ...";
std::cout<<"\n\n\tEnter The students admission no.";
std::cin>>sn;
std::fstream file11;
file11.open("student.dat",std::ios::in|std::ios::out);
std::fstream fp2;
std::fstream fp1;
fp2.open("book.dat",std::ios::in|std::ios::out);
while(file11.read((char*)&st,sizeof(student)) && found==0)
{
if(strcmpi(st.retadmno(),sn)==0)
{
found=1;
if(st.rettoken()==1)
{
while(fp1.read((char*)&bk,sizeof(book))&& flag==0)
{
if(strcmpi(bk.retbno(),st.retstbno())==0)
{
bk.show_book();
flag=1;
std::cout<<"\n\nBook deposited in no. of
days";
std::cin>>day;
if(day>15)
{
fine=(day-15)*1;
std::cout<<"\n\nFine has to
deposited Rs. "<<fine;
}
st.resettoken();
int pos=-1*sizeof(st);
file11.seekp(pos,std::ios::cur);
file11.write((char*)&st,sizeof(student));
std::cout<<"\n\n\t Book deposited
successfully";
}
}
if(flag==0)
std::cout<<"Book no does not exist";
}
else
std::cout<<"No book is issued..please check!!";
}
}
if(found==0)
void admin_menu()
{
system("cls");
int ch2;
std::cout<<"\n\n\n\t*************ADMINISTRATOR MENU***************";
std::cout<<"\n\n\t1.CREATE STUDENT RECORD";
std::cout<<"\n\n\t2.DISPLAY ALL STUDENTS RECORD";
std::cout<<"\n\n\t3.DISPLAY SPECIFIC STUDENT RECORD ";
std::cout<<"\n\n\t4.MODIFY STUDENT RECORD";
std::cout<<"\n\n\t5.DELETE STUDENT RECORD";
std::cout<<"\n\n\t6.CREATE BOOK ";
std::cout<<"\n\n\t7.DISPLAY ALL BOOKS ";
std::cout<<"\n\n\t8.DISPLAY SPECIFIC BOOK ";
std::cout<<"\n\n\t9.MODIFY BOOK ";
std::cout<<"\n\n\t10.DELETE BOOK ";
std::cout<<"\n\n\t11.BACK TO MAIN MENU";
std::cout<<"\n\n\tPlease Enter Your Choice (1-11) ";
std::cin>>ch2;
switch(ch2)
{
case 1: write_student();
break;
case 2: display_alls();
break;
case 3:
char num[6];
std::cout<<"\n\n\tPlease Enter The Admission No. ";
std::cin>>num;
display_sps(num);
break;
case 4: modify_student();
break;
case 5: delete_student();
break;
case 6:
write_book();
break;
case 7: display_allb();
break;
case 8: {
char num[6];
system("cls");
std::cout<<"\n\n\tPlease Enter The book No. ";
std::cin>>num;
display_spb(num);
break;
}
case 9: modify_book();
break;
case 10: delete_book();
break;
case 11: return;
default:std::cout<<"Wrong Choice";
break;
}
admin_menu();
}
void intro()
{
for(int i=0;i<=10;i++)
{
std::cout<<"\n\n\n\n\n\n\t\t\t\tWELCOME \n\n\t\t\t\t TO \n\n\t\t\t\t C+
+\n\n\n\t\t\t\tPROJECT";
std::cout<<"\n\n\n\n\n\n\t\t\t\t************************";
std::cout<<"\n\t\t\t\t**LOADING YOUR PROJECT**";
std::cout<<"\n\t\t\t\t************************";
std::cout<<"\n\n\t\t\t\t\tPLEASE WAIT.........";
std::cout<<"\n\n\n\n\n\t\t\t\t\t\t";
std::cout<<i*10<<" % completed...";
delay(i*80);
system("cls");
}
std::cout<<"\n\n\n\n\n\n\t\t\t\t LIBRARY \n\n\t\t\t\tMANAGEMENT\n\n\t\t\t\t
SYSTEM\n\n\n\t\t\t\t\tBy::\n\t\t\t\t\t\tOM TIWARI";
std::cout<<"\n\n\n\n\n\n\n\n\n\t\t\t\t\t\t Press enter to continue.....";
getch();
}
//***************************************************************
// THE MAIN FUNCTION OF PROGRAM
//****************************************************************
using namespace std;
int main()
{
system("cls");
intro();
char ch;
std::cout<<"\n\n\n\n\t\t\tLIBRARY \n\n\n\t\t\t MANAGEMENT\n\n\n\t\t\t
SYSTEM";
std::cout<<"\n\n\t\t\t\t\t\tMADE BY :: \n\n\t\t\t\t\t\t\t\tOM TIWARI ";
getch();
do
{
system("cls");
std::cout<<"\n\n\n\t*****************MAIN MENU****************";
std::cout<<"\n\n\t01. BOOK ISSUE";
std::cout<<"\n\n\t02. BOOK DEPOSIT";
std::cout<<"\n\n\t03. ADMINISTRATOR MENU";
std::cout<<"\n\n\t04. EXIT";
std::cout<<"\n\n\tPlease Select Your Option (1-4) ";
ch=getche();
switch(ch)
{
case '1':book_issue();
break;
case '2': book_deposit();
break;
case '3':admin_menu();
break;
case '4':exit(0);
default :cout<<"\n\nWrong choice";
break;
}
}while(ch!='4'&&ch<='3'&&ch>='1');
getch();
}
//***************************************************************
// END OF PROJECT
//*************************************
OUTPUT:-