You are on page 1of 44

COMPUTER SCIENCE PROJECT 2016-17

LIBRARY MANAGEMENT SYSTEM

DONE BY:
AKSHAY
RAMAKRISHNAN

XII-E1
ROLL NUMBER- 4
(Affiliated to Central Board of Secondary Education, New Delhi)

(Chettinad House, R.A.Puram, Chennai 600 028)

COMPUTER SCIENCE

Certified to be the Bonafide Record of work done by

________________________________________ of Std XII Sec _____

in the Computer Science Lab of the CHETTINAD VIDYASHRAM,

CHENNAI, during the year 2016 2017.

Date: Teacher-in-charge
REGISTER NO. ____________________

Submitted for All India Senior Secondary Practical Examination in

Computer Science held on ______________________________at

Chettinad Vidyashram, Chennai 600 028.

Principal Internal Examiner External Examiner


ACKNOWLEDGEMENT

I would like to express my sincere thanks to Meena Aunty, Principal

Mrs. S.Amudhalakshmi for their encouragement and support to work on

this Project. I am grateful to my computer science teacher Mrs. V.

Mala and to the computer science department for the constant guidance

and support to complete the project.


TABLE OF CONTENTS:-

SL.NO. TOPIC PAGE


1. Overview of C++ and OOPs
2. Project description
3. Functions and files used.
4. Source code
5. Sample outputs
6. Conclusions
7. Bibliography
OVERVIEW OF C++ AND OBJECT ORIENTED
PROGRAMMING:-
C++ is a statically typed, compiled, general-purpose, case-sensitive,
free-form programming language that supports procedural, object-
oriented, and generic programming. It is regarded as a middle-
level language, as it comprises a combination of both high-level and low-
level language features. C++ was developed by Bjarne Stroustrup
starting in 1979 at Bell Labs in Murray Hill, New Jersey, as an
enhancement to the C language and originally named C with Classes but
later it was renamed C++ in 1983. C++ is a superset of C, and that
virtually any legal C program is a legal C++ program.

Note: A programming language is said to use static typing when type


checking is performed during compile-time as opposed to run-time.

Standard C++ consists of three important parts:

The core language giving all the building blocks including variables, data
types and literals, etc.

The C++ Standard Library giving a rich set of functions manipulating files,
strings, etc.

The Standard Template Library (STL) giving a rich set of methods


manipulating data structures, etc.

The ANSI standard is an attempt to ensure that C++ is portable -- that


code you write for Microsoft's compiler will compile without errors, using
a compiler on a Mac, UNIX, a Windows box, or an Alpha. The ANSI
standard has been stable for a while, and all the major C++ compiler
manufacturers support the ANSI standard.

The most important thing to do when learning C++ is to focus on


concepts and not get lost in language technical details. The purpose of
learning a programming language is to become a better programmer;
that is, to become more effective at designing and implementing new
systems and at maintaining old ones. C++ supports a variety of
programming styles. You can write in the style of Fortran, C, Smalltalk,
etc., in any language. Each style can achieve its aims effectively while
maintaining runtime and space efficiency.

C++ is used by hundreds of thousands of programmers in essentially


every application domain. It is being highly used to write device drivers
and other soft wares that rely on direct manipulation of hardware under
real-time constraints. It is widely used for teaching and research because
it is clean enough for successful teaching of basic concepts.

Anyone who has used either an Apple Macintosh or a PC running


Windows has indirectly used C++ because the primary user interfaces of
these systems are written in that language.

Object Oriented programming is a programming style that is associated with the concept of
Class, Objects and various other concepts revovling around these two, like Inheritance,
Polymorphism, Abstraction, Encapsulation etc.

Here are some of the main features of Object Oriented Programming which you will be using in
C++:

1. Objects 5. Inheritance

2. Overloading 6. Abstraction

3. Exception Handling 7. Encapsulation


4. Classes

Objects:
Objects are the basic unit of OOP. They are instances of class, which have data members and
uses various member functions to perform tasks.

Class
It is similar to structures in C language. Class can also be defined as user defined data type but it
also contains functions in it. So, class is basically a blueprint for object. It declare & defines what
data variables the object will have and what operations can be performed on the class's object.

Abstraction
Abstraction refers to showing only the essential features of the application and hiding the details.
In C++, classes provide methods to the outside world to access & use the data variables, but the
variables are hidden from direct access. This can be done access specifiers.

Encapsulation
It can also be said data binding. Encapsulation is all about binding the data variables and
functions together in class.

