Top Banner
KENDRIYA VIDYALAYA, NO.1, MADURAI
45

Library management

Aug 27, 2014

Download

Software

Vishnurockks

A project on a "Library Management System" .
This includes the coding in C - Language for the software used to manage a library.
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Library management

KENDRIYA VIDYALAYA, NO.1, MADURAI

Page 2: Library management

LIBRARY MANAGEMENT

SYSTEM

COMPUTER SCIENCE INVESTIGATORY

PROJECT

SUBMITTED BY

Under the guidance of

MR. AMAN GUPTA

KENDRIYA VIDYALAYA NO 1, NARIMEDU, MADURAI-625002

Page 3: Library management

KENDRIYA VIDYALAYA (NO 1)

NARIMEDU MADURAI-625002

COMPUTER SCIENCE

2013-2014

BONA FIDE CERTIFICATE

This is to certify that this project entitled “LIBRARY

MANAGEMENT SYSTEM” is a record of bona fide work carried

out by Vishnuprasad.V.P in Computer Science

prescribed by Kendriya Vidyalaya, Narimedu, Madurai -

625002.

ROLL NUMBER: DATE :

INTERNAL EXAMINER : PRINCIPAL : EXTERNAL EXAMINER :

Page 4: Library management

DECLARATION

I hereby declare that the project work entitled

“LIBRARY MANAGEMENT SYSTEM” submitted to KENDRIYA

VIDYALAYA NO.1, MADURAI for the subject Computer Science

under the guidance of MR. AMAN GUPTA is a record of

original work done by me. I further declare that this

project or any part of it has not been submitted elsewhere

for any other class.

Class: Place: Date:

Page 5: Library management

ACKNOWLEDGEMENT

First and foremost, I praise and thank the god almighty from the

bottom of my heart, he who has been an unfailing source of

strength, comfort and inspiration in the completion of this project

work.

I wish to express my sincere thanks to Mr.C.MUTHIAH

Principal, Kendriya Vidyalaya (No.1), Madurai, for the successful

outcome of this project work.

I wish to express my deep and profound sense of gratitude to my

teacher and guiding light Mr. AMAN GUPTA (PGT CS) for his

expert and valuable guidance, comments and suggestions.

I also express my gratitude to my parents and friends who have

helped me in preparing this project.

Page 6: Library management

CONTENTS

Introduction

Coding

Output

Bibliography

Page 7: Library management

Coding

#inc lude < ios tream.h>

# inc lude <fs tream.h> # inc lude <process .h>

# inc lude <s tr ing .h>

# inc lude <s td l ib .h> # inc lude <s td io .h>

# inc lude <c type .h> # inc lude <con io .h>

# inc lude<dos .h>

//S TRUC TURE THA T IN ITIA L IZES A LL THE VA RIA BLES

//____________________________________________

s truct data

{

int tcode ;

char tname[50] ;

char tauthor[50] ;

int tcop ies ;

f loat tpr ice ;

int tava i l ;

}b 1 ;

//CLA SS THA T CON TROLS A LL FUNCTIONS IN THE MENU

//_____________________________________________

c lass MENU {

pub l ic :

vo id introduct ion( ) ; vo id ma in_menu() ;

vo id ed it_menu() ;

vo id ed it_book( ) ;

vo id ed it_member() ;

vo id passw ord() ;

} ;

//CLA SS CON TA IN ING FUNCTIONS RELA TED TO BOOKS

Page 8: Library management

//___________________________________________

c lass BOOK

{

publ ic : vo id l is t (vo id) ;

char *bookname( int ) ; protected :

vo id add_new _book( int , char tname[33] , char tauthor[26] , f loat , int , in t ) ; vo id update_copies ( int , in t , in t ) ;

vo id de le t ion (vo id ) ;

in t book_found( int ) ;

in t bookname_found(char []) ;

in t recordno( int ) ;

in t ava i lab le( int ) ;

char *authorname(int ) ;

f loat bookpr ice( int ) ; in t no_of_copies ( int ) ;

in t bookcodeof (char[]) ; vo id d is p lay ( int ) ;

in t reccount(vo id) ;

pr ivate :

in t bookcode , cop ies ;

char name[40] , author[27] ; f loat pr ice ;

in t ava i l ; } ;

//CLA SS GOVERNING FUNCTIONS RELA TED TO MEMBERS

//____________________________________________

c lass MEMBER

