收藏 分销(赏)

C--图书馆实习报告.doc

上传人:仙人****88 文档编号:8749688 上传时间:2025-02-28 格式:DOC 页数:40 大小:254KB 下载积分:10 金币
下载 相关 举报
C--图书馆实习报告.doc_第1页
第1页 / 共40页
C--图书馆实习报告.doc_第2页
第2页 / 共40页


点击查看更多>>
资源描述
《程序设计》实习报告( 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并且key<5? 输入关键词 key=0 key++ 输入书号 返回 输出在库图书 链的头指针h为NULL? pwork=h pwork等于NULL? 输出书名 输出作者名 输出出版社名 输出关键词 pwork=pwork->next 输出没有书 返回 催还图书 输入一个日期 计算出借出日期和输入日期之间的天数day 规定归还期限为MAX=20天 链的头指针h=NULL? pwork=h pwork=NULL? day>MAX 输出图书资料 pwork=pwork->next 返回 删除图书 输入书号 在链中搜索 图书在链中? 令目标节点的上一个节点指向目标节点的下个节点 撤消目标节点 令目标节点的指针为NULL 返回 查询图书 输出有1,2,3,0选择 输入选择 输入3 输入1 输入2 输入0 输入书号 输入关键词 输入书名 在链中查找 图书在链中? 输出图书资料 返回 借出图书 输入书号 在在库图书链中查找 图书存在? 输入借书人姓名 此人借书量少于MAX 每人最多借书MAX=2本 输入借书人电话号码 输入借书日期 在在库图书链中删除该书 把该书插入已借图书链中 继续? 返回 归还图书 输入书号 在已借出图书链中查找该书 图书存在? 把该书的节点从已借链中删除 把该书插入在库图书链中 返回 4.源程序代码 #include<iostream.h> #include<conio.h> #include<string.h> #include<stdio.h> #include<stdlib.h> const int Mbook=2; // 每人最多只能借两本书 struct Student // 借书人的资料 { char Sname[50]; // 所借出书的名称 unsigned long tel; // 借书人的电话 int year; // 所借年份 int mouth; // 所借月份 int date; // 所借天 }; struct Book // 书本的资料 { unsigned long Booknum; // 书本的号码 char Bname[100]; // 书本的名字 char author[50]; // 书本的作者 char publish[50]; // 书本的出版社 char key[5][50]; // 书本的关键字 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; 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; 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) > (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 { cout<<"\n************book data***************\n"; 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 the 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<<"]:";gets(pwork->key[i]); } 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<<"\nThe 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->publish<<endl <<"The book's key word:"; for(int i=0; i<5 ;i++) { cout<<pwork->key[i]<<"@"<<" "; } getch(); pwork=pwork->pnext; } } else cout<<"\nHas no book in the library !\n"; };break; case 2:{cout<<"\n*******Borrow List**************\n"; Book *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:"<<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->key[i]<<"@"<<" "; } cout<<"\nThe lender is:"<<pwork->student.Sname<<endl <<"The telephone is:"<<pwork->student.tel<<endl <<"The..date..is:"<<pwork->student.year<<'.'<<pwork->student.mouth<<'.'<<pwork->student.date<<endl; getch(); 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: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>>idnumber; 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:"<<pwork->author<<endl <<"the book output is:"<<pwork->publish<<endl <<"the book key word:"; for(int i=0; i<5 ;i++) { cout<<pwork->key[i]<<"||"<<" "; } flag1++; } pwork=pwork->pnext; } if(flag1==0) cout<<"\t\nNO Result\n"; } else cout<<"\nthe link is empty\n"; };break; case 2:{char bname[100]; 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*********"; cout<<"\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<<endl <<"The book key word:"; for(int i=0; i<5 ;i++) { cout<<pwork->key[i]<<"@"<<" "; } flag1++; getch(); } pwork=pwork->pnext; } if(flag1==0) cout<<"\t\nNo Result !\n"; } else cout<<"\nThe link is empty !\n"; };break; case 3:{char key[5][50]; char key2[50]; 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(key[count],key2); count++; }while(count<5); if(pwork!=NULL) { while(pwork!=NULL) {int flag=0; for(int i=0; i<count ;i++) { int flag1=0; for(int j=0; j<5 ;j++) if(strcmp(key[i],pwork->key[j])==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<<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->key[i]<<"@"<<" "; } flag1++; getch(); } pwork=pwork->pnext; } if(flag1==0) cout<<"\t\nNo 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>>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 stuname[50]; cout<<"\nPlease input the student name:";gets(stuname); while(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<<"\t\tbook name is:"<<pwork->Bname; 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 the 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 MAX borrow number is :"<<Mbook<<endl; } } else cout<<"\nNO this book\n"; } 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; Book *pre; while((idnumber!=pwork->Booknum)&&(pwork->pnext!=NULL)) { pre=pwork;pwork=pwork->pnext; } if(idnumber==pwork->Booknum) { char ch; cout<<"\t\tbook name is:"<<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.mouth<<' '<<pwork->student.date; cout<<"\n********************************\n"; { if(pwork==headB) { headB=pwork->pnext; headA=order(headA,pwork); } else { pre->pnext=pwork->pnext; headA=order(headA,pwork); } cout<<"\t\tbook name is:"<<pwork->Bname; strcpy(pwork->student.Sname,"NO NAME"); pwork->student.tel=0; pwork->student.year=0;pwork->student.mouth=0;pwork->student.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:"<< pwork->student.year<<" "<<pwork->student.mouth<<" "<<pwork->student.date; cout<<"\n \tyou succeeed in Returning"<<endl; } } else cout<<"\nNO this book\n"; } else { cout<<"\n THE Link is empty:"<<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(mouth<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!
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传

当前位置:首页 > 教育专区 > 小学其他

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2026 宁波自信网络信息技术有限公司  版权所有

客服电话:0574-28810668  投诉电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服