# Including
# Including
# Including
#include// input/output file stream class
usingnamespacestd
constit maxr = 100; //The most readers
constit maxb = 100; //The most books
constitmaxbor = 5; //Each reader can borrow up to five books.
//reader class, which describes the information of readers.
Class reader
{
Private:
Inttag// delete tag 1: deleted 0: not deleted.
Intno// reader number
charname[ 10]; //Reader's name
intborbook[max bor]; //Borrow books
Public:
Reader(){}
char * getname(){ return name; }//Get the name
int gettag(){ return tag; }//Get delete tag
int getno(){ return no; }//Get the reader number
Voidsetname(charna[])// Set the name.
{
Strcpy (name, not applicable);
}
void del book(){ tag = 1; }//Set the delete flag 1: Deleted 0: Not deleted.
Voida reader(intn, char * na)// Add a reader.
{
tag = 0;
no = n;
Strcpy (name, not applicable);
for(inti = 0; ibor book[I]= 0;
}
Voidborrowbook(intbookid)// Borrowing operation
{
for(inti = 0; I {
if(borbook[i]==0)
{
bor book[I]= bookid;
Return;
}
}
}
Intro Book(intbookid)// book return operation
{
for(inti = 0; I {
if(borbook[i]==bookid)
{
bor book[I]= 0;
return 1;
}
}
return0
}
Voiddisp()// Read the reader information.
{
Standard output
for(inti = 0; iif(borbook[i]! =0)
Standard output
Standard output
}
};
//reader class library, to realize the establishment of readers' personal data.
Classified database
{
Private:
Inttop// reader record pointer
reader read[Maxr]; //Reader record
Public:
The RDatabase()// constructor reads reader.txt into read[].
{
Readers;
top =- 1;
fstreamfile("reader.txt ",IOs::in); //Open an input file
while( 1)
{
file . read((char *)& amp; s,sizeof(s));
If (! File) interrupt;
Top;
read[top]= s;
}
file . close(); //close reader.txt
}
Voidclear()// Delete all reader information.
{
top =- 1;
}
Intaddreader(intn, char*na)// When adding readers, check whether they exist.
{
reader * p = query(n);
if(p==NULL)
{
Top;
Read [top]. addreader(n,na);
return 1;
}
return0
}
Reader*query(intreaderid)// Search by number.
{
for(inti = 0; I
If (read [me]. getno()= = readerid & amp; & amp
Read [me]. gettag()==0)
{
Change & to [i];
}
returnNULL
}
Voiddisp()// Output all reader information.
{
for(inti = 0; I
Read [me]. disp();
}
voidreaderdata(); //Reader Library Maintenance
~RDatabase()// destructor, write read[] to the reader.txt file.
{
fstreamfile("reader.txt ",IOs::out);
for(inti = 0; I
If (read [me]. gettag()==0)
file . write((char *)& amp; read[i],sizeof(read[I]);
file . close();
}
};
voidRDatabase::readerdata()
{
charchoice
charr name[20];
intreaderid
reader * r;
And (choose! ='0')
{
Standard output
CIN & gt; & gt selection;
Switch (selection)
{
Case "1":
Standard output
CIN & gt; & gtreaderid
Standard output
CIN & gt; & gtrname
addreader(readerid,rname);
Break;
Case "2":
Standard output
CIN & gt; & gtreaderid
r = query(readerid);
if(r==NULL)
{
Standard output
Break;
}
Standard output
CIN & gt; & gtrname
r-& gt; set name(rname);
Break;
Case "3":
Standard output
CIN & gt; & gtreaderid
r = query(readerid);
if(r==NULL)
{
Standard output
Break;
}
r-& gt; del book();
Break;
Case "4":
Standard output
CIN & gt; & gtreaderid
r = query(readerid);
if(r==NULL)
{
Standard output
Break;
}
r-& gt; disp();
Break;
Case "5":
disp();
Break;
Case "6":
clear();
Break;
Default value: cout
}
}
}
//Book category, which realizes the description, book number, title, lending and return of books.
Roll call book
{
Private:
Inttag// delete tag 1: deleted 0: not deleted.
Intno// book number
charname[20]; //Book title
Intonshelf// Do you want to borrow 1: Borrow 2: Borrow?
Public:
Book(){}
char * getname(){ return name; }//Get the name
int getno(){ return no; }//Get the book number
int gettag(){ return tag; }//Get delete tag
Voidsetname(charna[])// Set the title of the book.
{
Strcpy (name, not applicable);
}
void del book(){ tag = 1; }//Delete books
Voidaddbook(intn, char*na)// Add books.
{
tag = 0;
no = n;
Strcpy (name, not applicable);
on shelf = 1;
}
Intborrowbook()// Book borrowing operation
{
if(on self = = 1)
{
on shelf = 0;
return 1;
}
return0
}
Voidretbook()// Book Return Operation
{
on shelf = 1;
}
Voiddisp()// output books
{
Standard output
}
};
//Library class, which can maintain, search and delete books.
Class b database
{
Private:
Inttop// book record pointer
book book[Maxb]; //Book records
Public:
The BDatabase()// constructor reads book.txt into book[].
{
Bookb
top =- 1;
fstreamfile("book.txt ",IOs::in);
while( 1)
{
file . read((char *)& amp; b,sizeof(b));
If (! File) interrupt;
Top;
book[top]= b;
}
file . close();
}
Voidclear()// Delete All
{
top =- 1;
}
Intaddbook(intn, char*na)// Add books.
{
book * p = query(n);
if(NULL==p)
{
Top;
Book [top]. addbook(n,na);
return 1;
}
return0
}
Book*query(intbookid)// find books.
{
for(inti = 0; I
If (book [me]. getno()= = bookid & amp; & Book [me]. gettag()==0)
{
Return to & book [i];
}
returnNULL
}
voidbookdata(); //Library maintenance
voiddisp()
{
for(inti = 0; I
If (book [me]. gettag()==0)
Book [me]. disp();
}
~BDatabase()// destructor, and write book[] into the book.txt file.
{
fstreamfile("book.txt ",IOs::out);
for(inti = 0; I
If (book [me]. gettag()==0)
file . write((char *)& amp; book[i],sizeof(book[I]);
file . close();
}
};
void db database::book data()
{
charchoice
charb name[40];
intbookid
Book * b;;
And (choose! ='0')
{
Standard output
Standard output
CIN & gt; & gt selection;
Switch (selection)
{
Case "1":
Standard output
CIN & gt; & gtbookid
Standard output
CIN & gt; & gtbname
addbook(bookid,bname);
Break;
Case "2":
Standard output
CIN & gt; & gtbookid
B = BookID;
if(b==NULL)
{
Standard output
Break;
}
Standard output
CIN & gt; & gtbname
b-& gt; set name(bname);
Break;
Case "3":
Standard output
CIN & gt; & gtbookid
B = BookID;
if(b==NULL)
{
Standard output
Break;
}
b-& gt; del book();
Break;
Case "4":
Standard output
CIN & gt; & gtbookid
B = BookID;
if(b==NULL)
{
Standard output
Break;
}
b-& gt; disp();
Break;
Case "5":
disp();
Break;
Case "6":
clear();
Break;
Default value: cout
}
}
}
//The realization of the main () function and the guidance of the main interface of the program.
voidmain()
{
charchoice
intbookid,readerid
RDatabaseReaderDB
reader * r;
BDatabaseBookDB
Book * b;;
And (choose! ='0')
{
Standard output
Standard output
CIN & gt; & gt selection;
Switch (selection)
{
Case "1":
Standard output
CIN & gt; & gtreaderid
Standard output
CIN & gt; & gtbookid
r = readerdb . query(readerid); //Search by number
if(NULL==r)
{
Standard output
Break;
}
b = bookdb . query(bookid);
if(b==NULL)
{
Standard output
Break;
}
if(b-& gt; borrowbook()==0)
{
Standard output
Break;
}
r-& gt; Borrowing books (b-> getno());
Break;
Case "2":
Standard output
CIN & gt; & gtreaderid
Standard output
CIN & gt; & gtbookid
r = readerdb . query(readerid);
if(r==NULL)
{
Standard output
Break;
}
b = bookdb . query(bookid);
if(b==NULL)
{
Standard output
Break;
}
b-& gt; ret book();
r-& gt; retbook(b-& gt; getno());
Break;
Case "3":
bookdb . book data();
Break;
Case "4":
reader db . reader data();
Break;
Default value: cout
}
}
}