C++图书馆实习报告.doc_第1页
C++图书馆实习报告.doc_第2页
C++图书馆实习报告.doc_第3页
C++图书馆实习报告.doc_第4页
C++图书馆实习报告.doc_第5页
已阅读5页,还剩36页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

程序设计实习报告( 2012-6-1 )姓名:秦炜杰 学号:110520021 日期: 2012-6-1一、题目 图书馆管理系统二、基本要求1类的基本操作要熟练,类的定义,类的创建,构造函数与析构函数的使用要熟练。2输入和输出要清晰,输入提示要清楚。三、实习报告1实习题:设一本书的基本资料由以下数据项来描述:1. 书号(设为一个无符号长整型);2. 书名(设为不超过30个字符的字符串);3. 作者名(设为不超过20个字符的字符串);4. 出版社(设为不超过30个字符的字符串);5. 关键词(最多5个,每个关键词为不超过10个字符的英文单词); 其中,设每本书的书号、书名、作者名和出版社均是惟一的。请用类形式来构造一个小型图书资料管理系统(模拟)。该系统应能提供以下常规功能:1. 图书资料库:从键盘输入各图书资料,建立图书资料库;设图书依书号从小到大次序组织存放;2. 查询功能:1) 读者可通过提供书名查询,若该书仍在库中,则列出该书资料;2) 读者可通过提供书号查询,若该书仍在库中,则列出该书资料;3) 读者也可通过提供关键词查询(最多5个:一般情况下,读者提供用于查询的关键词个数都不会超过在书库中登记的图书原有的关键词个数),若提供的关键词和原书中关键词相匹配,则列出所有符合要求的所有图书资料给读者选择;读者可从系统所列出可供选择的图书资料信息中,通过书号来办理借阅手续;3. 借书功能: 当所查询的图书的确字库内时,读者可采用提供书号形式来办理借阅手续(每次操作只能借一本书);1) 登记借阅人的姓名(不超过20个字符的字符串)、电话(无符号长整型整数)、借阅日期(年、月、日,均是整型量);2) 置“该图书已被借走”状态;4. 还书功能:(提供书号办理还书手续)1) 删去图书中该书借阅人的资料;2) 将该书资料归入“该图书仍在库内”状态;5. 催还功能: 管理人员定期列出借书人借阅图书资料,以便检查是否有超期借阅者,若有则发通知催还。时间计算只从该书借出那天起到当前工作日(20为期限)。请设计出符合要求的类并设计出模拟运行的主程序。说明:1. 理论上,图书资料库藏书量应没有限制(实际上是受硬件资料所限);2. 图书资料库可以采用以下组织形式:1) 每本图书的资料由基本资料和借阅人资料组成,所有图书资料由一个链表链接在一起;2) 每本图书的资料也由基本资料和借阅人资料组成,但所有图书资料分别由未借出链表和已借出链表链接在一起;3. 请先确定好图书资料组织形式,然后再考虑设计功能的实现。4. 模拟图书资料系统工作的主函数基本要求如下:1) 在键盘上输入每本图书资料,在存储区中建立图书资料库。因无法预知图书册数,可以设当输入书号为0时表示输入结束。图书资料库正常工作期间追加新入库图书时也如此办理;2) 输出图书库中所有在库图书资料清单,此操作只有管理人员使用;3) 输出图书库中已被借出的图书资料清单和追加图书,此操作只由管理人员使用;4) 查询图书、借阅图书、归还图书;5) 每借出一本图书或归还一本图书之后,输出书库内图书情况或借书人登记资料,以便核对操作是否完成;6) 书库内没有登记的图书,不能办理借阅手续。当然,不是在该图书库借出的图书也不能在此处办理还书手续。 2.解题的基本算法:(1)说明:定义两个结构体,书的基本资料,借书人的资料与其借书的日期。在书的基本资料中有一个指针,指向下一本图书。设计的类中,有两个指针作为数据成员,而函数成员有“插入图书”函数,“显示所有图书”函数,“合并指针”函数,“催还图书”函数,“删去一个节点”函数,“借书”函数,“还书”函数,“查询图书”函数,“求两个日期之间的天数”函数,“删除图书”函数。(2)程序运行时,将分为“图书馆管理人员”和“借书人界面”。系统管理人员的功能有追加图书,显示所有在库图书,显示所有已借出图书,催还图书,删除图书,查询图书,还书,借书。一般用户的功能有查询图书,借书,还书。(3)程序运行,初始化数据,进入主菜单,有三个选择,分别是1,2,0。选1就进入图书馆管理人员的菜单界面,选2就进入用户的菜单界面,选0就结束程序。(4)选1后,有9个选择:(由于管理员的权限已经包括用户的,所以此处只说明管理员的功能操作) 1.输入图书资料:输入的图书会按照书号从小到大的顺序插入到在库图书的链表中,当输入书号为0时,结束插入图书。2.输出所有在库图书:即输出未借出链表的节点,当链表为空时,输出提示。否则,当输出一本书后停止,按回车键输出下一本书,直到链表输完。3.输出所有借出的图书:即输出已经借出链表的节点,当链表为空时,输出提示。否则,当输出一本书后停止,按回车键输出下一本书,直到链表输完。4.催还图书:输入一个日期,利用求天数函数求出输入日期与借书日期之间的天数,如果天数大于规定还书天数,就发催还通知。5. 删除图书:输入书号,从未借出链表中删除该图书,并撤销该节点和令指向该节点的指针为空。6.查询图书,有三种方法查询图书: 书名查询:输入书名,在未借出链表中查询,有则输出该图书,否则输出提示。 书号查询:输入书号,在未借出链表中查询,有则输出该图书,否则书出提示。 关键词查询:输入最多5个关键词,与未借出链表中的节点的关键词匹配,如果所有关键词都符合,就输出该书,与下本书匹配。直到链表完结。7.借书:输入书号,该书在未借出链表中存在时,接着输入借书人姓名,当该借书人所借的书不多与2本时,输完借书人资料,借出图书,如果多余2本,输出提示,借书不成功。当该书不存在时,输出提示,借书不成功。8.还书:输入书号,如果该书在已借出链表中存在时,借书成功,否则输出提示,借书不成功。 0.返回主菜单。 3.程序流程图输入1进入主菜单,有1,2,0三个选择输入2输入0进入管理人员菜单显示菜单有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并且keynext输出没有书返回催还图书输入一个日期计算出借出日期和输入日期之间的天数day规定归还期限为MAX=20天链的头指针h=NULL?pwork=hpwork=NULL?dayMAX输出图书资料pwork=pwork-next返回删除图书输入书号在链中搜索图书在链中?令目标节点的上一个节点指向目标节点的下个节点撤消目标节点令目标节点的指针为NULL返回查询图书输出有1,2,3,0选择输入选择输入3输入1输入2输入0输入书号输入关键词输入书名在链中查找图书在链中?输出图书资料返回借出图书输入书号在在库图书链中查找图书存在?输入借书人姓名此人借书量少于MAX每人最多借书MAX=2本输入借书人电话号码输入借书日期在在库图书链中删除该书把该书插入已借图书链中继续?返回归还图书输入书号在已借出图书链中查找该书图书存在?把该书的节点从已借链中删除把该书插入在库图书链中返回4.源程序代码#include#include#include#include#includeconst int Mbook=2; / 每人最多只能借两本书 struct Student / 借书人的资料 char Sname50; / 所借出书的名称 unsigned 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: 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:Library() /构造函数,设置两个指针为空 headA=NULL; headB=NULL; coutMAX;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; 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-Booknumpwork1-Booknum)& (pwork1-pnext!=NULL) ) pre=pwork1;pwork1=pwork1-pnext; if(pwork1-Booknum) (pwork-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 coutn*book data*n; coutnumber; if(number=0) break; pwork=new Book; pwork-Booknum=number; coutBname); coutauthor); coutpublish); 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;i5;i+) coutninput the key wordi+1keyi); headA=order(headA,pwork);while(number0); coutendl;void Library:display(int number) / 显示图书 switch(number) case 1:coutn*Unborrow LIST*n; Book *pwork=headA; if(pwork!=NULL) while(pwork!=NULL) coutn*Book Data*n; coutnThe books ID number is :Booknumendl The books name is:Bnameendl The books author is:authorendl The books publish is:publishendl The books key word:;for(int i=0; i5 ;i+) coutkeyipnext; else coutnHas no book in the library !n; ;break; case 2:coutn*Borrow List*n; Book *pwork=headB; if(pwork!=NULL) while(pwork!=NULL) coutn*Book Data*n; coutnThe books ID number is :Booknumendl The books name is:Bnameendl The books author is:authorendl The books publish is:publishendl The books key word:;for(int i=0; i5 ;i+) coutkeyi ; coutnThe lender is:student.Snameendl The telephone is:student.telendlThe.date.is:student.year.student.mouth.student.datepnext; else coutnHas no book borrow !n; ;break; void Library:check_show() / 查询图书 Book *pwork=headA; int number; coutn*Welcome to check book *n; coutnPlease, how do you want to check ? :n; coutn book number:1 endl book name:2 endl key word:3 endl; coutnumber; switch(number) case 1:unsigned long idnumber; int flag1=0; /书号查询 coutidnumber; if(pwork!=NULL) while(pwork!=NULL) if(idnumber=pwork-Booknum) coutn*Book data*; coutnthe book ID number is :Booknumendl the book name is:Bnameendl the book author is:authorendl the book output is:publishendl the book key word:;for(int i=0; i5 ;i+) coutkeyi|pnext; if(flag1=0) couttnNO Resultn; else coutnthe link is emptyn; ;break; case 2:char bname100; int flag1=0; / 书名查询 coutBname,bname)=0) coutn*Book Data*; coutnThe book ID number is :Booknumendl The book name is:Bnameendl The book author is:authorendl The book publish is:publishendl The book key word:;for(int i=0; i5 ;i+) coutkeyipnext; if(flag1=0) couttnNo Result !n; else coutnThe link is empty !n; ;break; case 3:char key550; char key250; int flag1=0; int count=0; char ch; do coutnPlease input the key word(0 to end):;gets(key2); if(strcmp(key2,0)=0) break; strcpy(keycount,key2); count+; while(count5); if(pwork!=NULL) while(pwork!=NULL) int flag=0; for(int i=0; icount ;i+) int flag1=0; for(int j=0; jkeyj)=0) if(flag1=0) flag1+; flag+; if(flag=count) coutn*Book Data*; coutnThe book ID number is :Booknumendl The book name is:Bnameendl The book author is:authorendl The book output is:publishendl The book key word:;for(int i=0; i5 ;i+) coutkeyipnext; if(flag1=0) couttnNo Result !n; else coutnThe link is empty !n; ;break; void Library:borrow() / 借书 unsigned long idnumber; coutn*Welcome to borrow*n; coutidnumber; 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; coutstudent.Sname)=0) flag3+; pwork2=pwork2-pnext; if(flag3pnext; headB=order(headB,pwork);else pre-pnext=pwork-pnext; headB=order(headB,pwork); coutttbook name is:Bname; strcpy(pwork-student.Sname,stuname);coutpwork-student.tel; coutpwork-student.year; coutpwork-student.mouth; coutpwork-student.date; coutn*n;couttbook name:Bname;coutnLENDER name:student.Sname; coutn tyou are succeed to borrowingendl; else coutnthe MAX borrow number is :Mbookendl; else coutnNO this bookn; void Library:Return() / 还书 unsigned long idnumber; coutn*Welcome to return book*n;Book *pwork=headB;if(pwork!=NULL) coutidnumber; Book *pre;while(idnumber!=pwork-Booknum)&(pwork-pnext!=NULL) pre=pwork;pwork=pwork-pnext; if(idnumber=pwork-Booknum) char ch; coutttbook name is:Bname; coutninput the student name:student.Sname; coutn input the tel:student.tel; coutn input the data:student.year student.mouth student.date; coutpnext; headA=order(headA,pwork);else pre-pnext=pwork-pnext; headA=order(headA,pwork); coutttbook name is:Bname; strcpy(pwork-student.Sname,NO NAME); pwork-student.tel=0; pwork-student.year=0;pwork-student.mouth=0;pwork-student.date=0; coutn*n;couttbook name:Bnameendl;coutnLENDER name:student.Snameendl;coutntel number:student.telendl;coutndate:student.year student.mouth student.date; coutn tyou succeeed in Returningendl; else coutnNO this bookn; else coutn THE Link is empty:endl; void Library:urge() /催还 int year; int mouth; int day; Book *pwork = headB; coutn*Welcome to the Urge system*n; do coutyear; while(year3000); do coutmouth; if(mouth12) coutn ERROR ,please input again !n; while(mouth12);int max;do coutday; if(mouth=2) if(year%4=0&year%100!=0)|year%400=0) max=29; else max=28; else if(mouth7&mouth%2=0) ) max=31; else max=30; if(daymax|day1) coutmax|daystudent.yearstudent.year=year)&(pwork-student.mouthstudent.year=year&pwork-student.mouth=mouth&pwork-student.datestudent.year ; jyear ;j+) if(j%4=0&j%100!=0)|j%400=0) sum1=sum1+366; else sum1=sum1+365; for(int i=1 ;istudent.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(i7&i%2=0)sum2=sum2+31; elsesum2=sum2+30; sum2=sum2+pwork-student.date;for(int c=1 ;cmouth; c+) if(c=2) if(year%4=0&year%100!=0)|year%400=0)sum3=sum3+29; elsesum3=sum3+28; else if(c7&c%2=0)sum3=sum3+31; elsesum3=sum3+30; sum3=sum3+day;total=sum1+sum3-sum2;if(totalMAX) coutn*n; coutttbook name is:Bname; coutninput the student name:student.Sname; coutn input the tel:student.tel; coutn input the data:student.year student.mouth student.date; coutnttotal days:total; coutpnext; else coutnt ALL RETURNING n;void Library:deletebook() /删除图书Book *pwork=headA; Book *pre; coutn*Delete book system*n ; if(pwork!=NULL) unsigned long number; coutnumber; while(number!=pwork-Booknum)&(pwork-pnext!=NULL) pre=pwork; pwork=pwork-pnext; if(number=pwork-Booknum) if(pwork=headA) headA=pwork-pnext; delete pwork; else pre-pnext=pwork-pnext; delete pwork; coutn Succeed in delete bookn; else coutnERROR ! NO THIS BOOK; else coutn the book link is empty; int main() / 主函数 clrscr(); Library people; int number; coutn*WELCOME TO THE LIBRARY *n; people.insert(); people.display(1); coutn*n; coutn library manger system:1 endl borrower system:2 endl Exit the library:0 endl; do co

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论