Inheritance
Inheritance is a way to reuse once written code again and again. The class which is inherited is
called base calls & the class which inherits is called derived class. So when, a derived class
inherits a base class, the derived class can use all the functions which are defined in base class,
hence making code reusable.

Polymorphism
It is a feature, which lets us create functions with same name but different arguments, which will
perform differently. That is function with same name, functioning in different way. Or, it also
allows us to redefine a function to provide its new definition. You will learn how to do this in
details soon in coming lessons.

Exception Handling
Exception handling is a feature of OOP, to handle unresolved exceptions or errors produced at
runtime.

Project description:
This project has been created with the aim that this would
simply the management of books and account in a library.
Several factors such as user accounts, number of books issued,
number of books deposited have been taken into account in
this project. This project also contains an administrators menu
which would give him absolute access to all the contents of the
program.
Library management is a very tedious process considering the
large volume of books as well as library accounts. These
information cannot be managed by hand by a librarian as such.
That is why this project is essential for the librarian in order to
efficiently manage these records.
This project has two main blocks as already stated above:
1. Student block:
This block takes care all of the users which have accounts
in the library. This keeps track of what books have been
taken by each user, the books which have been deposited,
the number of users, etc. The administrator will have
access to these records and can also add or delete users
as well as view the books that have been issued or
deposited.
2. Books block:
This block maintains a catalogue as to what books are
present in the library. It gives a list of all the books that
are available for users to borrow. Here also the
administrator has been given sole access to these records
and can add or delete books from the library.
Functions used:
1. create_book() To update existing book records.
2. show_book() To display the book.
3. modify_book() To modify contents of a book.
4. retbno() To return the book number
5. report() To display the content of one book record
Function 1-5 under class book.
6. create_student() To create a student user record.
7. show_student() To display the student user record.
8. modify_student() To modify student name.
9. retadmno() To return admission number.
10. retstbno() To return book number.
11. rettoken() To return token value.
12. addtoken() To initialize token value to 1 to
indicate presence of record.

13. resettoken() To reset token value to 0 to indicate


absence of record.
14. getstbno(char t[]) To assign book number
15. report() To display content of one student record.
Function 6-15 under class student
16. graph() To execute the graphic code given under
this function.
17. write_book() To write book records to file.
18. write_student() To write student records to file.
19. display_spb(char n[]) - To read specific book
record from file.
20. display_sps(char n[]) To read specific student
record from file.
21. modify_book() To modify record from file
22. modify_student() To modify record from file.
23. delete_student() and delete_book()- To delete
record from file.
24. display_alls() - To display all students list.
25. display_allb() To display all books list.
26. book_issue() To issue book.
27. book_deposit() To deposit book.
28. intro() Introduction function.
29. admin_menu() Gives the administrators menu.
30. main() Main function of program.
Files used:
1. book.dat: Used to store catalogue of
books and manipulate them according to
administrators decision.
2. student.dat: Used to store a list of
students and perform operations on them.
3. temp.dat: Used a temporary file for
deletion of record.
SOURCE CODE:
//*************************************************
**************
// HEADER FILE USED IN PROJECT
//*************************************************
***************

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

//*************************************************
**************
// CLASS USED IN PROJECT
//*************************************************
***************

class book
{
char bno[6];
char bname[50];
char aname[20];
public:
void create_book()
{
cout<<"\nNEW BOOK ENTRY...\n";
cout<<"\nEnter The book no.";
cin>>bno;
cout<<"\n\nEnter The Name of The Book ";
gets(bname);
cout<<"\n\nEnter The Author's Name ";
gets(aname);
cout<<"\n\n\nBook Created..";
}

void show_book()
{
cout<<"\nBook no. : "<<bno;
cout<<"\nBook Name : ";
puts(bname);
cout<<"Author Name : ";
puts(aname);
}

void modify_book()
{
cout<<"\nBook no. : "<<bno;
cout<<"\nModify Book Name : ";
gets(bname);
cout<<"\nModify Author's Name of Book : ";
gets(aname);
}

char* retbno()
{
return bno;
}

void report()

{cout<<bno<<setw(30)<<bname<<setw(30)<<aname<<end
l;}

}; //class ends here

