图书馆管理系统 数据结构与算法 C语言 无错误.docx
《图书馆管理系统 数据结构与算法 C语言 无错误.docx》由会员分享,可在线阅读,更多相关《图书馆管理系统 数据结构与算法 C语言 无错误.docx(23页珍藏版)》请在冰豆网上搜索。
![图书馆管理系统 数据结构与算法 C语言 无错误.docx](https://file1.bdocx.com/fileroot1/2023-7/12/f9a0af6a-2dde-4cb9-9f9f-12958f87f86c/f9a0af6a-2dde-4cb9-9f9f-12958f87f86c1.gif)
图书馆管理系统数据结构与算法C语言无错误
软件技术报告:
图书管理系统的设计与实现
系统的需求分析
图书登记管理系统作为一个应用软件将为学校的老师和学生提供一个对学校图书馆深入了解并借阅、还书的平台。
根据系统界面的提示信息对图书馆信息进行查询、初始化等操作
1.基本要求
(1)主菜单:
管理员、读者信息。
(2)管理员操作:
注册,登录。
查询,删除,增加读者信息。
新书上架(插入)。
图书处理(删除)。
图书丢失(删除)。
图书借阅,归还处理。
(3)读者操作:
注册,登录。
查询。
借书。
还书。
丢失赔偿。
借书本书上线。
借书期限。
(4)图书信息:
ID类别书名作者出版年出版社单价现存数量。
2.算法说明
下面从系统的整体流程的功能模块、系统界面及数据结构进行总体设计。
总体思想
本系统主要设计思想是实现图书馆的功能机管理系统信息的查询、借书、还书等主要功能。
系统的设计方法是结构化实际方法,系统用C语言进行开发用户可以清晰的了解图书馆内的情况。
系统模块结构图
根据需求分析结果,图书管理系统可以分为两大大模块:
管理员模块、读者模块。
系统模块结构如图:
系统的概要设计
系统主菜单。
显示系统的主菜单,里面有相应的功能代码,根据选择各功能代码进入不同的界面。
功能主要包括:
退出系统、查询图书、借书、还书。
系统说明
系统文件夹
Administator储存的是管理员信息。
第一行为管理员数量
后续行分别为管理员ID和管理员密码
Book储存的是图书信息
第一行为图书数量
后续行为图书ID类别书名作者出版年出版社单价现存数量。
Reader储存的是读者信息
第一行储存的是读者数量
后续行储存的分别是读者ID密码要赔多少钱借的书数量借的书名
3.算法分析与设计
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
usingnamespacestd;
#defineLLlonglong
#defineULLunsignedlonglong
#defineLDlongdouble
#definesqr(x)(x)*(x)
constintMAXN=5005;
constintMAXM=30;
constintINF=0x7fffffff;
constintMOD=1e9+9;
constdoubleeps=1e-5;
constintUpbooks=10;
structBOOKS{
charid[100];
chartype[100];
charname[100];
charauthor[100];
charpress[100];
intyear,price,quantity;
}books[100010];//图书结构体
structREADERS{
charid[100];
charname[100];
charborrow[11][100];
intquantity,price;
}readers[100010];//读者结构体
mapamp,rmp;//string分别存入ID密码
mapamp1,rmp1;//string分别存入ID和数量用作注册判重。
charTheReader[100],TheBook[100],book_ID[100],reader_ID[100];
charst[10],stt[10],aid[100],Aid[100],apw[100],Apw[100],rid[100],Rid[100],rpw[100],Rpw[100];
intnbooks,nreaders,nad;//储存信息数组
voidfuzhi(char*a,char*b){
intl=strlen(b);
for(inti=0;i}
//赋值子函数
voidreadln(){
ifstreamicin;
icin.open("book.txt");
icin>>nbooks;
chars1[10],s2[10],s3[10],s4[10],s5[10],s6[10],s7[10],s8[10];
icin>>s1>>s2>>s3>>s4>>s5>>s6>>s7>>s8;
for(inti=1;i<=nbooks;++i){
icin>>books[i].id>>books[i].type>>books[i].name>>books[i].author>>books[i].press>>books[i].year>>books[i].quantity>>books[i].price;
}//读入图书数据函数
icin.close();
////ifstreamicin;
icin.open("administrator.txt");
icin>>nad;
charstr1[100],str2[100];
for(inti=1;i<=nad;++i){
icin>>str1>>str2;
amp[string(str1)]=string(str2);
amp1[string(str1)]=1;
//cout<}
icin.close();
ifstreamicin1;
icin.open("reader.txt");
icin>>nreaders;
for(inti=1;i<=nreaders;++i){
icin>>str1>>str2>>readers[i].price>>readers[i].quantity;
fuzhi(readers[i].id,str1);
rmp[string(str1)]=string(str2);
rmp1[string(str1)]=1;
for(intj=1;j<=readers[i].quantity;++j){
icin>>readers[i].borrow[j];
}
}
icin.close();
}
voidwriteln(){
ofstreamocout;
ocout.open("book.txt");
ocout<ocout<<"IDtypenameauthorpressyearquantityprice"<for(inti=1;i<=nbooks;++i){
//printf("%s%s%s%s%s%d%d%d\n",books[i].id,books[i].type,book[i].name,books[i].author,books[i].press,books[i].year,books[i].price,books[i].quantity);
ocout<}
ocout.close();
//ofstreamocout;
ocout.open("reader.txt");
ocout<for(inti=1;i<=nreaders;++i){
ocout<for(intj=1;j<=readers[i].quantity;++j){
ocout<<""<}//写入图书数据函数
}
ocout.close();
//ofstreamocout;
ocout.open("administrator.txt");
ocout<map:
:
const_iteratorit;
for(it=amp.begin();it!
=amp.end();++it)
ocout<first<<""<second<ocout.close();
}
boolcmp_books(BOOKSa,BOOKSb){
returnstring(a.id)}
boolcmp_readers(READERSa,READERSb){
returnstring(a.id)}
intFind_Reader(char*name){
for(inti=1;i<=nreaders;++i){
if(string(readers[i].id)==string(name))returni;
}//查找读者函数
return0;
}
voidprint_reader(intx){
printf("ID:
%s\n",readers[x].id);
printf("Amountofcompensation:
%d\n",readers[x].price);
printf("Youhaveborrowedbooks:
%d\n",readers[x].quantity);
printf("Thebooksyouhaveborrowed:
\n");
for(inti=1;i<=readers[x].quantity;++i){
printf("%s\n",readers[x].borrow[i]);
}
}//输出读者信息函数
voidprint_reader_borrow(intx){
printf("Youhaveborrowedbooks:
%d\n",readers[x].quantity);
printf("Thebooksyouhaveborrowed:
\n");
for(inti=1;i<=readers[x].quantity;++i){
printf("%s\n",readers[x].borrow[i]);
}
}//输出读者借阅信息函数
voiddelete_reader(intx){
for(inti=x;ifuzhi(readers[i].id,readers[i+1].id);
readers[i].quantity=readers[i+1].quantity;
readers[i].price=readers[i+1].price;
for(intj=1;j<=readers[i].quantity;++j){
fuzhi(readers[i].borrow[j],readers[i+1].borrow[j]);
}
}//删除读者函数
nreaders--;
//sort(readers+1,readers+1+nreaders,cmp_readers);
}
intFind_book(char*st){
for(inti=1;i<=nbooks;++i){
if(string(books[i].id)==string(st))returni;
}
return0;
}//查找图书函数
voidDelete_book(intx){
for(inti=x;ifuzhi(books[i].id,books[i+1].id);
fuzhi(books[i].type,books[i+1].type);
fuzhi(books[i].name,books[i+1].name);
fuzhi(books[i].author,books[i+1].author);
fuzhi(books[i].press,books[i+1].press);
books[i].year=books[i+1].year;
books[i].quantity=books[i+1].quantity;
books[i].price=books[i+1].price;
}//删除图书函数
nbooks--;
//sort(books+1,books+1+nbooks,cmp_books);
}
voidprint_Book(intx){
printf("bookinformation:
\n");
printf("id:
");
printf("%s\n",books[x].id);
printf("type:
");
printf("%s\n",books[x].type);
printf("name:
");
printf("%s\n",books[x].name);
printf("author:
");
printf("%s\n",books[x].author);
printf("publishingyear:
");
printf("%d\n",books[x].year);
printf("press:
");
printf("%s\n",books[x].press);
printf("unitprice:
");
printf("%d\n",books[x].price);
printf("Existingquantity:
");
printf("%d\n",books[x].quantity);
}//输出图书信息函数
intmain(){//主程序
readln();
printf("------------Welcometothelibrarymanagementsystem------------\n");
printf("WHOAREYOU?
\n");
printf("1:
ADMINISTRATOR.\n");
printf("2:
READER.\n");
intq;
scanf("%d",&q);
while(q==1){
printf("HAVEYOUREGISTERED?
Y/N\n");
scanf("%s",st);
if(st[0]=='Y'){
printf("ID:
");
scanf("%s",Aid);
printf("Password:
");
scanf("%s",Apw);
while(amp1[string(Aid)]!
=1){
printf("TheIDiswrong,pleasere-enter!
!
!
\n");
printf("ID:
");
scanf("%s",Aid);
printf("Password:
");
scanf("%s",Apw);
}
while(amp[string(Aid)]!
=string(Apw)){
printf("Yourpasswordisnotcorrect,pleasere-enter!
!
!
\n");
printf("Password:
");
scanf("%s",Apw);
}
while
(1){
printf("Whatdoyouwanttodo?
\n");
printf("1:
Checkreaderinformation.\n");
printf("2:
NewBook.\n");
printf("3:
DeleteBook.\n");
printf("4:
LoseaBook.\n");
printf("5:
BorrowingandReturningbooks.\n");
printf("6:
Exit.\n");
intqq;
scanf("%d",&qq);
while(qq==1){
printf("Whatdoyouwanttodo?
\n");
printf("1:
Findareader.\n");
printf("2:
Deleteareader.\n");
intqqq;
scanf("%d",&qqq);
printf("READERID:
");
scanf("%s",TheReader);
intxxx=Find_Reader(TheReader);
if(xxx==0){
printf("WrongReaderID.\n");
continue;
}
if(qqq==1)print_reader(xxx);
if(qqq==2)delete_reader(xxx);
printf("print""1""return\n");
scanf("%d",&qqq);
if(qqq==1)break;
}
while(qq==2){
printf("newbookinformation:
\n");
printf("id:
");
scanf("%s",books[++nbooks].id);
printf("type:
");
scanf("%s",books[nbooks].type);
printf("name:
");
scanf("%s",books[nbooks].name);
printf("author:
");
scanf("%s",books[nbooks].author);
printf("publishingyear:
");
scanf("%d",&books[nbooks].year);
printf("press:
");
scanf("%s",books[nbooks].press);
printf("unitprice:
");
scanf("%d",&books[nbooks].price);
printf("Existingquantity:
");
scanf("%d",&books[nbooks].quantity);
//sort(books+1,books+nbooks+1,cmp_books);
printf("print""1""return\n");
intqqq;
scanf("%d",&qqq);
if(qqq==1)break;
}
while(qq==3){
printf("DeletebookID:
");
scanf("%s",book_ID);
intxxx=Find_book(book_ID);
Delete_book(xxx);
printf("print""1""return\n");
intqqq;
scanf("%d",&qqq);
if(qqq==1)break;
}
if(qq==4){
printf("LosebookID:
");
scanf("%s",book_ID);
intxxx=Find_book(book_ID);
while(xxx==0){
printf("wrongbookID\n");
printf("LosebookID:
");
scanf("%s",book_ID);
xxx=Find_book(book_ID);
}
//printf("%d\n",xxx);
printf("LosebookreaderID:
");
scanf("%s",reader_ID);
intyyy=Find_Reader(reader_ID);
while(yyy==0){
printf("wrongreaderID\n");
printf("LosebookreaderID:
");
scanf("%s",reader_ID);
yyy=Find_Reader(reader_ID);
}
//printf("%d\n",yyy);
//print_reader(yyy);
readers[