📄 book_library.cpp
字号:
file.close() ;
}
// THIS FUNCTION DISPLAY THE LIST OF BOOKS.
void BOOK :: table(void)
{
clrscr() ;
int row = 6 , found=0, flag=0 ;
char ch ;
gotoxy(33,2) ;
cout <<"LIST OF BOOKS" ;
gotoxy(32,3) ;
cout <<"~~~~~~~~~~~~~~~" ;
gotoxy(1,4) ;
cout <<"CODE BOOK NAME AUTHOR PRICE COPIES" ;
gotoxy(1,5) ;
cout <<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" ;
fstream file ;
file.open("BOOK.DAT", ios::in) ;
file.seekg(0,ios::beg) ;
while (file.read((char *) this, sizeof(BOOK)))
{
flag = 0 ;
delay(20) ;
found = 1 ;
gotoxy(2,row) ;
cout <<bookcode ;
gotoxy(7,row) ;
cout <<name ;
gotoxy(40,row) ;
cout <<author ;
gotoxy(66,row) ;
cout <<price ;
gotoxy(73,row) ;
cout <<copies ;
textbackground(WHITE) ; textcolor(BLACK) ;
gotoxy(40,row+1) ;
cprintf("STATUS: ") ;
textcolor(BLACK+BLINK) ;
cprintf("%d COPIES AVAILABLE ",avail) ;
textbackground(BLACK) ; textcolor(LIGHTGRAY) ;
if ( row == 22 )
{
flag = 1 ;
row = 6 ;
gotoxy(1,25) ;
cout <<"PRESS ANY KEY TO CONTINUE OR PRESS <ESC> TO EXIT " ;
ch = getch() ;
if (ch == 27)
break ;
clrscr() ;
gotoxy(33,2) ;
cout <<"LIST OF BOOKS" ;
gotoxy(32,3) ;
cout <<"~~~~~~~~~~~~~~~" ;
gotoxy(1,4) ;
cout <<"CODE BOOK NAME AUTHOR PRICE COPIES" ;
gotoxy(1,5) ;
cout <<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" ;
}
else
row = row + 2 ;
}
if (!found)
{
gotoxy(5,10) ;
cout <<"\7RECORDS NOT FOUND " ;
}
if (!flag)
{
gotoxy(1,25) ;
cout <<"PRESS ANY KEY TO CONTINUE..." ;
getche() ;
}
file.close () ;
}
//this function return 0 if given member code not found
int MEMBER::m_found(int mcode)
{
fstream file;
file.open("MEMBER.DAT",ios::in);
file.seekg(0,ios::beg);
int found=0;
while(file.read((char*)this,sizeof(MEMBER)))
{
if(memcode==mcode)
{found=1;break;
}
}
file.close();
return found;
}
//this function return 0 if member have not issued any 4book
int MEMBER::issued(int mcode)
{
fstream file ;
file.open("MEMBER.DAT",ios::in);
file.seekg(0,ios::beg);
int missue=0;
while(file.read((char*)this,sizeof(MEMBER)))
{
if(memcode==mcode)
{ missue=bookcode;break;
}
}
file.close();
return missue;
}
//this function calculate and return fine for given member code
int MEMBER::fine(int mcode)
{
DATE D;
int d1,m1,y1 ;
struct date d;
getdate(&d);
d1=d.da_day;
m1=d.da_mon;
y1=d.da_year;
fstream file;
file.open("MEMBER.DAT",ios::in);
file.seekg(0,ios::beg);
int days,t_fine;
while(file.read((char*)this,sizeof(MEMBER)))
{
if(memcode==mcode)
{ days=D.diff(dd,mm,yy,d1,m1,y1);
t_fine=days*2;
break;
}
}
file.close();
return t_fine;
}
//this function return last code of member file
int MEMBER::ltcode(void)
{
fstream file;
file.open("MEMBER.DAT",ios::in);
file.seekg(0,ios::beg);
int mcode=0;
while(file.read((char*)this,sizeof(MEMBER)))
mcode=memcode;
file.close();
return mcode;
}
//this function return member name of given member code
char*MEMBER::m_name(int mcode)
{
fstream file;
file.open("MEMBER.DAT",ios::in);
file.seekg(0,ios::beg);
char mname[26];
while(file.read((char*)this,sizeof(MEMBER)))
{
if(memcode==mcode)
{
strcpy(mname,name);
}
}
file.close();
return mname;
}
//this function return member phone of given member
char*MEMBER::m_phone(int mcode)
{ fstream file;
file.open("MEMBER.DAT",ios::in);
file.seekg(0,ios::beg);
char mphone[10];
while(file.read((char*)this,sizeof(MEMBER)))
{
if(memcode==mcode)
{
strcpy(mphone,phone);break;
}
}
file.close();
return mphone;
}
//this function return member address of given member
char*MEMBER::m_address(int mcode)
{
fstream file;
file.open("MEMBER.DAT",ios::in);
file.seekg(0,ios::beg);
char maddress[33];
while(file.read((char*)this,sizeof(MEMBER)))
{
if(memcode==mcode)
{
strcpy(maddress,maddress);
}
}
file.close();
return maddress;
}
//this function return record no of given member code
int MEMBER::recordno(int mcode)
{
fstream file;
file.open("MEMBER.DAT",ios::in);
file.seekg(0,ios::beg);
int count=0;
while(file.read((char*)this,sizeof(MEMBER)))
{
count++;
if(memcode==mcode)
break;
}
file.close();
return count;
}
//this function delete record for given member code
void MEMBER::del_rec(int mcode)
{
fstream file;
file.open("MEMBER.DAT",ios::in);
fstream temp;
temp.open("TEMP.DAT",ios::out) ;
file.seekg(0,ios::beg);
while(!file.eof())
{
file.read((char*)this,sizeof(MEMBER));
if(file.eof())break;
if(memcode!=mcode)
temp.write((char*)this,sizeof(MEMBER));
}
file.close();
temp.close();
file.open("MEMBER.DAT",ios::out);
temp.open("TEMP.DAT",ios::in);
temp.seekg(0,ios::beg);
while(!temp.eof())
{
temp.read((char*)this,sizeof(MEMBER));
if(temp.eof())break;
file.write((char*)this,sizeof(MEMBER));
}
file.close();
temp.close();
}
//this function update record for given member code
void MEMBER::update_b(int mcode,int tcode,int d1,int m1,int y1)
{
fstream file;
file.open("MEMBER.DAT",ios::in);
fstream temp;
temp.open("TEMP.DAT",ios::out);
file.seekg(0,ios::beg);
while(!file.eof())
{
file.read((char*)this,sizeof(MEMBER));
if(file.eof())break;
if(memcode==mcode)
{
bookcode=tcode;
dd=d1;
mm=m1;
yy=y1;
temp.write((char*)this,sizeof(MEMBER));
}
else
temp.write((char*)this,sizeof(MEMBER));
}
file.close();
temp.close();
file.open("MEMBER.DAT",ios::out);
temp.open("TEMP.DAT",ios::in) ;
temp.seekg(0,ios::beg);
while(!temp.eof())
{
temp.read((char*)this,sizeof(MEMBER));
if(temp.eof())break;
file.write((char*)this,sizeof(MEMBER));
}
file.close();
temp.close();
}
//this function modify record for given member code
void MEMBER::mod(int mcode,char mname[26],char mphone[10],char maddress[33])
{
int recno;
recno=recordno(mcode);
fstream file;
file.open("MEMBER.DAT",ios::out|ios::ate);
strcpy(name,mname);
strcpy(phone,mphone);
strcpy(address,maddress);
int location;
location=(recno-1)*sizeof(MEMBER);
file.seekp(location);
file.write((char*)this,sizeof(MEMBER));
file.close();
}
//this function add record in file for given member code
void MEMBER::add_mem(int mcode,int bcode,char mname[26],char maddress[33],char mphone[10],int d1,int m1,int y1)
{
fstream file;
file.open("MEMBER.DAT",ios::app);
memcode=mcode;
bookcode=bcode;
strcpy(name,mname);
strcpy(phone,mphone);
strcpy(address,maddress);
dd=d1;
mm=m1;
yy=y1;
file.write((char*)this,sizeof(MEMBER));
file.close();
}
//this function display record for given member code
void MEMBER::display(int mcode)
{
fstream file;
file.open("MEMBER.DAT",ios::in);
file.seekg(0,ios::beg);
while(file.read((char*)this,sizeof(MEMBER)))
{
if(memcode==mcode)
{
gotoxy(5,3);cout<<"MEMBER CODE#"<<mcode;
gotoxy(5,4);cout<<"~~~~~~~~~~~~~";
gotoxy(5,6);cout<<"NAME:"<<name;
gotoxy(5,7);
cout<<"PHONE: "<<phone;
gotoxy(5,8);cout<<"ADDRESS:"<<address;
break;
}
}
file.close();
}
//list of members
void MEMBER::jot(void)
{
clrscr();
BOOK B;
int row =6,found=0,flag=0;
char ch;
gotoxy(32,2);cout<<"LIST OF MEMBERS";
gotoxy(31,3);cout<<"~~~~~~~~~~~~~~~~~";
gotoxy(1,4);
cout<<"MEMBER CODE BOOK CODE NAME PHONE";
gotoxy(1,5);
cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
fstream file;
file.open("MEMBER.DAT",ios::in);
file.seekg(0,ios::beg);
while(file.read((char*)this,sizeof(MEMBER)))
{
flag=0;
delay(20);
found=1;
gotoxy(3,row);cout<<memcode;
gotoxy(20,row);cout<<bookcode;
gotoxy(41,row);cout<<name;
gotoxy(65,row);cout<<phone;
textbackground(WHITE);textcolor(BLACK);
gotoxy(7,row+1);
if(bookcode==0)
cprintf("BOOK NAME:(NOT ISSUED)");
else
{cprintf("BOOK NAME: %s",B.b_name(bookcode));
gotoxy(42,row+1);
cprintf("DATE OF RETURN:");
textcolor(BLACK+BLINK);
cprintf("%d\\%d\\%d",dd,mm,yy);
}
textbackground(BLACK);textcolor(LIGHTGRAY);
if(row==2)
{
flag=1;
row=6;
gotoxy(1,25);cout<<"PRESS ANY KEY TO CONTUNUE";
ch=getch();
if(ch==27)break;
clrscr();
gotoxy(32,2);cout<<"LIST OF MEMBERS";
gotoxy(31,3);cout<<"~~~~~~~~~~~~~~~";
gotoxy(1,4);cout<<"MEMBER CODE BOOK CODE NAME PHONE";
gotoxy(1,5);cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
}
else
row=row+2;
}
if(!found)
{
gotoxy(5,10);
cout<<"\7RECORDS NOT FOUND";
}
if(!flag)
{
gotoxy(1,25);
cout<<"PRESS ANY KEY TO CONTINUE...";
getche();
}
file.close();
}
// THIS FUNCTION GIVES DATA TO ADD RECORD IN THE BOOK FILE.
void WORKING :: add_b(void)
{
if (!reccount()) // MEMBER FUNCTION OF BOOK
{
add_book(0,"null","null",0.0,0,0) ;
BOOK::delete_rec(0) ;
}
char ch ;
int tcode, tcopies, tavail ;
char tname[33], tauthor[26] ;
float tprice=0.0 ;
do
{
int found=0, valid=0 ;
int tc ;
float t2=0.0 ;
char t[10], t1[10] ;
clrscr() ;
gotoxy(29,3) ;
cout <<"ADDITION OF THE BOOKS" ;
gotoxy(29,4) ;
cout <<"~~~~~~~~~~~~~~~~~~~~~" ;
gotoxy(72,1) ;
cout <<"<0>=Exit" ;
gotoxy(5,25) ;
cout <<"ENTER CODE NO. OF THE BOOK" ;
gotoxy(5,5) ;
cout <<"CODE NO. " ;
gets(t) ;
tc = atoi(t) ;
tcode = tc ;
if (tcode == 0)
return ;
if (b_found(tcode))
{
found = 1 ;
gotoxy(19,8) ;
cout <<b_name(tcode) ;
gotoxy(19,9) ;
cout <<a_name(tcode) ;
gotoxy(22,10) ;
cout <<b_price(tcode) ;
}
gotoxy(5,8) ;
cout <<"BOOK NAME : " ;
gotoxy(5,9) ;
cout <<"AUHOR NAME : " ;
gotoxy(5,10) ;
cout <<"PRICE : Rs." ;
gotoxy(5,12) ;
cout <<"COPIES : " ;
valid = 0 ;
while (!valid && !found)
{
valid = 1 ;
gotoxy(5,25) ; clreol() ;
cout <<"ENTER THE NAME OF THE BOOK" ;
gotoxy(19,8) ; clreol() ;
gets(tname) ;
strupr(tname) ;
if (tname[0] == '0')
return ;
if (strlen(tname) < 1 || strlen(tname) > 32)
{
valid = 0 ;
gotoxy(5,25) ; clreol() ;
cout <<"\7ENTER CORRECTLY (RANGE: 1..32)" ;
getch() ;
}
}
valid = 0 ;
while (!valid && !found)
{
valid = 1 ;
gotoxy(5,25) ; clreol() ;
cout <<"ENTER THE AUTHOR'S NAME THE BOOK" ;
gotoxy(19,9) ; clreol() ;
gets(tauthor) ;
strupr(tauthor) ;
if (tauthor[0] == '0')
return ;
if (strlen(tauthor) < 1 || strlen(tauthor) > 25)
{
valid = 0 ;
gotoxy(5,25) ; clreol() ;
cout <<"\7ENTER CORRECTLY (RANGE: 1..25)" ;
getch() ;
}
}
valid = 0 ;
while (!valid && !found)
{
valid = 1 ;
gotoxy(5,25) ; clreol() ;
cout <<"ENTER THE PRICE OF THE BOOK" ;
gotoxy(22,10) ; clreol() ;
gets(t1) ;
t2 = atof(t1) ;
tprice = t2 ;
if (t1[0] == '0')
return ;
if (tprice < 1 || tprice > 9999)
{
valid = 0 ;
gotoxy(5,25) ; clreol() ;
cout <<"\7ENTER CORRECTLY" ;
getch() ;
}
}
valid = 0 ;
while (!valid)
{
valid = 1 ;
gotoxy(5,25) ; clreol() ;
cout <<"ENTER NO. OF COPIES OF BOOK TO BE ADDED" ;
gotoxy(19,12) ; clreol() ;
gets(t) ;
tc = atoi(t) ;
tcopies = tc ;
if (t[0] == '0')
return ;
if (tcopies < 1 || tcopies > 50)
{
valid = 0 ;
gotoxy(5,25) ; clreol() ;
cout <<"\7ENTER CORRECTLY" ;
getch() ;
}
}
tavail = available(tcode) + tcopies ;
tcopies = no_of_copies(tcode) + tcopies ;
gotoxy(5,25) ; clreol() ;
do
{
gotoxy(5,15) ; clreol() ;
cout <<"DO YOU WANT TO SAVE (Y/N) : " ;
ch = getche() ;
ch = toupper(ch) ;
} while (ch != 'Y' && ch != 'N') ;
if (ch == 'Y')
{
if (found)
update_copies(tcode,tcopies,tavail) ;
else
add_book(tcode,tname,tauthor,tprice,tcopies,tavail) ;
}
do
{
gotoxy(5,17) ; clreol() ;
cout <<"DO YOU WANT TO ADD MORE (Y/N) : " ;
ch = getche() ;
ch = toupper(ch) ;
} while (ch != 'Y' && ch != 'N') ;
} while (ch == 'Y') ;
}
// THIS FUNCTION GIVES DATA TO ADD RECORD IN THE MEMBER FILE
void WORKING :: add_m(void)
{
char ch ;
int mcode, bcode ;
char mname[26], mphone[10], maddress[33] ;
int d1, m1, y1 ;
mcode = ltcode() ;
mcode++ ;
do
{
int valid=0 ;
clrscr() ;
gotoxy(28,3) ;
cout <<"ADDITION OF THE MEMBERS" ;
gotoxy(28,4) ;
cout <<"~~~~~~~~~~~~~~~~~~~~~~~" ;
gotoxy(72,1) ;
cout <<"<0>=Exit" ;
gotoxy(5,7) ;
cout <<"MEMBER CODE # " <<mcode ;
gotoxy(5,8) ;
cout <<"~~~~~~~~~~~~~~~~~" ;
gotoxy(5,10) ;
cout <<"NAME : " ;
gotoxy(5,12) ;
cout <<"PHONE : " ;
gotoxy(5,14) ;
cout <<"ADDRESS : " ;
do
{
valid = 1 ;
gotoxy(5,25) ; clreol() ;
cout <<"ENTER THE NAME OF THE NEW MEMBER" ;
gotoxy(15,10) ; clreol() ;
gets(mname) ;
strupr(mname) ;
if (mname[0] == '0')
return ;
if (strlen(mname) < 1 || strlen(mname) > 25)
{
valid = 0 ;
gotoxy(5,25) ; clreol() ;
cout <<"\7ENTER CORRECTLY (RANGE: 1..25)" ;
getch() ;
}
} while (!valid) ;
do
{
valid = 1 ;
gotoxy(5,25) ; clreol() ;
cout <<"ENTER PHONE NO. OF THE MEMBER OR PRESS <ENTER> FOR NONE" ;
gotoxy(15,12) ; clreol() ;
gets(mphone) ;
if (mphone[0] == '0')
return ;
if ((strlen(mphone) < 7 && strlen(mphone) > 0) || (strlen(mphone) > 9))
{
valid = 0 ;
gotoxy(5,25) ; clreol() ;
cout <<"\7ENTER CORRECTLY" ;
getch() ;
}
} while (!valid) ;
if (strlen(mphone) == 0)
strcpy(mphone,"-") ;
do
{
valid = 1 ;
gotoxy(5,25) ; clreol() ;
cout <<"ENTER THE ADDRESS OF THE NEW MEMBER" ;
gotoxy(15,14) ; clreol() ;
gets(maddress) ;
strupr(maddress) ;
if (maddress[0] == '0')
return ;
if (strlen(maddress) < 1 || strlen(maddress) > 32)
{
valid = 0 ;
gotoxy(5,25) ; clreol() ;
cout <<"\7ENTER CORRECTLY (RANGE: 1..32)" ;
getch() ;
}
} while (!valid) ;
gotoxy(5,25) ; clreol() ;
do
{
gotoxy(5,17) ; clreol() ;
cout <<"DO YOU WANT TO SAVE (Y/N) : " ;
ch = getche() ;
ch = toupper(ch) ;
if (ch == '0')
return ;
} while (ch != 'Y' && ch != 'N') ;
if (ch == 'Y')
{
bcode = 0 ;
d1 = 0 ;
m1 = 0 ;
y1 = 0 ;
add_mem(mcode,bcode,mname,maddress,mphone,d1,m1,y1) ;
mcode++ ;
}
do
{
gotoxy(5,19) ; clreol() ;
cout <<"DO YOU WANT TO ADD MORE (Y/N) : " ;
ch = getche() ;
ch = toupper(ch) ;
if (ch == '0')
return ;
} while (ch != 'Y' && ch != 'N') ;
} while (ch == 'Y') ;
}
// THIS FUNCTION ISSUES THE BOOK
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -