版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、武汉理工大学基础强化训练课程设计图书馆库存信息管理一、系统描述图书馆库存信息管理的基础强化训练要求学生自己设计并编制一个小型并具有一定功能的图书管理系统,该系统要求能对图书的库存信息进行一定的统计,不要求采用数据库和图形化界面,只要求在命令提示符的界面下对图书的入库、出库、修改、增加进行操作即可,对数据的存储以文件的形式存储在外存中。二、需求分析1、功能需求(1)图书入库(一本书的各个信息,书名 ISBN等)(2)图书出库(3)修改一条图书记录(4)查询图书记录2、数据物理存储结构以及逻辑存储结构武汉理工大学基础强化训练课程设计(1)每本书采用一个结构体来定义其特点如 struct LNode
2、 int sequenceNum; /图书序号string ISBN; /ISBN编号string BookName; /书名string press; /出版社string author; /作者string date_of_in; /入库时间string date_of_out; /出库时间int store_number; /库存数double price; /单价LNode * next; /指向下一个图书;在进行数据处理的时候,每本书的消息记录存储在一个文本文档中,以便对大量外存中的数据进行操作(2)逻辑结构武汉理工大学基础强化训练课程设计采用一个单链表来对每本书进行索引,单链表的节
3、点为书本信息的结构体,当对一个节点进行操作是,若是打印节点的信息,则从文件中首先取出信息写到内存中,然后再在命令提示符中打印出来;若是进行图书出库或者图书信息的修改,则是先写到节点中,然后在保存到文件中。三、详细设计#include<windows.h>/获取系统日期#include<fstream>#include<iostream>#include<string>#include<sstream>/istringstream#include<cstdlib>#include<stdio.h>using na
4、mespace std;enum query_form BookName,press,author,ISBN;template <class T>bool from_string(T& t, const string& s, ios_base& (*f)(ios_base&)/字符串类型转换istringstream iss(s);return !(iss >> f >> t).fail();/*函数声明*/void menu(); /主 菜单void sub_menu_Query(); /查询记录 菜单void ADD();
5、 /增加记录void Modify(); /修改记录void Delete(); /删除记录void query(int choice_of_query,string query_keyword); /查询记录string get_date()/获取当前系统日期并转换成yyyy-mm-dd格式string str;char s10;SYSTEMTIME st;GetSystemTime(&st);武汉理工大学基础强化训练课程设计sprintf(s,"%d",st.wYear); str= s;str+="-"sprintf(s,"%d&
6、quot;,st.wMonth); str+=s; str+="-"sprintf(s,"%d",st.wDay);str+=s;return str;/*类型定义*/struct LNodeint sequenceNum; /图书序号string ISBN; /ISBN编号string BookName; /书名string press; /出版社string author; /作者string date_of_in; /入库时间string date_of_out; /出库时间int store_number; /库存数double price; /
7、单价LNode * next; /指向下一个图书;/*链表基本操作*/LNode * CreateDefaultLink( )/创建以默认数据建立的链表ifstream book("Bookmanagement.txt");if(!book)cerr<<"打开文件失败!"<<endl;char * s="Bookmanagement.txt"cout<<"请重新输入完整文件路径及文件名(盘符:路径文件名.txt):"<<endl; cin>>s;book.
8、open(s);LNode *p1,*p2,*head=NULL;p1=p2=new LNode;p1->next =NULL;int i=0,j=1;string read,r11; /read用来读取每一行关键字,r1-r9依次用来保存每个结点的关键字getline(book,read);read.append(1,'n');武汉理工大学基础强化训练课程设计while(j<10)string temp;while( readi!= 'n'&& readi+!='t')temp.append(1,readi-1);/
9、依次分离一个单词,每个单词之间用 垂直制表符分割rj=temp;j+;from_string<in、t>(p1->sequenceNum, r1, dec);p1->ISBN = r2;p1->BookName = r3;p1->author = r4;p1->press = r5;from_string<int>(p1->store_number, r6, dec);from_string<double>(p1->price, r7, dec);p1->date_of_in=r8;p1->date_of
10、_out=r9;while(!book.eof()if(head=NULL)head=p1;else p2->next=p1;p2=p1;p1=new LNode;p1->next=NULL;getline(book,read);read.append(1,'n');i=0,j=1;while(j<10)string temp;while(readi!='n' && readi+!='t')temp.append(1,readi-1);/依次将一个单词rj=temp;j+;武汉理工大学基础强化训练课程设计from
11、_string<int>(p1->sequenceNum, r1, dec);/将r1转换成int型,序号 p1->ISBN = r2;p1->BookName = r3;p1->author = r4;p1->press = r5;from_string<int>(p1->store_number, r6, dec);/将r6转换成int型,库存数 from_string<double>(p1->price, r7, dec);/将r7转换成double型,单价p1->date_of_in=r8;p1->
12、;date_of_out=r9;return head;book.close();void main()system("color f1"); /改变当前控制台窗口的背景颜色为F(白色),字体颜色为1(蓝色) menu();system("pause");/*函数实现*/void menu()cout<<"*"<<endl;cout<<"* "<<endl;cout<<"* 图书库存管理系统"<<endl;cout<&
13、lt;"* 选择一个操作: *"<<endl;cout<<"* <1> 图书入库 *"<<endl;cout<<"* <2> 修改一条图书记录 *"<<endl;cout<<"* <3> 图书出库 *"<<endl;cout<<"* <4> 查询图书记录 *"<<endl;cout<<"* <5> 清屏 *&
14、quot;<<endl;cout<<"* <6> 退出系统 *"<<endl;cout<<"*"<<endl;cout<<endl;int choice=6;cout<<" 请输入您的选择(1-6):"<<endl;武汉理工大学基础强化训练课程设计cin>>choice;while (choice<1 | choice>6)cout<<" 输入不正确!请重新再输入一个1至6之间的整数
15、:"<<endl; cin>>choice;cout<<"nnnn"switch(choice)case 1:cout<<"nnnn"ADD();break;case 2:cout<<"nnnn"Modify();break;case 3:cout<<"nnnn"Delete();break;case 4:cout<<"nnnn"sub_menu_Query();break;case 5:system(
16、"cls");menu();break;case 6:exit(0);void ADD()cout<<"请依次按照顺序输入图书的信息: ISBN编号 书名 作者 出版社 单价"<<endl;LNode *new_book=new LNode;char t60;cin>>new_book->ISBN;cin>>new_book->BookName;cin.get();gets(t); new_book->author=t;cin>>new_book->press;cin.g
17、et();gets(t);new_book->price=atof(t);new_book->date_of_in=get_date();new_book->sequenceNum=0;/初始化图书的序号,后面再修改。cout<<"您输入的图书的信息是:"<<endl;cout<<"ISBN编号 书名 作者 出版社 单价"<<endl;cout<<new_book->ISBN<<"t"<<new_book->BookNam
18、e<<"t"<<new_book->author<<"t"<<new_book->press<<"t"<<new_book->price<<"t"<<new_book->date_of_in<<endl;/查找该书是否存在,如果是,打印信息,并将其库存数加1.如果没有,则插入到链表的最后。LNode *x= CreateDefaultLink();武汉理工大学基础强化训练课程设计LNo
19、de *head=x;int exist_tag=0; /图书存在识别标志while(x->next!=NULL && (int)x->store_number)if( new_book->ISBN.compare(x->ISBN)=0)/判断入库图书是否已经存在,使用ISBN判别cout<<endl;cout<<"此书已经存在,库存数目加1"<<endl;x->store_number+;exist_tag=1; /图书存在识别标志.break;x=x->next;if(exist_t
20、ag=0)cout<<"此书是新书,文件记录中将放到最后"<<endl;new_book->sequenceNum=x->sequenceNum+1;new_book->store_number=1;x->next=new_book;new_book->next=NULL;/写入文件,因为是文本模式打开的,所以要全部重写文件。ofstream output_book("Bookmanagement.txt",ios:trunc);cout<<"是否将修改写入文件?(Y/N)&qu
21、ot;<<endl;char decision;cin>>decision;if(decision ='y' |decision ='Y')output_book<<"序号 ISBN 书名 作者 出版社 库存数 单价 入库时间 出库时间n"head=head->next;/跳过第一行while(head)output_book<<head->sequenceNum<<"t"<<head->ISBN<<"t&quo
22、t;<<head->BookName<<"t"<<head->author<<"t"<<head->press<<"t"<<head->store_number<<"t"<<head->price<<"t"<<head->date_of_in<<"t"<<head->date_of
23、_out<<"n"head=head->next;武汉理工大学基础强化训练课程设计cout<<"写入完毕nn"output_book.close();system("%windir%notepad.exe Bookmanagement.txt");system("pause");cout<<"是否继续?(Y/N):"<<endl;cin>>decision;if(decision ='y' |decision =&
24、#39;Y')menu();else cout<<"谢谢使用!"<<endl;void Delete()cout<<"请选择要出库的ISBN编号:"LNode *new_book=new LNode;cin>>new_book->ISBN;LNode *x= CreateDefaultLink();LNode *head=x;int exist_tag=0; /图书存在识别标志while(x!=NULL && x->store_number)if( new_book-&g
25、t;ISBN.compare(x->ISBN)=0)/判断入库图书是否已经存在,使用ISBN判别cout<<endl;cout<<"此书书库中存在"<<endl;cout<<"ISBN编号 书名 作者 出版社 单价"<<endl;cout<<x->ISBN<<"t"<<x->BookName<<"t"<<x->author<<"t"<&
26、lt;x->press<<"t"<<x->price<<"t"<<x->date_of_in<<endl;x->store_number-;/库存数减少1exist_tag=1; /图书存在识别标志.break;x=x->next;if(exist_tag=0)cout<<"此书书库中不存在,不可以出库!"<<endl;/写入文件,因为是文本模式打开的,所以要全部重写文件。else武汉理工大学基础强化训练课程设计ofstr
27、eam output_book("Bookmanagement.txt");cout<<"是否将修改写入文件?(Y/N)"<<endl;char deci;cin>>deci;if(deci ='y' |deci ='Y')output_book<<"序号 ISBN 书名 作者 出版社 库存数 单价 入库时间 出库时间n"head=head->next;/跳过第一行while(head)output_book<<head->sequ
28、enceNum<<"t"<<head->ISBN<<"t"<<head->BookName<<"t"<<head->author<<"t"<<head->press<<"t"<<head->store_number<<"t"<<head->price<<"t"<
29、<head->date_of_in<<"t"<<head->date_of_out<<"n"head=head->next;cout<<"写入完毕!"<<endl;output_book.close();char decision;cout<<"是否继续?(Y/N):"<<endl;cin>>decision;if(decision ='y' |decision ='Y
30、39;)menu();else cout<<"谢谢使用!"<<endl;void Modify()cout<<"请选择要修改的ISBN编号:"<<endl;string ISBN_of_Modify;cin>>ISBN_of_Modify;LNode *x= CreateDefaultLink();LNode *head=x;int exist_tag=0; /图书存在识别标志while(x!=NULL && x->store_number)if( ISBN_of_Mpar
31、e(x->ISBN)=0)/判断入库图书是否已经存在,使用ISBN判别cout<<endl;cout<<"此书书库中存在"<<endl;武汉理工大学基础强化训练课程设计cout<<x->ISBN<<"t"<<x->BookName<<"t"<<x->author<<"t"<<x->press<<"t"<<x->pric
32、e<<"t"<<x->date_of_in<<endl;cout<<"请依次按照顺序输入图书的信息: ISBN编号 书名 作者 出版社 单价"<<endl;char t60;cin>>x->ISBN;cin>>x->BookName;cin.get();gets(t); x->author=t;cin>>x->press;cin.get();gets(t);x->price=atof(t);x->date_of_in=
33、get_date();cout<<"您输入的图书的信息是:"<<endl;cout<<"ISBN编号 书名 作者 出版社 单价"<<endl;cout<<x->ISBN<<"t"<<x->BookName<<"t"<<x->author<<"t"<<x->press<<"t"<<x->pric
34、e<<"t"<<x->date_of_in<<endl;exist_tag=1; /图书存在识别标志.break;x=x->next;if(exist_tag=0)cout<<"此书书库中不存在!"<<endl;/写入文件,因为是文本模式打开的,所以要全部重写文件。elseofstream output_book("Bookmanagement.txt",ios:trunc);cout<<"是否将修改写入文件?(Y/N)"<&
35、lt;endl;char deci;cin>>deci;if(deci ='y' |deci ='Y')output_book<<"序号 ISBN 书名 作者 出版社 库存数 单价 入库时间 出库时间n"head=head->next;/跳过第一行while(head)武汉理工大学基础强化训练课程设计output_book<<head->sequenceNum<<"t"<<head->ISBN<<"t"<&l
36、t;head->BookName<<"t"<<head->author<<"t"<<head->press<<"t"<<head->store_number<<"t"<<head->price<<"t"<<head->date_of_in<<"t"<<head->date_of_out<
37、<"n"head=head->next;cout<<"写入完毕!"<<endl;output_book.close();char decision;cout<<"是否继续?(Y/N):"<<endl;cin>>decision;if(decision ='y' |decision ='Y')menu();else cout<<"谢谢使用!"<<endl;void sub_menu_Quer
38、y()cout<<"* 选择一个查询方式 *"<<endl;cout<<"* <1> 按 书名 查询 *"<<endl;cout<<"* <2> 按 ISBN 序列号查询 *"<<endl;cout<<"* <3> 按 作者 查询 *"<<endl;cout<<"* <4> 按 出版社 查询 *"<<endl;cout<&l
39、t;"* <5> 清屏 *"<<endl;cout<<"* <6> 返回上级菜单 *"<<endl;cout<<"*"<<endl;cout<<endl;int choice;cout<<" 请输入您的选择(1-6):"<<endl;cin>>choice;if (choice<1 | choice>6)cout<<" 输入不正确!请重新再输入一个1至
40、6之间的整数:"<<endl; cin>>choice;switch(choice)case 1:cout<<"请输入要查询的 书名(不提供模糊查询,请输入准确关键 12武汉理工大学基础强化训练课程设计字) :"<<endl;string name;cin.clear(); /更改cin的状态标示符cin.sync(); /清除输入缓存区的数据流getline(cin,name,'n');query (1,name);break;case 2:cout<<" 请输入要查询的 IS
41、BN 编号(不提供模糊查询,请输入准确关键字):"<<endl;string ISBN;cin.clear(); /更改cin的状态标示符cin.sync(); /清除输入缓存区的数据流getline(cin,ISBN,'n');query (2,ISBN);break;case 3:cout<<" 请输入要查询的 作者(不提供模糊查询,请输入准确关键字):"<<endl;string author;cin.clear(); /更改cin的状态标示符cin.sync(); /清除输入缓存区的数据流getline(
42、cin,author,'n');query (3,author);break;case 4:cout<<" 请输入要查询的 出版社(不提供模糊查询,请输入准确关键字):"<<endl;string press;cin.clear(); /更改cin的状态标示符cin.sync(); /清除输入缓存区的数据流getline(cin,press,'n');query (4,press);break;case 5:system("cls");sub_menu_Query();break;case 6:me
43、nu();武汉理工大学基础强化训练课程设计cout<<"是否需要打印全部图书信息?(y/n)"<<endl;char decision;cin>>decision;if(decision ='y' |decision ='Y')LNode *head=CreateDefaultLink();cout<<"序号 ISBN编号 书名 作者 出版社 "<<endl;head=head->next;/跳过第一行while(head)cout<<head-
44、>sequenceNum<<" "<<head->ISBN<<" "<<head->BookName<<" "<<head->author<<" "<<head->press<<"n"head=head->next;cout<<endl;cout<<"是否继续查询?(Y/N):"<<endl;cin
45、>>decision;if(decision ='y' |decision ='Y')sub_menu_Query();else cout<<"谢谢使用!"<<endl;void query(int choice_of_query,string query_keyword)LNode * t=CreateDefaultLink();switch (choice_of_query)case 1:int find_tag=0;while(t && t->store_number)if( q
46、uery_pare(t->BookName)=0)cout<<t->sequenceNum<<"t"<<t->ISBN<<"t"<<""<<t->BookName<<""<<"t"<<t->author<<"t"<<t->press<<"t"<<t->price
47、<<endl;cout<<endl;find_tag=1;武汉理工大学基础强化训练课程设计t=t->next;if (find_tag=0)cout<<"对不起,未找到您所要求的图书!"<<endl;break;break;case 2:int find_tag=0;while(t && t->store_number)if( query_pare(t->ISBN)=0)cout<<t->sequenceNum<<"t"<<t-&g
48、t;ISBN<<"t"<<""<<t->BookName<<""<<"t"<<t->author<<"t"<<t->press<<"t"<<t->price<<endl; cout<<endl;find_tag=1;t=t->next;if (find_tag=0)cout<<"对不
49、起,未找到您所要求的图书!"<<endl;break;break;case 3:int find_tag=0;while(t && t->store_number)if( query_pare(t->author)=0)cout<<t->sequenceNum<<"t"<<t->ISBN<<"t"<<""<<t->BookName<<""<<"
50、t"<<t->author<<"t"<<t->press<<"t"<<t->price<<endl; 15武汉理工大学基础强化训练课程设计cout<<endl;find_tag=1;t=t->next;if (find_tag=0)cout<<"对不起,未找到您所要求的图书!"<<endl;break;break;case 4:int find_tag=0;while(t && t->store_number)if( query_pare(t->
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 小学英语口语教学中游戏化教学法的实践效果分析课题报告教学研究课题报告
- 《项目式学习策略在高中物理课堂中的实践与教学效果评价研究》教学研究课题报告
- 中学数学智能教学助手:行为预测与数学问题解决策略培养策略研究教学研究课题报告
- 人工智能在跨学科教学评价中的应用与评价体系构建策略教学研究课题报告
- 2024年温州理工学院马克思主义基本原理概论期末考试真题汇编
- 2024年哈尔滨华德学院马克思主义基本原理概论期末考试笔试真题汇编
- 2025年广东水利电力职业技术学院马克思主义基本原理概论期末考试真题汇编
- 2025年喀什大学马克思主义基本原理概论期末考试真题汇编
- 2024年可克达拉职业技术学院马克思主义基本原理概论期末考试笔试题库
- 2025年惠州经济职业技术学院马克思主义基本原理概论期末考试笔试题库
- 矿产企业管理办法
- 企业账期管理暂行办法
- 从大庆油田股权改革透视公司股权结构优化与治理创新
- 慈善春节慰问活动方案
- 2025至2030中国电地暖系统行业市场现状分析及竞争格局与投资发展报告
- 互联网金融浪潮下A银行网点智能轻型化转型之路
- 胸科手术麻醉管理专家共识
- 物联网智能家居设备智能控制手册
- (二模)东北三省三校2025年高三第二次联合模拟考试 英语试卷(含答案解析)
- 福建省泉州市2024-2025学年高一上学期期末质量监测生物试题(原卷版+解析版)
- 10千伏环网柜(箱)标准化设计方案 (2023 版)
评论
0/150
提交评论