class student
{
char admno[6];
char name[20];
char stbno[6];
int token;
public:
void create_student()
{
clrscr();
cout<<"\nNEW STUDENT ENTRY...\n";
cout<<"\nEnter The admission no. ";
cin>>admno;
cout<<"\n\nEnter The Name of The Student ";
gets(name);
token=0;
stbno[0]='/0';
cout<<"\n\nStudent Record Created..";
}

void show_student()
{
cout<<"\nAdmission no. : "<<admno;
cout<<"\nStudent Name : ";
puts(name);
cout<<"\nNo of Book issued : "<<token;
if(token==1)
cout<<"\nBook No "<<stbno;
}
void modify_student()
{
cout<<"\nAdmission no. : "<<admno;
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()

{cout<<"\t"<<admno<<setw(20)<<name<<setw(10)<<toke
n<<endl;}

}; //class ends here

//*************************************************
**************
// global declaration for stream object, object
//*************************************************
***************

fstream fp,fp1;
book bk;
student st;
//*************************************************
**************
// function to write in file
//*************************************************
***************

void graph()
{
int y;
int x[5];

for(x[0]=50,x[1]=100,x[2]=200,x[3]=400,x[4]=500,y=450;y
>=240;y=y-10,x[0]=x[0]+13,x[2]=x[2]+6,x[1]+=11,x[3]-
=4,x[4]-=9)
{
fillellipse(x[0],y,20,20);setfillstyle(1,GREEN);
fillellipse(x[1],y,20,20); setfillstyle(1,YELLOW);
fillellipse(x[2],y+10,20,20);setfillstyle(1,WHITE);
fillellipse(300,y-15,20,20); setfillstyle(1,6);
fillellipse(x[3],y-5,20,20); setfillstyle(1,BLUE);
fillellipse(x[4],y+20,20,20); setfillstyle(1,CYAN);

clearviewport();
for(int c=440;c<480;++c)
{
setlinestyle(0,1,3);setcolor(BLACK);
line(0,c,325,480);
line(680,c,325,480); }
delay(20);
}

for(int c=0;c<150;++c)
{
setcolor(BLACK);
fillellipse(325,240,c*1.5,c);
delay(10);
}

clearviewport();
}
void write_book()
{
char ch;
fp.open("book.dat",ios::out|ios::app);
do
{
clrscr();
bk.create_book();
fp.write((char*)&bk,sizeof(book));
cout<<"\n\nDo you want to add more record..
(y/n?)";
cin>>ch;
}while(ch=='y'||ch=='Y');
fp.close();
}
void write_student()
{
char ch;
fp.open("student.dat",ios::out|ios::app);
do
{
st.create_student();
fp.write((char*)&st,sizeof(student));
cout<<"\n\ndo you want to add more record..
(y/n?)";
cin>>ch;
}while(ch=='y'||ch=='Y');
fp.close();
}

//*************************************************
**************
// function to read specific record from file
//*************************************************
***************

void display_spb(char n[])


{
cout<<"\nBOOK DETAILS\n";
int flag=0;
fp.open("book.dat",ios::in);
while(fp.read((char*)&bk,sizeof(book)))
{
if(strcmpi(bk.retbno(),n)==0)
{
bk.show_book();
flag=1;
}
}

fp.close();
if(flag==0)
cout<<"\n\nBook does not exist";
getch();
}

void display_sps(char n[])


{
cout<<"\nSTUDENT DETAILS\n";
int flag=0;
fp.open("student.dat",ios::in);
while(fp.read((char*)&st,sizeof(student)))
{
if((strcmpi(st.retadmno(),n)==0))
{
st.show_student();
flag=1;
}
}

fp.close();
if(flag==0)
cout<<"\n\nStudent does not exist";
getch();
}

//*************************************************
**************
// function to modify record of file
//*************************************************
***************

void modify_book()
{
char n[6];
int found=0;
clrscr();
cout<<"\n\n\tMODIFY BOOK REOCORD.... ";
cout<<"\n\n\tEnter The book no. of The book";
cin>>n;
fp.open("book.dat",ios::in|ios::out);
while(fp.read((char*)&bk,sizeof(book)) && found==0)
{
if(strcmpi(bk.retbno(),n)==0)
{
bk.show_book();
cout<<"\nEnter The New Details of
book"<<endl;
bk.modify_book();
int pos=-1*sizeof(bk);
fp.seekp(pos,ios::cur);
fp.write((char*)&bk,sizeof(book));
cout<<"\n\n\t Record Updated";
found=1;
}
}

fp.close();
if(found==0)
cout<<"\n\n Record Not Found ";
getch();
}

void modify_student()
{
char n[6];
int found=0;
clrscr();
cout<<"\n\n\tMODIFY STUDENT RECORD... ";
cout<<"\n\n\tEnter The admission no. of The student";
cin>>n;
fp.open("student.dat",ios::in|ios::out);
while(fp.read((char*)&st,sizeof(student)) && found==0)
{
if(strcmpi(st.retadmno(),n)==0)
{
st.show_student();
cout<<"\nEnter The New Details of
student"<<endl;
st.modify_student();
int pos=-1*sizeof(st);
fp.seekp(pos,ios::cur);
fp.write((char*)&st,sizeof(student));
cout<<"\n\n\t Record Updated";
found=1;
}
}

fp.close();
if(found==0)
cout<<"\n\n Record Not Found ";
getch();
}
//*************************************************
**************
// function to delete record of file
//*************************************************
***************

void delete_student()
{
char n[6];
int flag=0;
clrscr();
cout<<"\n\n\n\tDELETE STUDENT...";
cout<<"\n\nEnter The admission no. of the Student You
Want To Delete : ";
cin>>n;
fp.open("student.dat",ios::in|ios::out);
fstream fp2;
fp2.open("Temp.dat",ios::out);
fp.seekg(0,ios::beg);
while(fp.read((char*)&st,sizeof(student)))
{
if(strcmpi(st.retadmno(),n)!=0)
fp2.write((char*)&st,sizeof(student));
else
flag=1;
}

fp2.close();
fp.close();
remove("student.dat");
rename("Temp.dat","student.dat");
if(flag==1)
cout<<"\n\n\tRecord Deleted ..";
else
cout<<"\n\nRecord not found";
getch();
}

void delete_book()
{
char n[6];
clrscr();
cout<<"\n\n\n\tDELETE BOOK ...";
cout<<"\n\nEnter The Book no. of the Book You Want To
Delete : ";
cin>>n;
fp.open("book.dat",ios::in|ios::out);
fstream fp2;
fp2.open("Temp.dat",ios::out);
fp.seekg(0,ios::beg);
while(fp.read((char*)&bk,sizeof(book)))
{
if(strcmpi(bk.retbno(),n)!=0)
{
fp2.write((char*)&bk,sizeof(book));
}
}

fp2.close();
fp.close();
remove("book.dat");
rename("Temp.dat","book.dat");
cout<<"\n\n\tRecord Deleted ..";
getch();
}

//*************************************************
**************
// function to display all students list
//*************************************************
***************

void display_alls()
{
clrscr();
fp.open("student.dat",ios::in);
if(!fp)
{
cout<<"ERROR!!! FILE COULD NOT BE OPEN ";
getch();
return;
}

cout<<"\n\n\t\tSTUDENT LIST\n\n";

cout<<"==================================
================================\n";
cout<<"\tAdmission
No."<<setw(10)<<"Name"<<setw(20)<<"Book Issued\n";

cout<<"==================================
================================\n";

while(fp.read((char*)&st,sizeof(student)))
{
st.report();
}

fp.close();
getch();
}

//*************************************************
**************
// function to display Books list
//*************************************************
***************

void display_allb()
{
clrscr();
fp.open("book.dat",ios::in);
if(!fp)
{
cout<<"ERROR!!! FILE COULD NOT BE OPEN ";
getch();
return;
}

cout<<"\n\n\t\tBook LIST\n\n";

cout<<"==================================
=======================================
\n";
cout<<"Book Number"<<setw(20)<<"Book
Name"<<setw(25)<<"Author\n";

cout<<"==================================
=======================================
\n";

while(fp.read((char*)&bk,sizeof(book)))
{
bk.report();
}
fp.close();
getch();
}

//*************************************************
**************
// function to issue book
//*************************************************
***************

void book_issue()
{
char sn[6],bn[6];
int found=0,flag=0;
clrscr();
cout<<"\n\nBOOK ISSUE ...";
cout<<"\n\n\tEnter The student's admission no.";
cin>>sn;
fp.open("student.dat",ios::in|ios::out);
fp1.open("book.dat",ios::in|ios::out);
while(fp.read((char*)&st,sizeof(student)) && found==0)
{
if(strcmpi(st.retadmno(),sn)==0)
{
found=1;
if(st.rettoken()==0)
{
cout<<"\n\n\tEnter the book no. ";
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);
fp.seekp(pos,ios::cur);

fp.write((char*)&st,sizeof(student));
cout<<"\n\n\t Book issued
successfully\n\nPlease Note: Write current data in backside of
book and submit within 15 days fine Rs. 1 for each day after 15
days period";
}
}
if(flag==0)
cout<<"Book no does not exist";
}
else
cout<<"You have not returned the last
book ";

}
}
if(found==0)
cout<<"Student record not exist...";
getch();
fp.close();
fp1.close();
}

