图书管理系统程c++序代码.docx
《图书管理系统程c++序代码.docx》由会员分享,可在线阅读,更多相关《图书管理系统程c++序代码.docx(26页珍藏版)》请在冰豆网上搜索。
图书管理系统程c++序代码
图书管理系统c++程序源代码
#include
#include
#include
#include
#include
#definemax3
usingnamespacestd;
typedefstructBooks
{
charbook_name[15];
inttotal_num;
intborrow_num;
charbook_num[15];
Books*next;
}
books_node;
typedefstructReaders
{
charreader_name[15];
charreader_no[15];
intreader_borrow_num;
structReader_borrow_books
{
charborrow_books_name[15];
charborrow_books_no[15];
}reader_borrow_book[max];
Readers*next;
}
readers_node;classbooks
{
protected:
books_node*broot;
public:
books();
savebooks();
search_book();
print_books();
virtualadd_book()=0;
virtualdelet_book()=0;
};
classmanager:
publicbooks
{
protected:
readers_node*rroot;
public:
manager(readers_node*);
savereaders();add_book();
delet_book();search_reader();
add_reader();delet_reader();
print_readers();
};
classreader:
publicbooks{
private:
readers_node*personnel;
public:
reader(readers_node*);
add_book();
reader_borrow();
delet_book();
reader_return();
print_me();
save_readers(readers_node*);
};
books:
:
books()
{
books_node*r;
broot=newbooks_node;
r=newbooks_node;
r->next=NULL;
broot=r;
ifstreaminFile;
inFile.open("c:
\\books.dat",ios:
:
binary);
if(inFile.is_open()==-1)cout<<"con'topenbooks.dat"<else
{
inti=0;
while
(1)
{
i++;
books_node*node;
node=newbooks_node;
inFile.read((char*)node,sizeof(books_node));
if(inFile.eof())break;node->next=r->next;
r->next=node;
}inFile.close();
if(i<2)cout<<"暂时没有图书数据"<}
}
books:
:
savebooks()
{
books_node*L;
L=newbooks_node;
L=broot->next;
ofstreamoutFile;
outFile.open("c:
\\books.dat",ios:
:
binary);
while(L)
{
outFile.write((char*)L,sizeof(books_node));
L=L->next;
}outFile.close();
}
books:
:
search_book()
{
charsearchedbook[15];
cout<<"输入要查找的书的名子:
";
cin>>searchedbook;
books_node*r;
r=newbooks_node;
r=broot->next;
while(r)
{
if((strcmp(searchedbook,r->book_name))==0)
{
cout<<"书名:
"<book_name<<"书的总量:
"<total_num<<"借出:
"<borrow_num<<"书的编号:
"<book_num<break;
}
r=r->next;
}
if(r==NULL)
cout<<"对不起,没有此书"<}
books:
:
print_books()
{
books_node*r;
r=newbooks_node;
r=broot->next;
while(r)
{
cout<<"书名:
"<book_name<<"书的总量:
"<total_num<<"借出:
"<borrow_num<<"书的编号:
"<book_num<r=r->next;
}
deleter;
}
manager:
:
add_book()
{
books_node*L;
L=newbooks_node;
L=broot;while
(1)
{
books_node*r;
r=newbooks_node;
r->next=NULL;
cout<<"输入书名:
";
cin>>r->book_name;
cout<<"输入书的编号:
";
cin>>r->book_num;
r->borrow_num=0;
cout<<"输入总数:
";
cin>>r->total_num;
r->next=L->next;
L->next=r;
cout<<"addmore?
(n终止,其它键继续)";
charsign;
cin>>sign;
if(sign=='n'||sign=='N')
break;
}
broot=L;
savebooks();
}
manager:
:
delet_book()
{
chardeleted[15];
cout<<"输入要删除的图书名字:
";
cin>>deleted;
books_node*node,*L;
node=newbooks_node;
L=newbooks_node;
node=broot;
while(node->next)
{
if((strcmp(deleted,node->next->book_name))==0)break;
node=node->next;
}if(node->next==NULL)
{
cout<<"sorry!
Thereisnothebook!
"<}else
{
if(node->next->borrow_num==0)
{
node->next=node->next->next;savebooks()
}
else
cout<<"对不起,暂时不能删除,因为还有没有归还的书"<}
}
manager:
:
manager(readers_node*node)
{
rroot=newreaders_node;rroot=node;
}
manager:
:
savereaders()
{
readers_node*L;L=newreaders_node;L=rroot->next;
ofstreamoutFile;
outFile.open("c:
\\Readers.dat",ios:
:
binary);
while(L)
{
outFile.write((char*)L,sizeof(readers_node));
L=L->next;
}
outFile.close();
}
manager:
:
add_reader()
{
readers_node*L;
L=newreaders_node;
L=rroot;intsign=0;
while
(1)
{
readers_node*r;
r=newreaders_node;
r->next=NULL;
cout<<"输入姓名:
";
cin>>r->reader_name;
cout<<"输入读者的编号:
";
cin>>r->reader_no;
r->reader_borrow_num=0;
r->next=L->next;
L->next=r;
cout<<"addmore?
(n终止,其它键继续)";
charsign;cin>>sign;
if(sign=='n'||sign=='N')
break;
}
root=L;
savereaders();
}
manager:
:
delet_reader()
{
chardeleted[15];
cout<<"输入要删除读者的名字:
";
cin>>deleted;
readers_nodenode,*L;
node=newreaders_node;
L=newreaders_node;
node=rroot;
while(node->next)
{
if((strcmp(deleted,node->next->reader_name))==0)break;
node=node->next;
}
if(node->next==NULL)
{
cout<<"sorry!
Thereisnothereader!
"<}else
{
node->next=node->next->next;
savereaders();
}
}
manager:
:
search_reader()
{
readers_node*r;
r=newreaders_node;
r=rroot->next;
charreader[15];
cout<<"输入要查找读者的姓名:
";
cin>>reader;
while(r)
{
if((strcmp(reader,r->reader_name))=0)
{
cout<<"姓名:
"<reader_name<<"编号:
"<reader_no<<"借书总数:
"<reader_borrow_num<for(inti=0;ireader_borrow_num;i++)
{
cout<<"书名:
"<reader_borrow_book[i].borrow_books_name<<""<<"书的编号:
"<reader_borrow_book[i].borrow_books_no;
}
break;
}
elser=r->next;
}
if(!
r)cout<<"没有此人"<}
manager:
:
print_readers()
{
readers_nodeprintL;
printL=newreaders_node;
printL=rroot->next;
while(printL)
{
cout<<"姓名编号借书总数"<cout<reader_name<<""<reader_no<<""<reader_borrow_num<for(inti=0;ireader_borrow_num;i++)
{
cout<<"书名:
"<reader_borrow_book[i].borrow_books_name<<""<<"书的编号:
"<reader_borrow_book[i].borrow_books_no;
}
printL=printL->next;
}
deleteprintL;
}
reader:
:
reader(readers_node*node)
{
(personnel)==newreaders_node;
personnel=node;
}
reader:
:
add_book()
{
books_node*node;
node=newbooks_node;
node=broot->next;
charreturned[15];
cout<<"输入要还书的名子:
";
cin>>returned;
for(inti=0;i=personnel->reader_borrow_num;i++)
{
if((strcmp(returned,personnel->reader_borrow_book[i].borrow_books_name))==0)break;
}
if(i==personnel->reader_borrow_num+1)
{
printf("不好意思,你没有此书");
system("pause");
}
else
{
while(node)
{
if((strcmp(node->book_name,returned)==0))break;
elsenode=node->next;
}
if(node)
{
personnel->reader_borrow_num--;
node->borrow_num--;
savebooks();
}
elsecout<<"对不起,没有你要还的书或者所还书被删除"<}
}
reader:
:
delet_book()
{
if(personnel->readerborrow_num{
books_node*node;
node=newbooks_node;
node=broot->next;
charborrowed[15];
cout<<"输入要借书的名子:
";
cin>>borrowed;
while(node)
{
if((strcmp(node->book_name,borrowed)==0))break;
elsenode=node->next;
}
if(node&&(node->total_num-node->borrow_num)>0)
{
strcpy(personnel->reader_borrow_book[personnel->reader_borrow_num].borrow_books_name,node->book_name);
strcpy(personel->reader_borrow_book[personnel->reader_borrw_num++].borrow_books_no,node->book_num);
node->borrow_num++;savebooks();
}
elsecout<<"对不起,没有你要借的书或者所要借的书已经借完!
"<}elsecout<<"对不起,你借书的数量已经超过最大借数量"<}
reader:
:
print_me()
{
cout<<"姓名"<reader_name<<"编号:
"<reader_no<<"借书总数:
"<reader_borrow_num<for(inti=0;ireader_borrow_num;i++)
{
printf("书名:
%s,书的编号:
%s",personnel->reader_borrow_book[i].borrow_books_name,personnel->reader_borrow_book[i].borrow_books_no)
}
}
voidPause()
{
getch();
fflush(stdin);
}
reader:
:
reader_borrow(){delet_book();}
reader:
:
reader_return(){add_book();}
reader:
:
save_readers(readers_node*L)
{
readers_node*root;
root=newreaders_node;
root=L->next;
ofstreamoutFile;
outFile.open("c:
\\Readers.dat",ios:
:
binary);
while(root)
{
outFile.write((char)root,sizeof(readers_node));
root=root->next;
}
outFle.close();
}
readers_node*read_readers()
{
readers_node*r;
r=newreaders_node;
r->next=NULL;
intflag=0;
ifstreaminFile;
inFile.open("c:
\\Readers.dat",ios:
:
binary);
if(inFile.is_open()==-1)
{
cout<<"con'topenreaders.dat"<}
else
{
while
(1)
{
flag++;
readers_node*node;
node=newreaders_node;
inFile.read((char*)node,sizeof(readers_node));
if(inFile.eof())break;
node->next=r->next;
r->next=node;
}
inFile.close();
if(flag<2)
{
cout<<"暂无读者"<}
else
returnr;
}
}
password()
{
system("cls");
chara[]="111111",b[10],c;intn=0,k;
cerr<<"\n\n\n\n\t\t\t请输入密码,你将拥有3次机会:
\n";
while
(1)
{
n++;
k=0;
cout<<"\t\t\t输入密码:
";
while
(1)
{
c=getch();
if(c==13)break;
b[k]=c;k++;
cerr<<"*";
}b[k]='\0';
cout<<"\n";
if(n>2)
{
printf("你已经超过输入次数,系统将退出\n");
getch();
}
if(strcmp(a,b)==0)break;
elsecout<<"密码错误,请重新输入\n";cerr<<"\n";
}
}
voidmanager_menu_1(managerM)
{
intN;
while
(1)
{
cout<<"┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n";
cout<<"┃图书管图书管理系统┃\n";
cout<<"┃菜单┃\n";
cout<<"┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫\n";
cout<<"┃①增加图书┃\n";
cout<<"┃②.删除图书┃\n";
cout<<"┃③.查找图书┃\n";
cout<<"┃④.输出所有┃\n";
cout<<"┃退出请按0┃\n";
cout<<"┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛\n";
cout<<"请输入您的选择(0--4):
()\b\b";
cin>>N;
switch(N)
{
case1:
M.add_book();
getch();
break;
case2:
M.delet_book();
getch();
break;
case3:
M.search_book();
getch();
break;
case4:
M.print_books();
getch();
break;
case0:
return;
}
system("cls");
}
}
voidmanager_menu_2(managerM)
{
intN