{

pub l ic : vo id l is t (vo id) ;

protected :

vo id add_mem(int , int , char [] , char [] , char[] , int , in t , in t ) ; in t member_found( int ) ;

vo id update_book( int , int , in t , in t , in t ) ;

char *membername(int ) ;

char *memberphone( int ) ;

char *memberaddress ( int ) ;

in t recordno( int ) ;

in t las tcode(vo id ) ;

in t iss ued( int ) ;

in t f ine ( int ) ;

Page 9: Library management

vo id d is p lay ( int ) ;

vo id de le te_rec( int ) ;

pr ivate :

in t memcode , bookcode ;

char name[27] , phone[10] , address [50] ;

in t dd , mm, yy ; // DA TE OF RE TURNING THE BOOK // } ;

//CLA SS CON TA IN ING FUNCTIONS TO ISSUE, R E TURN A BOOK, ETC . . //_________________________________________________________

c lass WORKING : publ ic BOOK, pub l ic MEMBER

{

pub l ic :

vo id iss uebook(vo id ) ;

vo id returnbook(vo id) ; vo id add_book(vo id ) ;

vo id add_member(vo id ) ; vo id mod i fy_book(vo id) ;

vo id mod ify_member(vo id ) ;

vo id de le te_book(vo id ) ;

vo id de le te_member(vo id ) ;

} ;

//CLA SS CON TA IN ING FUNCTIONS RELA TED TO DA TE

//__________________________________________

c lass DA TE

{

pub l ic :

vo id extend_date( int , int , int , int ) ;

in t d if f ( int , in t , in t , in t , in t , in t ) ;

in t day , mon, year ; } ;

//FUNC TION TO EX TEND THE DA TE BY 15 DA YS

//______________________________________

vo id DA TE : : extend_date( int d 1 , in t m1 , int y 1 , in t days )

{

s tat ic int month[] = {3 1 ,29 ,3 1 ,30,3 1 ,30,3 1 ,3 1 ,30,3 1 ,30,3 1} ;

f or ( int i= 1 ; i<=days ; i++)

{

Page 10: Library management

d 1++ ;

i f ( (d 1 > month[m1 - 1 ]) | | (y 1%4 != 0 && m1 == 2 && d 1 > 28))

{

d 1 = 1 ;

m1++ ;

} i f (m1 > 12 )

{ m1 = 1 ;

y 1++ ; }

}

day = d 1 ;

mon = m1 ;

year = y 1 ;

}

//FUNC TION TO RE TURN THE D IFFERENCE B/W TW O DA TES

//_______________________________________________

int DA TE : : d i f f ( int d 1 , in t m1 , int y 1 , in t d2 , int m2 , int y2)

{

int days = 0 ; i f ( (y2<y1 ) | | (y2==y 1 && m2<m1) | | (y2==y1 && m2==m1 && d2<d1 ))

return days ; s tat ic int month[] = {3 1 ,29 ,3 1 ,30,3 1 ,30,3 1 ,3 1 ,30,3 1 ,30,3 1} ;

whi le (d 1 != d2 | | m 1 != m2 | | y 1 != y2)

{

days ++ ;

d 1++ ;

i f ( (d 1 > month[m1 - 1 ]) | | (y 1%4 != 0 && m1 == 2 && d 1 > 28))

{

d 1 = 1 ;

m1++ ;

} i f (m1 > 12 )

{

m1 = 1 ; y 1++ ;

}

}

return days ;

}

//FUNC TION TO D ISP LA Y MA IN MENU A ND CON TROL A LL THE FUNCTIONS P RESEN T IN I T

//_________________________________________________________________________

Page 11: Library management

vo id MENU: :ma in_menu()

{

w hi le ( 1 )

{ in t ch ;

c lrscr() ; gotoxy(26 ,2) ;

textbackground(W HITE ) ; textco lor(BLA CK) ;

cpr int f ("W ELCOME TO THE L IBRA RY OF CONGRESS") ;

textco lor(BLA CK) ;

gotoxy(26 ,3) ;

cout<<"***********************************" ;

gotoxy(3 1 ,7 ) ;

cout<<" 1 . IN TRODUC TION " ;

gotoxy(3 1 ,8) ; cout<<"2 . A DD NEW BOOK" ;

gotoxy(3 1 ,9) ; cout<<"3 . A DD NEW MEMBER" ;

gotoxy(3 1 , 10) ;

cout<<"4. ISSUE A BOOK" ;

gotoxy(3 1 , 1 1 ) ;

cout<<"5 . RETURN A BOOK" ; gotoxy(3 1 , 12 ) ;

cout<<"6 . L IS T OF BOOKS" ; gotoxy(3 1 , 13) ;

cout <<"7 . L IS T OF MEMBERS" ;

gotoxy(3 1 , 14) ;

cout <<"8. ED IT" ;

gotoxy(3 1 , 15 ) ;

cout <<"0. QUIT" ;

gotoxy(3 1 ,2 1) ;

cout <<"Enter your choice : " ;

c in>>ch ;

WORKING W ; sw itch(ch)

{

case 1 :

in troduct ion( ) ;

break;

case 2 :

W .add_book( ) ;

break;

Page 12: Library management

case 3 :

W .add_member() ;

break;

case 4 :

W . iss uebook() ; break;

case 5 :

W .returnbook() ;

break;

case 6:

BOOK B ;

B . l is t () ;

break;

case 7 :

MEMBER M ;

M . l is t () ;

break;

case 8:

password() ;

break;

case 0:

ex it (0) ;

de fau lt :

gotoxy(34, 17 ) ; cout<<"W RONG CHO ICE! !" ;

}

getch() ; }

}

//FUNC TION TO D ISP LA Y THE IN TRO DUC TION

//____________________________________

vo id MENU: : introduct ion( )

Page 13: Library management

{

c lrscr() ;

gotoxy(23 ,2) ;

cout<<"W ELCOME TO L IBRA RY MA NA GEMEN T SYS TEM" ;

gotoxy(23 ,3) ;

cout<<" . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . " ; gotoxy(30,5 ) ;

cout<<" THE L IBRA RY OF CONGRESS" ; gotoxy(30,6) ;

cout<<"_______________________" ; gotoxy(8,9) ;

cout <<" Th is is a pro jec t hav ing the fac i l i ty of mainta in ing the records" ;

gotoxy(29 , 1 1 ) ;

cout <<"of BOOKS and MEMBERS ." ;

gotoxy( 15 , 14) ;

cout <<" Th is pr o jec t can ho ld the records of more than " ;

gotoxy(33 , 16) ;

cout <<" 10,000 books " ; gotoxy(2 ,25 ) ;

cout<<"A UTHORS : K .M .Subangan Rao, V . Muthukr ishnan , V .P . V is hnuprasad" ;

gotoxy(27 ,20) ;

textco lor(W HITE ) ;

cout<<"P RESS A NY KEY TO CON TIN UE : " ;

textco lor(BLA CK+BLIN K) ; getch() ;

}

//FUNC TION TO GE T PA SSWORD

//_________________________

vo id MENU: : password()

{

char pass 1 ,pass2,pass3 ,ch ;

c lrscr() ; gotoxy(27 , 12 ) ;

cout<<"EN TER PA SSWORD : " ;

pass 1=getch() ; cout<<"*" ;

pass2=getch() ;

cout<<"*" ;

pass3=getch() ;

cout<<"*" ;

i f (pass 1==' l '&&pass2==' i '&&pass3=='b ' )

{

gotoxy(28, 13) ;

Page 14: Library management

cout<<"W RONG PA SSWORD! !" ;

main_menu() ;

}

e ls e

{

c lrscr() ; gotoxy(28, 13) ;

cout<<"W RONG PA SSWORD! !" ; }

}

//FUNC TION TO A SCERTA IN W HETHER THE BOOK CODE OR NA ME IS P RESEN T

//_____________________________________________________________

int BOOK : :book_found( int tcode)

{

fs tream f i le ; f i le .open("BOOK.DA T" , ios : : in ) ;

f i le .s eekg(0, ios : :beg) ; in t f ;

w hi le (f i le .read((char*)th is ,s izeof (BOOK)) )

{

i f (bookcode==tcode) {

f=1 ; break;

}

}

f i le .c los e() ;

re turn f ;

}

in t BOOK : : bookname_found(char t 1code[35])

{ fs tream f i le ;

f i le .open("BOOK.DA T" , ios : : in ) ;

f i le .s eekg(0, ios : :be g) ; in t g=0;

whi le (f i le .read((char*)th is ,s izeof (BOOK)) )

{

i f ( !s trcmpi(name, t 1code))

{

g=1 ;

break;

}

Page 15: Library management

}

f i le .c los e() ;

re turn g ;

}

//FUNC TION TO RE TURN THE RECORD NUMBER FOR A G IVEN BOOK //___________________________________ ___________________

int BOOK : : recordno( int t code)

{

fs tream f i le ;

f i le .open("BOOK.DA T" , ios : : in ) ;

f i le .s eekg(0, ios : :beg) ;

in t count=0 ;

whi le ( f i le .read((char *) th is , s izeof (BOOK)) )

{ count++ ;

i f (bookcode == tcode)

break ;

} f i le .c los e() ;

re turn count ; }

//FUNC TION TO RE TURN THE A VA ILA BLE COP IES FOR THE G IVEN BOOK CODE

//_______________________________________________________________

int BOOK : : ava i lab le( int tcode)

{

fs tream f i le ; f i le .open("BOOK.DA T" , ios : : in ) ;

f i le . s eekg(0, ios : :beg) ;

in t tava i l=0 ;

whi le ( f i le .read((char *) th is , s izeof (BOOK)) )

{

i f (bookcode == tcode)

{

tava i l = ava i l ;

break ;

}

}

Page 16: Library management

f i le .c los e() ;

re turn tava i l ;

}

//FUNC TION TO RE TURN THE NUMBER OF COP IES FOR THE G IVEN BOOK COD E //_______________________________________________________________

int BOOK : : no_of_copies ( int tcode) {

fs tream f i le ;

f i le .open("BOOK.DA T" , ios : : in ) ;

f i le .s eekg(0, ios : :beg) ;

in t tcop ies =0 ;

whi le ( f i le .read((char *) th is , s izeof (BOOK)) )

{ i f (bookcode == tcode)

{ tcop ies = cop ies ;

break ;

}

}

f i le .c los e() ; re turn tcop ies ;

}

//FUNC TION TO RE TURN BOOK NA ME OF THE G IVEN BOOK CODE

//___________________________________________________

char *BOOK : : bookname( int tcode)

{

fs tream f i le ;

f i le .open("BOOK.DA T" , ios : : in ) ; f i le .s eekg(0, ios : :beg) ;

char tname[33] ;

whi le ( f i le .read((char *) th is , s izeof (BOOK)) )

{

i f (bookcode == tcode)

{

s trcpy(tname,name) ;

break ;

}

}

f i le .c los e() ;

Page 17: Library management

re turn tname ;

}

//FUNC TION TO RE TURN THE NA ME OF THE A UTHOR FOR A GIVEN BOOK CODE

//_______________________________________________________________

char *BOOK : : authorname(int tcode)

{ fs tream f i le ;

f i le .open("BOOK.DA T" , ios : : in ) ;

f i le .s eekg(0, ios : :beg) ;

char tauthor[26] ;

whi le ( f i le .read((char *) th is , s izeof (BOOK)) )

{ i f (bookcode == tcode)

{ s trcpy(tauthor ,author) ;

break ;

}

}

f i le .c los e() ; re turn tauthor ;

}

//FUNC TION TO RE TURN THE P RICE OF A BOOK W HEN BOOK CODE IS EN TERED

//__________________ ______________________________________________

f loat BOOK : : bookpr ice( in t tcode)

{

fs tream f i le ;

f i le .open("BOOK.DA T" , ios : : in ) ; f i le .s eekg(0, ios : :beg) ;

f loat tpr ice=0.0 ;

whi le ( f i le .read((char *) th is , s izeof (BOOK)) )

{

i f (bookcode == tcod e)

{

tpr ice = pr ice ;

break ;

}

}

f i le .c los e() ;

Page 18: Library management

re turn tpr ice ;

}

//FUNC TION TO RE TURN THE BOOK CODE OF A GIVEN BOOK NA ME

//_____________________________________________________

int BOOK : : bookcodeof (char t 1code[33])

{ fs tream f i le ;

f i le .open("BOOK.DA T" , ios : : in ) ;

f i le .s eekg(0, ios : :beg) ;

in t tcode=0 ;

whi le ( f i le .read((char *) th is , s izeof (BOOK)) )

{

i f ( !s trcmpi(name, t 1code)) {

tcode = bookcode ; break ;

}

}

f i le .c los e() ;

re turn tcode ; }

//FUNC TION TO RE TURN THE NUMBER OF RECORDS IN THE F ILE

//____________________________________________________

int BOOK : : reccount(vo id)

{

fs tream f i le ;

f i le .open("BOOK.DA T" , ios : : in ) ;

f i le .s eekg(0, ios : :beg) ; in t count=0 ;

whi le ( f i le .read((char *) th is , s izeof (BOOK) ) ) count++ ;

f i le .c los e() ;

re turn count ;

}

//FUNC TION TO A DD A RECORD TO THE F ILE

//____________________________________

Page 19: Library management

void BOOK : : add_new _book( int tcode , char tname[33] , char tauthor[26] , f loat tpr ice , int tcop ies ,

int tava i l)

{

fs tream f i le ;

f i le .open("BOOK.DA T" , ios : :app , ios : :out ) ; bookcode = tcode ;

s trcpy(name,tname) ; s trcpy(author , tauthor) ;

pr ice = tpr ice ; cop ies = tcop ies ;

ava i l = tava i l ;

f i le .wr ite((char*)&b1 ,s izeof (b 1 )) ;

f i le .c los e() ;

}

//FUNC TION TO D ISP LA Y THE RECORDS FOR A GIVEN BOOK CODE //_____________________________________________________

vo id BOOK : : d is p lay( int tcode)

{

fs tream f i le ;

f i le .open("BOOK.DA T" , ios : : in ) ; f i le .s eekg(0, ios : :beg) ;

whi le ( f i le .read((char *) th is , s izeof (BOOK)) )

{

i f (bookcode == tcode)

{

gotoxy(5 ,5 ) ;

cout <<"Book Code : " <<bookcode ;

gotoxy(5 ,7) ;

cout <<"Book Name : " <<name ;

gotoxy(5 ,8) ;

cout <<"A uthor Name : " <<author ; gotoxy(5 ,9) ;

cout <<"P r ice : Rs ." <<pr ice ;

gotoxy(5 , 10) ; cout <<"No. of cop ies ex is t ing : " <<cop ies ;

gotoxy(5 , 1 1 ) ;

cout <<"No. of cop ies ava i lab le : " <<ava i l ;

break ;

}

}

f i le .c los e() ;

}

Page 20: Library management

//FUNC TION TO D ISP LA Y THE L IS T OF BOOKS

//_____________________________________

vo id BOOK : : l is t (vo id)

{ c lrscr() ;

in t row =6; gotoxy(32 ,2) ;

cout <<" L IS T OF BOOKS" ;

gotoxy(32 ,3) ;

cout <<" ~~~~~~~~~~~~~~~" ;

gotoxy( 1 , 4) ;

cout <<" CODE BOOK NAME A UTHOR PRICE COP IES " ;

gotoxy( 1 ,5 ) ; cout << "

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";

fs tream f i le ;

in t i=0;

f i le .open("BOOK.DA T" , ios : : in | ios : :out ) ;

whi le ( 1 )

{

f i le .read((char*)&b1 ,s izeof (b 1) ) ;

i f ( f i le .eof () )

break;

cout<<"\n" ;

gotoxy(4,row );

cout<<b1 . tcode ;

gotoxy( 10,row );

cout<<b1 . tname;

gotoxy(36 ,row ); cout<<b1 . tauthor ;

gotoxy(60,row );

cout<<b1 . tpr ice ; gotoxy(75 ,row );

cout<<b1 . tcop ies ;

b 1 . tava i l=b 1 . tcop ies ;

gotoxy(54,row +1) ;

cpr int f ("S TA TUS : " ) ;

textco lor(BLA CK+BLIN K) ;

cpr int f ("%d cop ies ava i lab le" ,b 1 . tava i l ) ;

textbackground(BLA CK) ; textco lor(L IGHTGRA Y) ;

row =row +2 ;

Page 21: Library management

}

f i le .c los e() ;

}

//FUNC TION TO CHECK W HE THER THE MEMBER CODE IS VA LID OR NOT

//_______________________________ __________________________

int MEMBER : : member_found( int mcode){return 0;}

{

fs tream f i le ;

f i le .open("MEMBER.DA T" , ios : : in) ;

f i le .s eekg(0, ios : :beg) ;

in t found=0 ;

whi le ( f i le .read((char *) th is , s izeof (MEMBER))) {

i f (memcode == mcode) {

f ound = 1 ;

break ;

}

} f i le .c los e() ;

re turn found ; }

//FUNC TION TO RE TURN 0 IF THE MEMBER HA S NOT ISSUED A NY BOOK

//__________________________________________________________

int MEMBER : : issued( int mcode){return 1 ; }

{

fs tream f i le ; f i le .open("MEMBER.DA T" , ios : : in) ;

f i le .s eekg(0, ios : :beg) ;

in t m issue=0 ;

whi le ( f i le .read((char *) th is , s izeof (MEMBER)))

{

i f (memcode == mcode)

{

m issue = bookcode ;

break ;

}

}

Page 22: Library management

f i le .c los e() ;

re turn miss ue ;

}

//FUNC TION TO CA LCULA TE & RETURN F INE A MOUN T FOR A GIVEN MEMBER CODE //_________________________________________________________________

int MEMBER : : f ine( int mcode) {

DA TE D ;

in t d 1 , m1 , y 1 ;

s truct date d ;

getdate(&d) ;

d 1 = d .da_day ;

m1 = d .da_mon ;

y 1 = d .da_yea r ; fs tream f i le ;

f i le .open("MEMBER.DA T" , ios : : in) ; f i le .s eekg(0, ios : :beg) ;

in t days , t_f ine ;

whi le ( f i le .read((char *) th is , s izeof (MEMBER)))

{ i f (memcode == mcode)

{ days = D.d if f (dd ,mm,yy ,d 1 ,m1 ,y 1 ) ;

t_f ine = days * 2 ;

break ;

}

}

f i le .c los e() ;

re turn t_f ine ;

}

//FUNC TION TO RE TURN THE LA S T CODE OF THE MEMBER F ILE

//___________________________________________________

int MEMBER : : las tcode(vo id )

{

fs tream f i le ;

f i le .open("MEMBER.DA T" , ios : : in) ;

f i le .s eekg(0, ios : : beg) ;

in t mcode=0 ;

whi le ( f i le .read((char *) th is , s izeof (MEMBER)))

Page 23: Library management

mcode = memcode ;

f i le .c los e() ;

re turn mcode ;

}

//FUNC TION TO RE TURN THE MEMBER NA ME FOR A GIVEN MEMBER CODE

//__________________________________________________________

char *MEMBER : : membername(int mcode)

{

fs tream f i le ;

f i le .open("MEMBER.DA T" , ios : : in) ;

f i le .s eekg(0, ios : :beg) ;

char mname[26] ;

whi le ( f i le .read((char *) th is , s izeof (MEMBER))) {

i f (memcode == mcode) {

s trcpy(mname,name) ;

break ;

}

} f i le .c los e() ;

re turn mname ; }

//FUNC TION TO RE TURN THE P HONE MEMBER FOR A G IVEN MEMBER CODE

//___________________________________________________________

char *MEMBER : : memberphone( int mcode)

{

fs tream f i le ; f i le .open("MEMBER.DA T" , ios : : in) ;

f i le .s eekg(0, ios : :beg) ;

char mphone[10] ;

whi le ( f i le .read((char *) th is , s izeof (MEMBER)))

{

i f (memcode == mcode)

{

s trcpy(mphone ,phone) ;

break ;

}

}

Page 24: Library management

f i le .c los e() ;

re turn mphone ;

}

//FUNC TION TO RE TURN THE A DDRESS FOR A GIVEN MEM BER CODE //______________________________________________________

char *MEMBER : : memberaddress ( int mcode) {

fs tream f i le ;

f i le .open("MEMBER.DA T" , ios : : in) ;

f i le .s eekg(0, ios : :beg) ;

char maddress[33] ;

whi le ( f i le .read((char *) th is , s izeof (MEMBE R)))

{ i f (memcode == mcode)

{ s trcpy(maddress ,address) ;

break ;

}

}

f i le .c los e() ; re turn maddress ;

}

//FUNC TION TO RE TURN THE RECORD NUMBER FOR THE G IVEN MEMBER CODE

//______________________________________________________________

int MEMBER : : recordno( in t mcode)

{

fs tream f i le ;

f i le .open("MEMBER.DA T" , ios : : in) ; f i le .s eekg(0, ios : :beg) ;

in t count=0 ;

whi le ( f i le .read((char *) th is , s izeof (MEMBER))) {

count++ ;

i f (memcode == mcode)

break ;

}

f i le .c los e() ;

re turn count ;

}

Page 25: Library management

//FUNC TION TO A DD RECORD IN TO THE F ILE FOR A GIVEN MEMBER CODE

//____________________________________________________________

vo id MEMBER : : add_mem(int mcode , int bcode , char mname[26] , char maddress[33] , char mphone[10] , int d 1 , in t m1 , int y 1)

{ fs tream f i le ;

f i le .open("MEMBER.DA T" , ios : :app) ; memcode = mcode ;

bookcode = bcode ;

s trcpy(name,mname) ;

s trcpy(address ,maddress) ;

s trcpy(phone ,mphone) ;

dd = d 1 ;

mm = m1 ;

yy = y 1 ; f i le .wr ite((char *) th is , s izeof (MEMBER)) ;

f i le .c los e() ; }

//FUNC TION TO D ISP LA Y THE RECORD FOR A GIVEN MEMBER CODE

//______________________________________________________

vo id MEMBER : : d is p lay( int mcode)

{

fs tream f i le ;

f i le .open("MEMBER.DA T" , ios : : in) ;

f i le .s eekg(0, ios : :beg) ;

whi le ( f i le .read((char *) th is , s izeof (MEMBER)))

{

i f (memcode == mcode)

{ gotoxy(5 ,3) ;

cout <<" Member Code # " <<mcode ;

gotoxy(5 ,4) ; cout <<" ~~~~~~~~~~~~~~~~~" ;

gotoxy(5 ,6) ;

cout <<"Name : " <<name ;

gotoxy(5 ,7) ;

cout <<"P hone No : " <<phone ;

gotoxy(5 ,8) ;

cout <<"A ddress : " <<address ;

break ;

}

Page 26: Library management

}

f i le .c los e() ;

}

//FUNC TION TO D ISP LA Y THE L IS T OF MEMBERS //_______________________________________

vo id MEMBER : : l is t (vo id ) {

c lrscr() ;

BOOK B ;

in t row = 6 , f ound=0, f lag=0 ;

char ch ;

gotoxy(32 ,2) ;

cout <<"L IS T OF MEMBERS" ;

gotoxy(3 1 ,3) ; cout <<"===================" ;

gotoxy( 1 , 4) ; cout <<" CODE BOOK CODE NA ME P HONE" ;

gotoxy( 1 ,5 ) ;

cout

<<"~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

~~~~~~~~~~~~~~" ; fs tream f i le ;

f i le .open("MEMBER.DA T" , ios : : in) ; f i le .s eekg(0, ios : :beg) ;

whi le ( f i le .read((char *) th is , s izeof (MEMBER)))

{

f lag = 0 ;

de lay(20) ;

f ound = 1 ;

gotoxy(2 ,row ) ;

cout <<memcode ;

gotoxy( 10,row ) ; cout <<bookcode ;

gotoxy( 19 ,row ) ;

cout <<name ; gotoxy(48,row ) ;

cout <<phone ;

textbackground(W HITE ) ; t extco lor(BLA CK) ;

gotoxy(7 ,row +1) ;

i f (bookcode == 0)

cpr int f ("BOOK NA ME: (Not Iss ued)") ;

e ls e

Page 27: Library management

{

cpr int f ("BOOK NA ME: %s " ,B .bookname(bookcode)) ;

gotoxy(42 ,row +1) ;

cpr int f ("Date of return : ") ;

textco lor(BLA CK+BLIN K) ;

cpr int f ("%d/%d/%d",dd ,mm,yy) ; }

textbackground(BLA CK) ; textco lor(L IGHTGRA Y) ;

i f ( row == 22 ) {

f lag = 1 ;

row = 6 ;

gotoxy( 1 ,25 ) ;

cout <<"P ress any key to cont inue or P ress <ESC> to ex it " ;

ch = getch() ;

i f (ch == 27)

break ; c lrscr() ;

gotoxy(32 ,2) ; cout <<"L IS T OF MEMBERS" ;

gotoxy(3 1 ,3) ;

cout <<"============= =====" ;

gotoxy( 1 , 4) ;

cout <<"CODE BOOK CODE NA ME P HONE" ; gotoxy( 1 ,5 ) ;

cout <<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

~~~~~~~~~~~~~~" ;

}

e ls e

row = row + 2 ;

}

i f ( ! f ound)

{ gotoxy(5 , 10) ;

cout <<"\nRecords not found" ;

}

i f ( ! f lag )

{

gotoxy( 1 ,25 ) ;

cout <<"P ress any key to cont inue . . . " ;

getche() ;

}

f i le .c los e () ;

Page 28: Library management

}

//FUNC TION TO UP DA TE THE RECORD IN THE F ILE FOR A GIVEN BOOK CODE

//_________________________ ______________________________________

vo id BOOK : : update_copies ( int tcode , int tcop ies , int tava i l)

{ fs tream f i le ;

f i le .open("BOOK.DA T" , ios : : in ) ; fs tream temp ;

temp.open("temp.dat" , ios : :out ) ;

f i le .s eekg(0, ios : :beg) ;

whi le ( ! f i le .eof () )

{

f i le .read((char *) th is , s izeof (BOOK)) ;

i f ( f i le .eof () )

break ;

i f ( bookcode == tcode )

{

cop ies = tcop ies ;

ava i l = tava i l ; temp.wr ite((char *) th is , s izeof (BOOK)) ;

}

e ls e

temp.wr ite((char *) th is , s izeof (BOOK)) ;

}

f i le .c los e() ;

temp.c lose() ;

f i le .open("BOOK.DA T" , ios : :out ) ;

temp.open("temp.dat" , ios : : in) ;

temp.seekg(0, ios : :beg) ;

whi le ( ! temp.eof () )

{

temp.read((char *) th is , s izeof (BOOK)) ;

i f ( temp.eof () )

break ;

f i le .wr ite((char *) th is , s izeof (BOOK)) ;

}

f i le .c los e() ;

temp.c lose() ;

}

Page 29: Library management

//FUNC TION TO GE T DA TA TO A DD RECORD IN TO THE BOOK F ILE

//______________________________________________________

vo id W ORKING : : add_book(vo id ) {

BOOK B ; char c ;

c lrscr() ; fs tream f i le ("BOOK. DA T" , ios : : in | ios : :app) ;

f i le .s eekg(0, ios : :end) ;

in t pos =f i le . te l lg( ) ;

gotoxy(25 ,9) ;

cout<<"Code No. : " ;

b 1 . tcode=(pos /s izeof (B))+1 ;

cout<<b1 . tcode ;

do {

b 1 . tcode++;

gotoxy(30,5 ) ;

cout<<"A D D B O O K S" ; gotoxy(30,6) ;

cout<<"----------------- " ;

gotoxy(25 , 1 1 ) ;

cout<<"Name of the Book : " ;

gotoxy(25 , 13) ;

cout<<"Name of the A uthor : " ;

gotoxy(25 , 15 ) ;

cout<<"P r ice : " ;

gotoxy(25 , 17 ) ;

cout<<"Number of Cop ies : " ;

gotoxy(49 , 1 1 ) ; gets (b1 . tname) ;

gotoxy(49 , 13) ;

gets (b1 . tauthor) ; gotoxy(49 , 15 ) ;

c in>>b1 . tpr ice ;

gotoxy(49 , 17 ) ;

c in>>b1 . tcop ies ;

char ch ;

gotoxy(25 ,20) ;

cout<<"Do you w ant to save?(y/n) " ;

c in>>ch ;

i f (ch=='y ' | |ch=='Y ' )

Page 30: Library management

{

c lrscr() ;

add_new _book(b1 . tcode ,b 1 . tname,b1 . tauthor ,b 1 . tpr ice ,b 1 . tcop ies ,b 1 . tava i l ) ;

}

b 1 . tava i l = ava i lab le(b1 . tcode) + b 1 . tcop ies ;

b 1 . tcop ies = no_of_copies (b1 . tcode) + b 1 . tcop ies ; gotoxy(25 ,23) ;

cout<<"Do you w ant to add more? (y/n) " ; c in>>c ;

}w hi le (c=='y ' ) ; f i le .c los e() ;

}

//FUN C TION TO DELE TE THE RECORD FOR A GIVEN MEMBER CODE

//_____________________________________________________

vo id MEMBER : : de le te_rec( int mcode) {

fs tream f i le ; f i le .open("MEMBER.DA T" , ios : : in) ;

fs tream temp ;

temp.open("temp.dat" , ios : :out ) ;

f i le .s eekg(0, ios : :beg) ;

whi le ( ! f i le .eof () )

{ f i le .read((char *) th is , s izeof (MEMBER)) ;

i f ( f i le .eof () )

break ;

i f ( memcode != mcode )

temp.wr ite((char *) th is , s izeof (MEMBER)) ;

}

f i le .c los e() ; temp.c lose() ;

f i le .open("MEMBER.DA T" , ios : :out ) ;

temp.open("temp.dat" , ios : : in) ; temp.seekg(0, ios : :beg) ;

whi le ( ! temp.eof () )

{

temp.read((char *) th is , s izeof (MEMBER)) ;

i f ( temp.eof () )

break ;

Page 31: Library management

f i le .wr ite((char *) th is , s izeof (MEMBER)) ;

}

f i le .c los e() ;

temp.c los e() ;

}

//FUNC TION TO GE T DA TA TO A DDD RECORD IN TO THE MEMBER F ILE //________________________________________________________

vo id W ORKING : : add_member(vo id )

{

char ch ;

in t mcode , bcode ;

char mname[31] , mphone[1 1 ] , maddress[41] ;

in t d 1 , m1 , y 1 ;

mcode = las tcode() ;

i f (mcode == 0) {

add_mem(mcode ,0,"nu l l" , "nu l l " , "nu l l" ,0 ,0,0) ;

MEMBER: :de le te_rec(mcode) ;

}

mcode++ ;

do {

in t va l id=0 ;

c lrscr() ;

gotoxy(28,3) ;

cout <<"A DDITION OF THE MEMBERS" ;

gotoxy(28,4) ;

cout <<" ------------------------" ;

gotoxy(72 , 1 ) ;

cout <<"<0>=Ex it" ;

gotoxy(5 ,7) ; cout <<" # Member Code " <<mcode ;

gotoxy(5 ,8) ;

cout <<"_______________" ; gotoxy(5 , 10) ;

cout <<"Name : " ;

gotoxy(5 , 12 ) ;

cout <<"P hone No. : " ;

gotoxy(5 , 14 ) ;

cout <<"A ddress : " ;

do

{

Page 32: Library management

va l id = 1 ;

gotoxy(5 ,25 ) ; c lreo l () ;

cout <<"Enter the name of the New Member : " ;

gotoxy( 15 , 10) ; c lreo l () ;

gets (mname) ;

s trupr(mname) ;

i f (mname[0] == '0 ' ) re turn ;

i f (s tr len(mname) < 1 | | s tr len(mname) > 30)

{

va l id = 0 ;

gotoxy(5 ,25 ) ; c lreo l () ;

cout <<"\7Enter correct ly (Range : 1 . .30)" ;

getch() ;

}

}

whi le ( !va l id ) ;

do

{

va l id = 1 ; gotoxy(5 ,25 ) ; c lreo l () ;

cout <<"Enter P hone no . of the Member or Press <EN TER> for none : " ;

gotoxy( 15 , 12 ) ; c lreo l( ) ;

gets (mphone) ;

i f (mphone[0] == '0 ' )

re turn ;

i f ( (s tr len(mphone) < 6 && s tr len(mphone) > 0) | | (s tr len(mphone) > 10) )

{

va l id = 0 ; gotoxy(5 ,25 ) ; c lreo l () ;

cout <<"\7Enter correct ly . . . . " ;

getch() ; }

}

whi le ( !va l id ) ;

i f (s tr len(mphone) == 0)

s trcpy(mphone ," -") ;

do

Page 33: Library management

{

va l id = 1 ;

gotoxy(5 ,25 ) ; c lreo l () ;

cout <<"Enter the A ddress of the New Member : " ;

gotoxy( 15 , 14) ; c lreo l () ;

gets (maddress ) ; s trupr(maddress) ;

i f (maddress[0] == '0 ' )

re turn ;

i f (s tr len(maddress ) < 1 | | s tr len(maddress ) > 32)

{

va l id = 0 ;

gotoxy(5 ,25 ) ; c lreo l () ;

cout <<"\7Enter correct ly (Range : 1 . .40 )" ;

getch() ;

}

} whi le ( !va l id ) ;

gotoxy(5 ,25 ) ; c lreo l () ;

do {

gotoxy(5 , 17 ) ; c lreo l ( ) ; cout <<"Do you w ant to save? (y/n) : " ;

ch = getche() ;

ch = toupper(ch) ;

i f (ch == '0 ' )

re turn ;

}

whi le (ch != ' Y ' && ch != 'N ' ) ;

i f (ch == 'Y ' )

{

bcode = 0 ; d 1 = 0 ;

m1 = 0 ;

y 1 = 0 ;

add_mem(mcode ,bcode ,mname,maddress ,mphone ,d1 ,m1 ,y 1) ;

mcode++ ;

}

do

{

Page 34: Library management

gotoxy(5 , 19) ; c lreo l ( ) ;

cout <<"Do you w ant to add more? (y/n) : " ;

ch = getche() ;

ch = toupper(ch) ;

i f (ch == '0 ' ) re turn ;

}

w hi le (ch != ' Y ' && ch != 'N ' ) ; }

w hi le (ch == 'Y ' ) ;

}

//FUNC TION TO UP DA TE THE RECORD FOR A GIVEN MEMBER CODE

//______________________________________________________

vo id MEMBER : : update_book( int mcode , int tcode , int d 1 , in t m1 , int y 1 ) {

fs tream f i le ;

f i le .open("MEMBER.DA T" , ios : : in) ;

fs tream temp ;

temp.open("temp.dat" , ios : :out ) ; f i le .s eekg(0, ios : :beg) ;

whi le ( ! f i le .eof () )

{

f i le .read((char *) th is , s izeof (MEMBER)) ;

i f ( f i le .eof () )

break ;

i f ( memcode == mcode )

{

bookcode = tcode ; dd = d 1 ;

mm = m1 ;

yy = y 1 ; temp.wr ite((char *) th is , s izeof (MEMBER)) ;

}

e ls e

temp.wr ite((char *) th is , s izeof (MEMBER)) ;

}

f i le .c los e() ;

temp.c lose() ;

Page 35: Library management

f i le .open("MEMBER.DA T" , ios : :out ) ;

temp.open("temp.dat" , ios : : in) ;

temp.seekg(0, ios : :beg) ;

whi le ( ! temp.eof () )

{

temp.read((char *) th is , s izeof (MEMBER)) ;

i f ( temp.eof () ) break ;

f i le .wr ite((char *) th is , s izeof (MEMBER)) ;

}

f i le .c los e() ;

temp.c lose() ;

}

//FUNC TION TO ISSUE THE BOOK

//__________________________

vo id W ORKING : : issuebook(vo id ) {

BOOK B ; MEMBER M ;

DA TE D ;

char t 1code[33] , ch ;

in t t2code=0, tcode=0, mcode=0 ;

in t va l id ;

in t d 1 , m1 , y 1 ;

s truct date d ;

getdate(&d) ;

d 1 = d .da_day ;

m1 = d .da_mon ; y 1 = d .da_year ;

do {

va l id = 1 ;

whi le ( 1 )

{

c lrscr() ;

gotoxy(5 ,2 ) ;

cout <<"Date : " <<d1 <<"/" <<m1 <<"/" <<y 1 ;

gotoxy(72 , 1 ) ;

Page 36: Library management

cout <<"<0>=Ex it" ;

gotoxy(5 ,5 ) ;

cout <<"Enter Code or Name of the Book to be issued" ;

gotoxy(5 ,6) ;

cout <<" or " ;

gotoxy(5 ,7) ; cout <<"P ress <EN TER> for he lp " ;

gets (t 1code ) ; i f (s tr len(t 1code) == 0)

B . l is t () ;

e ls e

break ;

}

i f ( ( tcode == 0 && !bookname_found(t 1code)) | | ( tco de != 0 &&

!book_found(tcode)))

{ va l id = 0 ;

gotoxy(5 , 10) ; cout <<"\7Record not found! !" ;

gotoxy(5 , 1 1 ) ;

cout <<"P ress <ESC> to ex it or any other key to cont inue . . . " ;

ch = getch() ;

i f (ch == 27)

re turn ; }

}

whi le ( !va l id ) ;

i f ( tcode == 0)

tcode = bookcodeof (t 1code) ;

i f ( !ava i lab le (tcode)) {

gotoxy(5 , 10) ;

cout <<"\7Sorry ! ! Book (" <<bookname(tcode) <<") is not ava i lab le" ; gotoxy(5 , 1 1 ) ;

cout <<"K ind ly iss ue any other Book" ;

gotoxy(5 , 12 ) ;

cout <<"See L is t of Books" ;

getch() ;

re turn ;

}

do

Page 37: Library management

{

va l id = 1 ;

whi le ( 1 )

{

c lrscr() ; gotoxy(72 , 1 ) ;

cout <<"<0>=Ex it" ; gotoxy(5 ,2 ) ;

cout <<"Date : " <<d1 <<"/" <<m1 <<"/" <<y 1 ; gotoxy(5 ,5 ) ;

cout <<"Book Name: " <<bookname(tcode) ;

gotoxy(5 ,7) ;

cout <<"Enter Code no . of the Member" ;

gotoxy(5 ,8) ;

cout <<" or " ;

gotoxy(5 ,9) ;

cout <<"P ress <EN TER> for he lp " ; gets (t 1code) ;

i f ( t 1code[0] == '0 ' )

re turn ;

i f (s tr len(t 1code) == 0)

M . l is t () ;

e ls e

break ;

}

t2code = ato i(t 1code) ;

mcode = t2code ;

i f (mcode == 0)

{

va l id = 0 ;

gotoxy(5 ,25 ) ; cout <<"\7Enter Correct ly . . . . " ;

getch() ;

}

i f ( !member_found(mcode) && va l id )

{

va l id = 0 ;

gotoxy(5 , 13) ;

cout <<"\7Record not found! !" ;

gotoxy(5 , 14 ) ;

cout <<"P ress <ESC> to ex it or any other key to cont inue . . . " ;

ch = getch() ;

Page 38: Library management

i f (ch == 27)

re turn ;

}

}

w hi le ( !va l id ) ;

in t tcop ies , tava i l ;

tcop ies = no_of_copies (tcode) ; // Member funct ion of BOOK tava i l = ava i lab le (tcode) - 1 ; // Member funct ion of BOOK

update_copies (tcode , tcopies , tava i l) ; // Member funct ion of BOOK D.extend_date(d 1 ,m 1 ,y 1 , 15 ) ;

d 1 = D.day ;

m1 = D.mon ;

y 1 = D.year ;

update_book(mcode , tcode,d 1 ,m1 ,y 1 ) ; // Member funct ion of MEMBER

gotoxy(5 , 13) ;

cout <<"\7Book has been iss ued to " <<membername(mcode) ;

gotoxy(5 , 15 ) ; cout <<"Date of Return : " <<d1 <<"/" <<m1 <<"/" <<y 1 ;

getch() ; }

//FUNC TION TO RE TURN THE BOOK

//____________________________

vo id W ORKING : : re turnbook(vo id )

{

MEMBER M ;

char t 1code[5] , ch ;

in t t2code=0, mcode=0, va l id ;

in t d 1 , m1 , y 1 ;

s truct date d ;

getdate(&d) ;

d 1 = d .da_day ;

m1 = d .da_mon ; y 1 = d .da_year ;

do {

va l id = 1 ;

whi le ( 1 )

{

c lrscr() ;

gotoxy(72 , 1 ) ;

cout <<"<0>=Ex it" ;

gotoxy(5 ,2 ) ;

Page 39: Library management

cout <<"Date : " <<d1 <<"/" <<m1 <<"/" <<y 1 ;

gotoxy(5 ,7) ;

cout <<"Enter Code no . of the Member :" ;

gotoxy(5 ,8) ;

cout <<" or " ;

gotoxy(5 ,9) ; cout <<"P ress <EN TER> for he lp " ;

gets (t 1code) ;

i f ( t 1code[0] == '0 ' ) re turn ;

i f (s tr len(t 1code) == 0)

M . l is t () ;

e ls e

break ;

} i f (mcode == 0)

{ va l id = 0 ;

gotoxy(5 ,25 ) ;

cout <<"\7Enter Correct ly . . . " ;

getch() ;

}

i f ( !member_found(mcode) && va l id ) {

va l id = 0 ;

gotoxy(5 , 13) ;

cout <<"\7Record not found! !" ;

gotoxy(5 , 14 ) ;

cout <<"P ress <ESC> to ex it or an y other key to cont inue . . . " ;

ch = getch() ;

i f (ch == 27)

re turn ;

}

i f ( ! iss ued(mcode) && va l id)

{ va l id = 0 ;

gotoxy(5 , 13) ;

cout <<"\7Member has no book to return! !" ;

gotoxy(5 , 14 ) ;

cout <<"P ress <ESC> to ex it or any ot her key to cont inue . . . " ;

ch = getch() ;

i f (ch == 27)

re turn ;

}

Page 40: Library management

}

whi le ( !va l id ) ;

in t bcode , tcop ies , tava i l ;

bcode = issued(mcode) ;

gotoxy(5 , 13) ; cout <<"Book Code : " <<bcode ;

gotoxy(5 , 14 ) ; cout <<"Book Name : " <<bookname( bcode) ;

tcop ies = no_of_copies (bcode) ; tava i l = ava i lab le (bcode) + 1 ;

in t f ;

f = f ine(mcode) ;

i f ( f != 0)

{

gotoxy(5 , 16) ;

cout <<"You are expected to pay a f ine of Rs ." <<f <<" due to la te submiss ion" ;

gotoxy(5 , 17 ) ; cout <<"P leas e do not de lay the Return of Book aga in . . . " ;

}

update_copies (bcode , tcop ies , tava i l) ;

update_book(mcode ,0,0,0 ,0) ;

gotoxy(5 , 19) ; cout <<"\7Book has been returned . . . " ;

getch() ; }

//MA IN FUNCTION

//_____________

vo id ma in ()

{

MENU menu; menu. introduct ion( ) ;

menu.main_menu() ;

}

Page 41: Library management

Output

Introduction Page

Main menu

Page 42: Library management

Add Books Window

Add Books Window with Information

Page 43: Library management

Add Members Window

Add members Window with Information

Page 44: Library management

List of Members

List of Books

Page 45: Library management

Bibliography

Computer Science with C++ - Sumita Arora

Turbo C++ Help

Codeblocks 10.05

www.agpgtcs.webs.com

www.cbsematerials.webnode.com