//*************************************************
**************
// function to deposit book
//*************************************************
***************

void book_deposit()
{
char sn[6],bn[6];
int found=0,flag=0,day,fine;
clrscr();
cout<<"\n\nBOOK DEPOSIT ...";
cout<<"\n\n\tEnter The students admission no.";
cin>>sn;
fp.open("student.dat",ios::in|ios::out);
fp1.open("book.dat",ios::in|ios::out);
while(fp.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;
cout<<"\n\nBook deposited in no. of
days";
cin>>day;
if(day>15)
{
fine=(day-15)*1;
cout<<"\n\nFine has to deposited Rs.
"<<fine;
}
st.resettoken();
int pos=-1*sizeof(st);
fp.seekp(pos,ios::cur);
fp.write((char*)&st,sizeof(student));
cout<<"\n\n\t Book deposited
successfully";
}
}
if(flag==0)
cout<<"Book no does not exist";
}
else
cout<<"No book is issued..please check!!";
}
}
if(found==0)
cout<<"Student record not exist...";
getch();
fp.close();
fp1.close();
}

//*************************************************
**************
// INTRODUCTION FUNCTION
//*************************************************
***************

void intro()
{

delay(200);
gotoxy(35,11);
cout<<"LIBRARY";
gotoxy(35,14);
cout<<"MANAGEMENT";
gotoxy(35,17);
cout<<"SYSTEM";
cout<<"\n\nMADE BY : SWARAN IYAPPAN,AKSHAY
RAMAKRISHNAN AND AJAY ADHITYA";
cout<<"\n\nSCHOOL : CHETTINAD VIDYASHRAM";
getch();
}

