版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、程序设计实习报告( 2012-6-1 )姓名:秦炜杰 学号:110520021 日期: 2012-6-1一、题目 图书馆管理系统二、基本要求1类的基本操作要熟练,类的定义,类的创建,构造函数与析构函数的使用要熟练。2输入和输出要清晰,输入提示要清楚。三、实习报告1实习题:设一本书的基本资料由以下数据项来描述:1. 书号(设为一个无符号长整型);2. 书名(设为不超过30个字符的字符串);3. 作者名(设为不超过20个字符的字符串);4. 出版社(设为不超过30个字符的字符串);5. 关键词(最多5个,每个关键词为不超过10个字符的英文单词); 其中,设每本书的书号、书名、作者名和出版社均是惟一
2、的。请用类形式来构造一个小型图书资料管理系统(模拟)。该系统应能提供以下常规功能:1. 图书资料库:从键盘输入各图书资料,建立图书资料库;设图书依书号从小到大次序组织存放;2. 查询功能:1) 读者可通过提供书名查询,若该书仍在库中,则列出该书资料;2) 读者可通过提供书号查询,若该书仍在库中,则列出该书资料;3) 读者也可通过提供关键词查询(最多5个:一般情况下,读者提供用于查询的关键词个数都不会超过在书库中登记的图书原有的关键词个数),若提供的关键词和原书中关键词相匹配,则列出所有符合要求的所有图书资料给读者选择;读者可从系统所列出可供选择的图书资料信息中,通过书号来办理借阅手续;3. 借
3、书功能: 当所查询的图书的确字库内时,读者可采用提供书号形式来办理借阅手续(每次操作只能借一本书);1) 登记借阅人的姓名(不超过20个字符的字符串)、电话(无符号长整型整数)、借阅日期(年、月、日,均是整型量);2) 置“该图书已被借走”状态;4. 还书功能:(提供书号办理还书手续)1) 删去图书中该书借阅人的资料;2) 将该书资料归入“该图书仍在库内”状态;5. 催还功能: 管理人员定期列出借书人借阅图书资料,以便检查是否有超期借阅者,若有则发通知催还。时间计算只从该书借出那天起到当前工作日(20为期限)。请设计出符合要求的类并设计出模拟运行的主程序。说明:1. 理论上,图书资料库藏书量应
4、没有限制(实际上是受硬件资料所限);2. 图书资料库可以采用以下组织形式:1) 每本图书的资料由基本资料和借阅人资料组成,所有图书资料由一个链表链接在一起;2) 每本图书的资料也由基本资料和借阅人资料组成,但所有图书资料分别由未借出链表和已借出链表链接在一起;3. 请先确定好图书资料组织形式,然后再考虑设计功能的实现。4. 模拟图书资料系统工作的主函数基本要求如下:1) 在键盘上输入每本图书资料,在存储区中建立图书资料库。因无法预知图书册数,可以设当输入书号为0时表示输入结束。图书资料库正常工作期间追加新入库图书时也如此办理;2) 输出图书库中所有在库图书资料清单,此操作只有管理人员使用;3)
5、 输出图书库中已被借出的图书资料清单和追加图书,此操作只由管理人员使用;4) 查询图书、借阅图书、归还图书;5) 每借出一本图书或归还一本图书之后,输出书库内图书情况或借书人登记资料,以便核对操作是否完成;6) 书库内没有登记的图书,不能办理借阅手续。当然,不是在该图书库借出的图书也不能在此处办理还书手续。 2.解题的基本算法:(1)说明:定义两个结构体,书的基本资料,借书人的资料与其借书的日期。在书的基本资料中有一个指针,指向下一本图书。设计的类中,有两个指针作为数据成员,而函数成员有“插入图书”函数,“显示所有图书”函数,“合并指针”函数,“催还图书”函数,“删去一个节点”函数,“借书”函
6、数,“还书”函数,“查询图书”函数,“求两个日期之间的天数”函数,“删除图书”函数。(2)程序运行时,将分为“图书馆管理人员”和“借书人界面”。系统管理人员的功能有追加图书,显示所有在库图书,显示所有已借出图书,催还图书,删除图书,查询图书,还书,借书。一般用户的功能有查询图书,借书,还书。(3)程序运行,初始化数据,进入主菜单,有三个选择,分别是1,2,0。选1就进入图书馆管理人员的菜单界面,选2就进入用户的菜单界面,选0就结束程序。(4)选1后,有9个选择:(由于管理员的权限已经包括用户的,所以此处只说明管理员的功能操作) 1.输入图书资料:输入的图书会按照书号从小到大的顺序插入到在库图书
7、的链表中,当输入书号为0时,结束插入图书。2.输出所有在库图书:即输出未借出链表的节点,当链表为空时,输出提示。否则,当输出一本书后停止,按回车键输出下一本书,直到链表输完。3.输出所有借出的图书:即输出已经借出链表的节点,当链表为空时,输出提示。否则,当输出一本书后停止,按回车键输出下一本书,直到链表输完。4.催还图书:输入一个日期,利用求天数函数求出输入日期与借书日期之间的天数,如果天数大于规定还书天数,就发催还通知。5. 删除图书:输入书号,从未借出链表中删除该图书,并撤销该节点和令指向该节点的指针为空。6.查询图书,有三种方法查询图书: 书名查询:输入书名,在未借出链表中查询,有则输出
8、该图书,否则输出提示。 书号查询:输入书号,在未借出链表中查询,有则输出该图书,否则书出提示。 关键词查询:输入最多5个关键词,与未借出链表中的节点的关键词匹配,如果所有关键词都符合,就输出该书,与下本书匹配。直到链表完结。7.借书:输入书号,该书在未借出链表中存在时,接着输入借书人姓名,当该借书人所借的书不多与2本时,输完借书人资料,借出图书,如果多余2本,输出提示,借书不成功。当该书不存在时,输出提示,借书不成功。8.还书:输入书号,如果该书在已借出链表中存在时,借书成功,否则输出提示,借书不成功。 0.返回主菜单。 3.程序流程图输入1进入主菜单,有1,2,0三个选择输入2输入0进入管理
9、人员菜单显示菜单有1,2,3,4,5,0选择输入5输入3输入4输入1输入2输入0插入图书显示在库图书显示借出图书催还图书删除图书结束进入用户的菜单显示有1,2,3,0选择输入1查询图书输入2借出图书输入3归还图书输入0开始输入6查询图书输入7输入8借出图书归还图书输入书号追加图书的函数流程图书号为0?输入书名输入作者名输入出版社名输入关键词按书号,从小到大插入在库图书链关键词为0并且key<5?输入关键词key=0key+输入书号返回输出在库图书链的头指针h为NULL?pwork=hpwork等于NULL?输出书名输出作者名输出出版社名输出关键词pwork=pwork->next输
10、出没有书返回催还图书输入一个日期计算出借出日期和输入日期之间的天数day规定归还期限为MAX=20天链的头指针h=NULL?pwork=hpwork=NULL?day>MAX输出图书资料pwork=pwork->next返回删除图书输入书号在链中搜索图书在链中?令目标节点的上一个节点指向目标节点的下个节点撤消目标节点令目标节点的指针为NULL返回查询图书输出有1,2,3,0选择输入选择输入3输入1输入2输入0输入书号输入关键词输入书名在链中查找图书在链中?输出图书资料返回借出图书输入书号在在库图书链中查找图书存在?输入借书人姓名此人借书量少于MAX每人最多借书MAX=2本输入借书人
11、电话号码输入借书日期在在库图书链中删除该书把该书插入已借图书链中继续?返回归还图书输入书号在已借出图书链中查找该书图书存在?把该书的节点从已借链中删除把该书插入在库图书链中返回4.源程序代码#include<iostream.h>#include<conio.h>#include<string.h>#include<stdio.h>#include<stdlib.h>const int Mbook=2; / 每人最多只能借两本书 struct Student / 借书人的资料 char Sname50; / 所借出书的名称 unsig
12、ned long tel; / 借书人的电话 int year; / 所借年份 int mouth; / 所借月份 int date; / 所借天;struct Book / 书本的资料 unsigned long Booknum; / 书本的号码 char Bname100; / 书本的名字 char author50; / 书本的作者 char publish50; / 书本的出版社 char key550; / 书本的关键字 Student student; / 储存一个Student 类型的 student Book *pnext;class Library /图书馆类 private
13、: Book *headA; /在库图书链的头指针 Book *headB; /已借图书链的头指针 int MAX; / 最大借出天数 public: Library(); Library(); Book *order(Book*,Book*); / 对两个指针的操作 void insert(); / 插入图书 void display(int); / 显示图书 void check_show(); / 查询图书 void borrow(); / 借书 void Return(); / 还书 void urge(); / 催还 void deletebook(); / 删除图书;Library
14、:Library() /构造函数,设置两个指针为空 headA=NULL; headB=NULL; cout<<"nPlease input the max day:" cin>>MAX;Library:Library() / 在链中删除图书 Book *pwork=headA; while(headA!=NULL) headA=headA->pnext; delete pwork; pwork=headA; pwork=headB;while(headB!=NULL) headB=headB->pnext; delete pwork;
15、pwork=headB; Book *Library:order(Book *head,Book *pwork) /对两个指针的操作 if(head=NULL) head=pwork; pwork->pnext=NULL; else Book *pwork1=head; Book *pre; while(pwork->Booknum>pwork1->Booknum)&& (pwork1->pnext!=NULL) ) pre=pwork1;pwork1=pwork1->pnext; if(pwork1->Booknum) > (p
16、work->Booknum) if(head=pwork1) head=pwork; pwork->pnext=pwork1; else pre->pnext=pwork; pwork->pnext=pwork1; else pwork1->pnext=pwork; pwork->pnext=NULL; return head;void Library:insert() / 插入图书 Book *pwork; Book *pre,*pwork1; unsigned long number; do cout<<"n*book data*n
17、" cout<<"ninput the book number:"cin>>number; if(number=0) break; pwork=new Book; pwork->Booknum=number; cout<<"ninput the book name:"gets(pwork->Bname); cout<<"ninput the author name:"gets(pwork->author); cout<<"ninput t
18、he press name:"gets(pwork->publish); strcpy(pwork->student.Sname,"NO NAME"); pwork->student.tel=0; pwork->student.year=0; pwork->student.mouth=0; pwork->student.date=0;for(int i=0;i<5;i+) cout<<"ninput the key word"<<i+1<<":"g
19、ets(pwork->keyi); headA=order(headA,pwork);while(number>0); cout<<endl;void Library:display(int number) / 显示图书 switch(number) case 1:cout<<"n*Unborrow LIST*n" Book *pwork=headA; if(pwork!=NULL) while(pwork!=NULL) cout<<"n*Book Data*n" cout<<"nTh
20、e book's ID number is :"<<pwork->Booknum<<endl <<"The book's name is:"<<pwork->Bname<<endl <<"The book's author is:"<<pwork->author<<endl <<"The book's publish is:"<<pwork->publ
21、ish<<endl <<"The book's key word:"for(int i=0; i<5 ;i+) cout<<pwork->keyi<<""<<" "getch();pwork=pwork->pnext; else cout<<"nHas no book in the library !n" ;break; case 2:cout<<"n*Borrow List*n" Bo
22、ok *pwork=headB; if(pwork!=NULL) while(pwork!=NULL) cout<<"n*Book Data*n" cout<<"nThe book's ID number is :"<<pwork->Booknum<<endl <<"The book's name is:"<<pwork->Bname<<endl <<"The book's author is:
23、"<<pwork->author<<endl <<"The book's publish is:"<<pwork->publish<<endl <<"The book's key word:"for(int i=0; i<5 ;i+) cout<<pwork->keyi<<""<<" " cout<<"nThe lender is:&qu
24、ot;<<pwork->student.Sname<<endl <<"The telephone is:"<<pwork->student.tel<<endl<<"The.date.is:"<<pwork->student.year<<'.'<<pwork->student.mouth<<'.'<<pwork->student.date<<endl;g
25、etch();pwork=pwork->pnext; else cout<<"nHas no book borrow !n" ;break; void Library:check_show() / 查询图书 Book *pwork=headA; int number; cout<<"n*Welcome to check book *n" cout<<"nPlease, how do you want to check ? :n" cout<<"n book number:
26、1 "<<endl<<" book name:2 "<<endl<<" key word:3 "<<endl; cout<<"Please input the number:"cin>>number; switch(number) case 1:unsigned long idnumber; int flag1=0; /书号查询 cout<<"input the number:"cin>>idnum
27、ber; if(pwork!=NULL) while(pwork!=NULL) if(idnumber=pwork->Booknum) cout<<"n*Book data*" cout<<"nthe book ID number is :"<<pwork->Booknum<<endl <<"the book name is:"<<pwork->Bname<<endl <<"the book author is:
28、"<<pwork->author<<endl <<"the book output is:"<<pwork->publish<<endl <<"the book key word:"for(int i=0; i<5 ;i+) cout<<pwork->keyi<<"|"<<" " flag1+; pwork=pwork->pnext; if(flag1=0) cout&
29、lt;<"tnNO Resultn" else cout<<"nthe link is emptyn" ;break; case 2:char bname100; int flag1=0; / 书名查询 cout<<"ninput the Book_name:"gets(bname); if(pwork!=NULL) while(pwork!=NULL) if(strcmp(pwork->Bname,bname)=0) cout<<"n*Book Data*" cou
30、t<<"nThe book ID number is :"<<pwork->Booknum<<endl <<"The book name is:"<<pwork->Bname<<endl <<"The book author is:"<<pwork->author<<endl <<"The book publish is:"<<pwork->publish<
31、;<endl <<"The book key word:"for(int i=0; i<5 ;i+) cout<<pwork->keyi<<""<<" " flag1+; getch(); pwork=pwork->pnext; if(flag1=0) cout<<"tnNo Result !n" else cout<<"nThe link is empty !n" ;break; case 3:ch
32、ar key550; char key250; int flag1=0; int count=0; char ch; do cout<<"nPlease input the key word(0 to end):"gets(key2); if(strcmp(key2,"0")=0) break; strcpy(keycount,key2); count+; while(count<5); if(pwork!=NULL) while(pwork!=NULL) int flag=0; for(int i=0; i<count ;i+)
33、 int flag1=0; for(int j=0; j<5 ;j+) if(strcmp(keyi,pwork->keyj)=0) if(flag1=0) flag1+; flag+; if(flag=count) cout<<"n*Book Data*" cout<<"nThe book ID number is :"<<pwork->Booknum<<endl <<"The book name is:"<<pwork->Bname&l
34、t;<endl <<"The book author is:"<<pwork->author<<endl <<"The book output is:"<<pwork->publish<<endl <<"The book key word:"for(int i=0; i<5 ;i+) cout<<pwork->keyi<<""<<" " flag1
35、+;getch(); pwork=pwork->pnext; if(flag1=0) cout<<"tnNo Result !n" else cout<<"nThe link is empty !n" ;break; void Library:borrow() / 借书 unsigned long idnumber; cout<<"n*Welcome to borrow*n" cout<<"nPlease input the id number:"cin>
36、>idnumber; Book *pwork=headA; Book *pre; while(idnumber!=pwork->Booknum)&&(pwork->pnext!=NULL) pre=pwork;pwork=pwork->pnext; if(idnumber=pwork->Booknum) int flag3=0; Book *pwork2=headB; char stuname50; cout<<"nPlease input the student name:"gets(stuname); while
37、(pwork2!=NULL) if( strcmp(stuname,pwork2->student.Sname)=0) flag3+; pwork2=pwork2->pnext; if(flag3<Mbook) if(pwork=headA) headA=pwork->pnext; headB=order(headB,pwork);else pre->pnext=pwork->pnext; headB=order(headB,pwork); cout<<"ttbook name is:"<<pwork->Bn
38、ame; strcpy(pwork->student.Sname,stuname);cout<<"n input the tel:"cin>>pwork->student.tel; cout<<"n input the year:"cin>>pwork->student.year; cout<<"n input the mouth:"cin>>pwork->student.mouth; cout<<"ninput th
39、e date:"cin>>pwork->student.date; cout<<"n*n"cout<<"tbook name:"<<pwork->Bname;cout<<"nLENDER name:"<<pwork->student.Sname; cout<<"n tyou are succeed to borrowing"<<endl; else cout<<"nthe
40、 MAX borrow number is :"<<Mbook<<endl; else cout<<"nNO this bookn" void Library:Return() / 还书 unsigned long idnumber; cout<<"n*Welcome to return book*n"Book *pwork=headB;if(pwork!=NULL) cout<<"n input the id number:"cin>>idnumber
41、; Book *pre;while(idnumber!=pwork->Booknum)&&(pwork->pnext!=NULL) pre=pwork;pwork=pwork->pnext; if(idnumber=pwork->Booknum) char ch; cout<<"ttbook name is:"<<pwork->Bname; cout<<"ninput the student name:"<<pwork->student.Sname; co
42、ut<<"n input the tel:"<<pwork->student.tel; cout<<"n input the data:"<<pwork->student.year<<' '<<pwork->student.mouth<<' '<<pwork->student.date; cout<<"n*n" if(pwork=headB) headB=pwork->
43、;pnext; headA=order(headA,pwork);else pre->pnext=pwork->pnext; headA=order(headA,pwork); cout<<"ttbook name is:"<<pwork->Bname; strcpy(pwork->student.Sname,"NO NAME"); pwork->student.tel=0; pwork->student.year=0;pwork->student.mouth=0;pwork->st
44、udent.date=0; cout<<"n*n"cout<<"tbook name:"<<pwork->Bname<<endl;cout<<"nLENDER name:"<<pwork->student.Sname<<endl;cout<<"ntel number:"<<pwork->student.tel<<endl;cout<<"ndate:"
45、;<< pwork->student.year<<" "<<pwork->student.mouth<<" "<<pwork->student.date; cout<<"n tyou succeeed in Returning"<<endl; else cout<<"nNO this bookn" else cout<<"n THE Link is empty:"<
46、<endl; void Library:urge() /催还 int year; int mouth; int day; Book *pwork = headB; cout<<"n*Welcome to the Urge system*n" do cout<<"ninput the year:"cin>>year; while(year<1900|year>3000); do cout<<"ninput the mouth:"cin>>mouth; if(m
47、outh<1|mouth>12) cout<<"n ERROR ,please input again !n" while(mouth<1|mouth>12);int max;do cout<<"ninput the day:"cin>>day; if(mouth=2) if(year%4=0&&year%100!=0)|year%400=0) max=29; else max=28; else if(mouth<7&&mouth%2!=0)|(mouth&
48、gt;7&&mouth%2=0) ) max=31; else max=30; if(day>max|day<1) cout<<"n ERROR ,please input again !n" while(day>max|day<1); if(pwork!=NULL) while(pwork!=NULL) if(pwork->student.year<year)|( (pwork->student.year=year)&&(pwork->student.mouth<mouth)
49、 )|(pwork->student.year=year&&pwork->student.mouth=mouth&&pwork->student.date<=day) ) int total=0;int sum1=0;int sum2=0;int sum3=0;for(int j=pwork->student.year ; j<year ;j+) if(j%4=0&&j%100!=0)|j%400=0) sum1=sum1+366; else sum1=sum1+365; for(int i=1 ;i<p
50、work->student.mouth; i+) if(i=2) if(pwork->student.year%4=0&&pwork->student.year%100!=0)|pwork->student.year%400=0)sum2=sum2+29; elsesum2=sum2+28; else if(i<7&&i%2!=0)|(i>7&&i%2=0)sum2=sum2+31; elsesum2=sum2+30; sum2=sum2+pwork->student.date;for(int c=1 ;
51、c<mouth; c+) if(c=2) if(year%4=0&&year%100!=0)|year%400=0)sum3=sum3+29; elsesum3=sum3+28; else if(c<7&&c%2!=0)|(c>7&&c%2=0)sum3=sum3+31; elsesum3=sum3+30; sum3=sum3+day;total=sum1+sum3-sum2;if(total>MAX) cout<<"n*n" cout<<"ttbook name is
52、:"<<pwork->Bname; cout<<"ninput the student name:"<<pwork->student.Sname; cout<<"n input the tel:"<<pwork->student.tel; cout<<"n input the data:"<<pwork->student.year<<' '<<pwork->student.
53、mouth<<' '<<pwork->student.date; cout<<"nttotal days:"<<total; cout<<"n*n" getch(); pwork=pwork->pnext; else cout<<"nt ALL RETURNING n"void Library:deletebook() /删除图书Book *pwork=headA; Book *pre; cout<<"n*Dele
54、te book system*n" ; if(pwork!=NULL) unsigned long number; cout<<"ninput the number:"cin>>number; while(number!=pwork->Booknum)&&(pwork->pnext!=NULL) pre=pwork; pwork=pwork->pnext; if(number=pwork->Booknum) if(pwork=headA) headA=pwork->pnext; delete p
55、work; else pre->pnext=pwork->pnext; delete pwork; cout<<"n Succeed in delete bookn" else cout<<"nERROR ! NO THIS BOOK" else cout<<"n the book link is empty" int main() / 主函数 clrscr(); Library people; int number; cout<<"n*WELCOME TO THE
56、 LIBRARY *n" people.insert(); people.display(1); cout<<"n*n" cout<<"n library manger system:1 "<<endl <<" borrower system:2 "<<endl <<" Exit the library:0 "<<endl; do cout<<"nplease input your choice:"cin>>number; if(number=0) break; if(number=1) int number1; cout<<"nas a manager , you can select:nn" cout<<"nn Input Book data:1 "&
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026河南郑州华卓医院(荥阳二院)招聘54人备考题库附答案详解(达标题)
- 2026重庆西区医院招聘医务人员97人备考题库及答案详解(考点梳理)
- 《建筑太阳能热水系统安装施工手册》
- 2026吉林省旅游发展集团有限责任公司紧缺医疗专业技术人员专项招聘10人备考题库含答案详解(能力提升)
- 2026浙江万盛人才信息服务有限公司宁波分公司招聘站点安检备考题库附答案详解(精练)
- IT运维部门服务器故障排查五步法方案
- 2026湖南益阳安岳县引进急需紧缺专业人才93人备考题库及答案详解(必刷)
- 2026北京航空航天大学电子信息工程学院聘用编软件工程师F岗招聘3人备考题库及答案详解(必刷)
- 2026湖南益阳安岳县引进急需紧缺专业人才93人备考题库含答案详解(培优b卷)
- 电力设备设计与制造规范手册
- 交易中心建设工作方案
- 2026春新人教版三年级数学下册期中测试卷(附答案解析及评分标准)
- 2026年医院招聘临床《专业知识》试题预测试卷及答案详解【网校专用】
- 起重机械吊具和索具安全规程
- 辽宁出版集团招聘笔试题库2026
- 国际公法学(第三版)全套教学课件
- 勘察处管理制度
- 2025网格员招聘笔试必考题库(含答案)
- 法学网络诽谤行为的法律规制与责任认定毕业论文答辩
- 初升高语文专项知识点巩固练习题库
- DB61T 1986-2025《林木采伐技术规范》
评论
0/150
提交评论