//*************************************************
**************
// ADMINISTRATOR MENU FUNCTION
//*************************************************
***************

void admin_menu()
{
clrscr();
int ch2;
cout<<"\n\n\n\tADMINISTRATOR MENU";
cout<<"\n\n\t1.CREATE STUDENT RECORD";
cout<<"\n\n\t2.DISPLAY ALL STUDENTS RECORD";
cout<<"\n\n\t3.DISPLAY SPECIFIC STUDENT RECORD ";
cout<<"\n\n\t4.MODIFY STUDENT RECORD";
cout<<"\n\n\t5.DELETE STUDENT RECORD";
cout<<"\n\n\t6.CREATE BOOK ";
cout<<"\n\n\t7.DISPLAY ALL BOOKS ";
cout<<"\n\n\t8.DISPLAY SPECIFIC BOOK ";
cout<<"\n\n\t9.MODIFY BOOK ";
cout<<"\n\n\t10.DELETE BOOK ";
cout<<"\n\n\t11.BACK TO MAIN MENU";
cout<<"\n\n\tPlease Enter Your Choice (1-11) ";
cin>>ch2;
switch(ch2)
{
case 1: clrscr();
write_student();break;
case 2: display_alls();break;
case 3:
char num[6];
clrscr();
cout<<"\n\n\tPlease Enter The Admission No. ";
cin>>num;
display_sps(num);
break;
case 4: modify_student();break;
case 5: delete_student();break;
case 6: clrscr();
write_book();break;
case 7: display_allb();break;
case 8: {
char num[6];
clrscr();
cout<<"\n\n\tPlease Enter The book No. ";
cin>>num;
display_spb(num);
break;
}
case 9: modify_book();break;
case 10: delete_book();break;
case 11: return;
default:cout<<"\a";
}
admin_menu();
}

//*************************************************
**************
// THE MAIN FUNCTION OF PROGRAM
//*************************************************
***************

void main()
{ clrscr();
int gdriver=DETECT,gmode;

initgraph(&gdriver,&gmode,"c:\\turboc3\\bgi");
graph();
char ch;
intro();
do
{
clrscr();
cout<<"\n\n\n\tMAIN MENU";
cout<<"\n\n\t01. BOOK ISSUE";
cout<<"\n\n\t02. BOOK DEPOSIT";
cout<<"\n\n\t03. ADMINISTRATOR MENU";
cout<<"\n\n\t04. EXIT";
cout<<"\n\n\tPlease Select Your Option (1-4) ";
ch=getche();
switch(ch)
{
case '1':clrscr();
book_issue();
break;
case '2':book_deposit();
break;
case '3':admin_menu();
break;
case '4':exit(0);
default :cout<<"\a";
}
}while(ch!='4');
}

//*************************************************
**************
// END OF PROJECT
//*************************************************
**************
SAMPLE OUTPUTS:
CONCLUSIONS:
This project can be put to great use by major
libraries. Also commercialisation of projects like
these would in fact reduce our dependence on
notebooks and make it easier to manage records.
BIBLIOGRAPHY:
1. www.cplusplus.com
2. www.tutorialspoint.com
3. www.daniweb.com
4. www.crazyengineers.com
5. www.stackoverflow.com