Linux大实验 (图书管理系统)

《程序设计基础综合实验》讲义

综合实验又称为课程设计,需要学生综合运用所学知识解决与实际应用紧密结合的、规模较大的问题,通过分析、设计、编码和调试等各环节的训练,使学生深刻理解、牢固掌握、综合运用数据结构和算法设计技术,增强分析问题、解决问题的能力,培养项目管理与团队合作精神。
本课程要求实验采用基本的软件工程开发方法,将软件开发过程分为需求分析、系统设计、编码实现、系统测试4个阶段。每个阶段设置相应的里程碑进行检查,对学生的设计过程进行评价。
(1)需求分析阶段
首先要充分分析和理解问题,明确要求做什么?限制条件是什么?即要确定需要实验那些功能(任务),并对所需完成的任务做出明确的回答,如,输入数据的类型、值的范围及输入的形式;输出数据的类型、值的范围及输出的形式;若是会话式输入,结束标志是什么?是否接受非法输入?对非法输入的回答方式是什么等。另外,还应该为调试程序准备好测试数据,包括合法的输入数据与非法的输入数据。同时,实验小组应该对设计工作进行分工,并形成小组成员通过的书面记录。
(2)概要设计和详细设计阶段
设计通常分为概要设计与详细设计两步。
在进行概要设计时,确定数据的逻辑结构,并要求按照自顶向下逐步求精的原则划分模块,画出模块间的调用关系图。
在进行详细设计时,要求定义数据的存储,并画出各模块(函数)的程序流程图或写出伪代码。
(3)编码实现阶段
在详细设计的基础上,用特定的程序设计语言编写程序。良好的程序设计风格可以保证较快地完成程序测试。程序的每行不要太长,每个函数不要太大,当一个函数太大时,可以考虑将其分解为较小的函数。对函数功能、核心语句、重要的类型和变量等应给出注释。一定要按凹入格式书写程序,分清每条语句的凹入层次,上下对齐层次的括号,以便发现语法错误。
(4)测试阶段
采用测试数据进行测试,列出实际的输入、输出结果、预期结果。
(5)总结与整理报告阶段
调试正确后认真整理源程序及注释,提交带有完整注释且格式良好的源程序,并撰写课程设计报告。
课程设计报告中除了上面提到的分析、设计过程外,还用给出下面几方面的内容。
① 调试分析:调试过程中主要遇到哪些问题?如何解决的?
② 算法分析:核心算法的时间复杂性与空间复杂性分析。
③ 改进设想、经验和体会。
一、图书管理信息系统的设计与实现 (难度系数:1)
1.问题描述
图书管理信息系统实现图书馆馆藏图书的信息管理与图书借阅。图书管理信息系统包括用户管理、读者管理、图书管理、图书流通功能。
2.整体要求
该系统应具有合理的界面设计,并易于操作;
编码风格良好;
该系统用控制台程序即可实现;
编程语言为C语言,编程环境为VC++ 6.0
3.设计要求
(1)登录系统时,要求用户输入用户名与密码,用户名与密码无误方可使用系统,最多可以尝试三次。用户分为:普通读者、图书管理员、系统管理员三种。普通读者只能使用“用户管理子系统”中“用户密码修改”功能和“图书管理子系统”中“图书信息查询”功能;图书管理员只能使用“图书管理子系统”和“图书流通管理子系统”;系统管理员只能使用“用户管理子系统”和“读者管理子系统”。
(2)图书管理信息系统包括:用户管理、读者管理、图书管理、图书流通管理这四个子系统。“图书管理信息系统”主菜单要求包含如下选项:
**********************************
1.用户管理
2.读者管理
3.图书管理
4.图书流通管理
5.退出系统


  要求在选择退出功能之前,可以反复选择系统的各项功能使用系统。

1)用户管理子系统:
应包括用户信息输入、用户信息修改、用户信息删除、用户信息显示、用户密码修改等功能。其中“普通读者”只能使用“用户密码修改”功能。
“用户管理”菜单要求包括如下选项:


  1. 用户信息输入
  2. 用户信息修改
  1. 用户信息删除
  2. 用户信息显示
  3. 用户密码修改
  4. 返回主菜单

“用户管理子系统”要求用文件与链表实现。
2)读者管理子系统:
应包括读者信息输入、读者信息修改、读者信息删除、读者信息按名查询等功能。
“读者管理”菜单要求包括如下选项:


      1. 读者信息输入
      2. 读者信息修改
      3. 读者信息删除
      4. 读者信息查询
      5. 读者信息显示(按读者姓氏排序)
      6. 返回主菜单
   *******************
 “读者管理子系统”要求用文件与链表实现。

3)图书管理子系统:
至少应包括图书信息输入、图书信息修改、图书信息查询、汇总统计等功能。其它功能(如图书订阅、图书编目、新书通报等功能)可根据自身情况酌情实现。
“图书管理”菜单至少要求包括如下选项:


      1. 图书信息输入
      2. 图书信息修改
      3. 图书信息查询
      4. 汇总统计
      5. 返回主菜单
   *******************

普通用户只能使用其中的图书信息查询和图书数目统计功能(功能3和功能4),当普通用选择其它功能时应告知不能使用。
如果在“图书管理”的菜单中选择了“3. 图书信息查询”,系统应提示如下子菜单:


   1. 按书号查询
   2. 按书名查询
   3. 按作者查询
   4. 按出版社查询
   5. 返回主菜单
  *******************

“图书管理子系统”要求用文件和顺序表实现。
4)图书流通管理子系统:
至少应包括借书处理和还书处理功能。其它功能(如预约处理、逾期处理等功能)可根据自身情况酌情实现。普通用户只能使用预约处理功能。
“图书管流通理”菜单至少要求包括如下选项:


   1. 借书处理
   2. 还书处理
   3. 返回主菜单
  *******************

“图书流通管理子系统”要求用文件和顺序表实现。
(3)要求建立如下文件:
1)建立用户文件,包括用户的如下信息:
用户名(可用读者号)、用户密码、用户类型
用户类型可分为:管理员和普通用户。管理员可以使用系统的所有功能,普通用户只可以查询图书及借阅情况。
2)建立读者文件,包括读者的如下信息:
读者号、读者名、单位、联系方式、可借书数、已借书数
3)建立与图书有关的如下文件。
图书主文件,包括图书的如下信息:
记录号、书号、书名、作者、出版社、藏书量、借出数、指针1、指针2、
指针3
图书主文件可以按主关键字(书号)有序或无序。
书号(主关键字)索引表,必须按书号有序。该索引表包括如下信息:
书号、该书号对应记录在主文件中记录号
书名(次关键字)索引表,包括如下信息:
书名、链头指针、长度
作者(次关键字)索引表,包括如下信息:
作者、链头指针、长度
出版社(次关键字)索引表,包括如下信息:
出版社、链头指针、长度
图书主文件和三个次关键字索引表的样例分别如表1至表4所示。
表1 图书主文件
记录号 书号 书名 作者 出版社 藏书量 借出数 指针1 指针2 指针3
1 1021 数据库 杨艳 人民邮电 10 8 0 0 0
2 1014 数据结构 赵鹏 高等教育 9 7 0 0 0
3 1106 操作系统 金虎 人民邮电 8 6 0 0 1
4 1108 数据结构 高扬 清华大学 7 5 2 0 0
5 1203 程序设计 杨艳 高等教育 9 4 0 1 2
6 2105 数据库 金虎 清华大学 7 3 1 3 4
7 1012 数据结构 杨艳 人民邮电 8 2 4 5 3
8 0109 程序设计 赵鹏 清华大学 9 1 5 2 6
表2 书名次关键字索引表
书名 链头指针 长度
数据库 6 2
数据结构 7 3
操作系统 3 1
程序设计 8 2
表3 作者次关键字索引表
作者 链头指针 长度
杨艳 7 3
赵鹏 8 2
金虎 6 2
高扬 4 1
表4 出版社次关键字索引表
出版社 链头指针 长度
人民邮电 7 3
高等教育 5 2
清华大学 8 3
4)建立借还书文件,包括如下信息:
读者号、书号、借书日期、还书日期
4.设计思想
下面将给出一些核心算法的设计思想。
(1)“登录系统”算法的设计思想
打开“用户文件”,读入文件内容,建立相应的链表。请用户输入用户名及密码。若用户名或密码输入不正确,最多允许尝试三次。用户名与密码输入正确时,记住当前用户类型。
当该用户为图书管理员时,打开“图书主文件”及所有的“索引表文件”,分别将文件内容读入相应的一维数组中,打开“借还书文件”,建立相应的链表,打开“读者文件”,建立相应的链表;当该用户为系统管理员时,打开“读者文件”,读入文件内容,建立相应的链表;当该用户为普通读者时,打开图书主文件及所有的索引表文件,分别将文件内容读入相应的一维数组中,并关闭所有打开的文件。
普通读者只能选“用户管理”功能项中“用户密码修改”子功能和“图书管理”功能项中“图书信息查询”子功能;图书管理员只能选“图书管理”和“图书流通管理”功能项;系统管理员只能选“用户管理”和“读者管理”功能项。需要根据用户类型显示相应的菜单,请用户选择功能项。
当退出系统时,需将各个链表和数组中的内容写回相应的文件。
(2)“图书信息输入”算法的设计思想
在输入图书信息时建立图书主文件,在图书主文件中记录号从1开始。根据设计要求,在建立图书文件的同时,需要建立一个主关键字(书号)索引表。索引表按书号升序排列(用插入排序法),索引表可以先在内存中用一维数组实现,最后再将相应内容一并写入(外存)文件。
根据设计要求,图书文件除了主关键字(书号)索引表外,还需要建立书名、作者、出版社三个次关键字索引表。次关键字索引表可采用头插法建立,具体做法是:根据一个主文件的记录,将要建立索引的次关键字与对应的次关键字索引表中的次关键字(如书名、作者、出版社)进行比较,若有相等的,就将主文件中的相应指针修改为索引表中的当前链头指针,并修改相应索引表中的链头指针为当前主文件的记录指针(即记录号),同时将长度加1;若没有相等的,就将主文件中的相应指针置为0,并在相应次关键字索引表中增加与该次关键字相关的一条记录,该记录的链头指针置为当前主文件的记录号,而将长度置为1。
(3)“图书信息查询”算法的设计思想
按书号查询时,由于图书文件已按书号建立了索引表,该索引表是按书号有序的,因此,在该索引表中可采用二分查找算法。
按书名查询时,先顺序查找书名次关键字索引表,找到相应的书名,取到该书名链头指针后,再回到图书主文件中顺链依次找出所有具有该书名的书。
按作者和出版社查询时,与按书名查询方法类似。
(4)“借书处理”算法设计思想
图书管理员输入读者号、书号、借书日期。系统检查读者是否为合法读者,若不是,显示提示信息,并返回;若是,则进一步检查读者借书数量是否超出限额。若超出,给出提示信息,并返回;若未超出,检查书号是否合法,若书号非法,给出提示信息,并返回;否则,继续检查该号图书是否已全部借出,若是,给出提示信息,并返回,否则,将借书文件记录数加1,借书文件追加1条相关记录,读者借书数加1,图书借出数加1,并提示借书成功。
(5)“还书处理”算法设计思想
图书管理员输入读者号、书号、还书日期。系统根据读者文件检查读者是否为合法读者,若不是合法读者,显示提示信息,并返回。否则,在借还书文件中检查书号是否合法,若书号非法,给出提示信息,并返回。否则,在图书文件中再检查书号是否合法,若非法,给出提示信息,并返回。否则,在“读者文件”中将该读者的借书数减1,在“图书文件”中修改借出数,在“借还书文件”中填入还书日期。
5.评价标准
本设计是一个比较综合的练习,用到顺序表、链表、静态链表、文件、排序、查找、字符串操作等方面的知识。本课程的主要目的是培养学生的综合设计能力、编程与调试能力,以及团队合作能力。因此要求本项目必须是团队合作完成的,程序必须能够正确运行,具体评分标准如表5所示。
表5 评分表
项目 所占分值 得分依据 得分
登录系统 10 使用“用户名”与“密码”登录系统,根据用户类
型打开相关文件,建立相应的链表或数组。
显示主菜单,并根据用户类型正确实现主菜单各个选项的跳转功能。
用户管理 15 子系统菜单(2分)
用户信息输入(2分)
用户信息修改(2分)
用户信息删除(2分)
用户信息显示(2分)
用户密码修改(2分)
完成质量与速度(3分)
读者管理 15 子系统菜单(2分)
读者信息输入(2分)
读者信息修改(2分)
读者信息删除(2分)
读者信息查询(2分)
读者信息显示(2分)
完成质量与速度(3分)
图书管理 20 子系统菜单(2分)
图书信息输入(2分)
图书信息修改(2分)
图书信息查询功能共9分,其中:
查询子菜单(1分)
按书号查询(2分)
按书名查询(2分)
按作者查询(2分)
按出版社查询(2分)
汇总统计(2分)
完成质量与速度(3分)
图书流通管理 10 子系统菜单(2分)
借书处理(3分)
还书处理(3分)
完成质量与速度(2分)
总体表现 10 根据完成附加功能情况、系统总体运行情况、完成的质量(包括算法的正确性、算法的复杂性、容错性、用户友好等因素)、团队合作情况等酌情加分。
旷课1次扣3分,缺勤1次扣1分。
报告 20
总分 100

二、银行卡管理系统(难度系数0.9)

  1. 需求分析
    随着社会经济的发展,信息化程度的不断深入,银行的传统业务己愈来愈不能满足银行客户的需要。
    现今,人们的金融意识、科技意识己经有了很大的提高,在紧张忙碌的生活中,己越来越来不习惯每月奔忙于各银行营业柜台之问去排队缴各种各样的费用了;同时,各种经营单位如电信、移动、供电、煤气、自来水、证券等等一是为了提高服务质量、方便客户,二是为了减轻自己日趋繁重的工作量,纷纷委托银行为其开展代收代付业务:同时,随着我国加入世贸组织的日益临近,我国的银行业将面临更加激烈的同业竞争,如何提供更多的金融产品和更优质的服务,如何吸引更多的客户,如何利用计算机技术加强银行帐户信息管理、进行银行业务再造,提高银行的工作效率和业务竟争能力是摆在各家银行面前的一个迫切需要解诀的问题。
  2. 问题描述
    近几年来,各商业银行加快了与社会各业的合作,利用自身的网点优势和业务特点,为其提供各种高效、快捷的代收代付业务,也就是中间代理业务,目前以与广大人民群众生活密切相关的各项缴费业务如水电费、电话费、手机费等代收业务为主,这些业务开展方式多种多样,但一般都离不开计算机的高效管理支持。
    随着代理业务不断发展,业务品种越来越多,各项业务做法互有差异,这就对银行的电子化水平和相应的管理水平提出了更高的要求。如何利用电子化的手段构建一个高效统一的、通用灵活的系统来管理各种各样的业务,是每个商业银行所要研究的课题。支持决策系统的,需要在数据库的基础上,进行联机分析处理,每次处理的数据量大,响应时间长。特别是银行每天要处理大量的存取款事件,做好存取款是银行工作重要的环节,然而要有效处理必须要有良好的程序和数据管理系统来建立一个良好的软件系统来实现快速、有效、准确、安全的处理银行事物。
  3. 基本要求
    (1)开户:创建一个新的账户,接受用户输入的身份证号,以及账户密码,判断用户输入的身份证号是否唯一且账户密码是否符合要求,如验证成功则为该用户生成一个唯一的帐号。
    (2)存款:在用户输入正确的帐号和密码的情况下,接受用户输入的存款金额,并对该帐号的存款信息进行更新。
    (3)取款:在用户输入正确的帐号和密码的情况下,接受用户输入的取款金额。取款金额不应该大于当前帐号存款金额,当取款金额不大于当前帐号存款金额时,执行取款操作,并对该帐户的存款信息进行更新。
    (4)挂失:在用户输入正确的帐号和密码的情况下,接受用户挂失操作。当帐号挂失后,与该帐号相关的操作都将被禁止。
    (5)销户:在用户输入正确的帐号和密码的情况下,接受用户销户。当用户销户后,该帐号将被永久删除。
    (6)转帐:在用户输入正确的帐号和密码的情况下,接受用户转账操作,转帐金额不应该大于当前帐号存款金额,当转帐金额不大于当前帐号存款金额时,执行转帐操作,并对该帐户的存款信息及转帐的接受账户的存款信息进行更新。
    (7)修改账户密码:在用户输入正确的帐号和密码的情况下,接受用户修改密码操作,用户输入的原密码,若用户输入的密码与原密码匹配,则接受用户输入的新密码,若用户两个输入的密码相同,则修改账户密码,并对数据文件进行更新操作。
    (8)查看余额:在用户输入正确的帐号和密码的情况下,接受用户查看余额操作,该模块只涉及数据查询,并不涉及数据文件更新操作。
    (9)查看用户交易历史:在用户输入正确的帐号和密码的情况下,接受用户查看用户交易历史操作,系统将显示当前账户的最近的存、取款操作记录,该模块只涉及数据查询,并不涉及数据文件更新操作。
  4. 数据结构
    完成本程序需要两个结构体来存储相应的信息,并且所以信息最终保存在文件中。
    银行卡基本信息结构:
    卡号:16位数字构成的字符串,前12位表示开户行、城市、网点等信息,后4位代表序号。
    姓名:持卡人姓名,长度为13的字符串。
    密码:字符+数字,不得少于6位。
    余额:doube类型。
    标记:short类型,0 表示正常,1 表示注销,2 表示冻结(注:如为1或2,该卡不能进行正常操作)。
    交易记录信息结构:
    卡号:与上面相同。
    交易日期:10位字符串,例如2017-03-01。
    交易金额:double类型。
    标记:short类型,0代表存款,1代表取款,2代表转账。
    对方卡号:与卡号说明相同,如标记为0或1,此项为空。
  5. 程序模块说明
    本系统采用结构化,自顶向下的设计思想实现。具体各个模块功能说明如下:
    第一个模块——主函数main()的功能是:根据菜单单的选项调用各函数,并完成相应的功能。
    第二个模块——oaccount()的功能是:用户开户信息将存入文件中。
    第三个模块——saving()的功能是:存款函数的实现。
    第四个模块——withdraw()的功能是:取款功能的实现。
    第五个模块——transfer()的功能是:转帐功能的实现。
    第六个模块——changemima()的功能是:修改密码的功能实现。
    第七个模块——serach()的功能是:查询余额的功能实现。
    第八个模块——guashi()的功能是:挂失(银行卡冻结)功能的实现。
    第九个模块——Tradejilu()的功能是:查询交易记录的功能实现。
    第十个模块——delete()的功能:删除银行卡信息的实现(要求用链表实现)。
    第十一个模块——welcome()的功能是:界面进入的功能实现。
    除主函数外,其他函数都通过welcome函数连接。
  6. 测试与分析
    系统运行参考界面
    欢迎界面:

管理登录操作主界面:

用户功能选择界面:

三、学生信息管理系统模拟 (难度系数0.8)

  1. 整体要求
    该系统应具有合理的界面设计,并易于操作;
    编码风格良好;
    该系统用控制台程序即可实现;
    编程语言为C语言,编程环境为VC++ 6.0。

  2. 存储结构设计
    设计学生结构体。

  3. 编程要求
    (1)结构体设计
    “学生”结构体包含“学号”、“姓名”、“性别”、“英语成绩”、“C语言成绩”。
    (2)存储结构要求
    学生信息要求保存到文件中。

  4. 菜单(界面)设计
    编程实现系统的整体菜单
    “登陆”菜单(选做,有加分)
    1----------用户登陆
    0----------退出系统
    主菜单样式如下:
    1----------学生录入
    2----------学生浏览
    3----------学生查询
    4----------学生删除
    5----------成绩统计
    0----------退出系统

  5. 功能和函数设计
    任务
    通过函数完成各个菜单模块的功能,要求合理设计主函数和各个子函数,合理设计各个函数之间的调用关系。
    编程要求
    1.主函数:显示主菜单。
    2.如果设计并编写登陆菜单,要求合理设计登陆界面,要求用户输入用户名和密码,如果全都正确则进入主菜单,如果有一项不对,系统再提供两次机会输入,三次都错退出系统。(此部分有加分)
    3.编写函数完成“学生录入”功能,要求能将用户由键盘输入的若干学生信息追加到student.txt或student.dat中,存储结构可以使用数组,也可以使用链表。
    4.编写函数完成“学生浏览”功能,要求能将student.txt或student.dat文件中的全部学生信息显示出来,存储结构可以使用数组,也可以使用链表。
    5.编写函数完成“学生查询”功能,要求能按照学号或姓名对学生进行查询。
    6.编写函数完成“学生删除”功能,要求按照学号或姓名将某个学生删除,并将删除后的结果写回到文件中,此功能要求存储结构必须使用链表。
    7.设计并编写编写函数完成“成绩统计”功能,可以对“英语成绩”、“C语言成绩”进行单科浏览(降序排列),按某个学生统计总分和平均分,按英语和C语言两科成绩对学生进行排序。

user.h

#ifndef USER_H
#define USER_H
#include<string>
using namespace std;
class user
{
	public:
		user();
		~user();
		user(char *u,char *p,char *n,char *w,long t,int a,int h);
		void set(char *u,char *p,char *n,char *w,long t,int a,int h);
		void setvalue(char *u,char *p,char *n,char *w,long t,int a,int h);
		void delete_();
		void mdf_s();
		void show();
		void mdf_pw();
		char* getname();
		char* getpw();
		char* rname();
		char* getwp();
		long gettel();
		int geta();
		int geth();
        void query();
        bool operator<(user a);
        void sortshow();
	protected:
		char user_name[20];
		char password[10];
		char name[10];
		char workplace[20];
		long tel;
		int ableb,hadb;
};

#endif

user.cpp

#include "user.h"
#include<string.h>
#include<iostream>
#include<fstream>
#include<list>
bool scmp(char *a,char *b);
using namespace std;
user::user()  //
{
	memset(user_name,0,sizeof(user_name));
	memset(password,0,sizeof(password));
	memset(name,0,sizeof(name));
	memset(workplace,0,sizeof(workplace));
	tel=0;
	ableb=0;
	hadb=0;
}

user::user(char *u,char *p,char *n,char *w,long t,int a,int h) //
{
	memset(user_name,0,sizeof(user_name));
	memset(password,0,sizeof(password));
	memset(name,0,sizeof(name));
	memset(workplace,0,sizeof(workplace));
	for(int i=0;i<strlen(u);i++)
	user_name[i]=u[i];
	for(int i=0;i<strlen(p);i++)
	password[i]=p[i];
	for(int i=0;i<strlen(n);i++)
	name[i]=n[i];
	for(int i=0;i<strlen(w);i++)
	workplace[i]=w[i];
	tel=t;
	ableb=a;
	hadb=h;
}
void user::set(char *u,char *p,char *n,char *w,long t,int a,int h) //
{
	memset(user_name,0,sizeof(user_name));
	memset(password,0,sizeof(password));
	memset(name,0,sizeof(name));
	memset(workplace,0,sizeof(workplace));
	for(int i=0;i<strlen(u);i++)
	user_name[i]=u[i];
	for(int i=0;i<strlen(p);i++)
	password[i]=p[i];
	for(int i=0;i<strlen(n);i++)
	name[i]=n[i];
	for(int i=0;i<strlen(w);i++)
	workplace[i]=w[i];
	tel=t;
	ableb=a;
	hadb=h;
}
void user::delete_() //
{
	ifstream inf("user.txt",ios::in|ios::binary);
	inf.seekg(0,ios::end);
	int n=inf.tellg();
	n/=sizeof(user);
	inf.close();
	ifstream in("user.txt",ios::in|ios::binary);
	list<user> lt;
	ofstream out("user.txt",ios::out|ios::binary);
	while(n--)
	{
		user temp;
		in.read((char*)&temp,sizeof(user));
		if(scmp(this->getname(),temp.getname()) && scmp(this->getpw(),temp.getpw()))
		{
            cout<<"你的用户信息已从文件里删除,改系统自动退出";
		}
		else lt.push_back(temp);
	}
	in.close();
	while(!lt.empty())
	{
		user temp(lt.front().getname(),lt.front().getpw(),lt.front().rname(),lt.front().getwp(),lt.front().gettel(),lt.front().geta(),lt.front().geth());
		out.write((char*)&temp,sizeof(user));
		lt.pop_front();
	}
	out.close();
}

void user::setvalue(char *u,char *p,char *n,char *w,long t,int a,int h) //
{
	ifstream inf("user.txt",ios::in|ios::binary);
	inf.seekg(0,ios::end);
	int ncnt=inf.tellg();
	ncnt/=sizeof(user);
	inf.close();
	ifstream in("user.txt",ios::in|ios::binary);
	list<user> lt;
	//cout<<ncnt<<endl;
	while(ncnt--)
	{
		user temp;
		in.read((char*)&temp,sizeof(user));
		if(scmp(this->getname(),temp.getname()) && scmp(this->getpw(),temp.getpw()))
		{
		    memset(user_name,0,sizeof(user_name));
            memset(password,0,sizeof(password));
	        memset(name,0,sizeof(name));
            memset(workplace,0,sizeof(workplace));
            for(int i=0;i<strlen(u);i++)
	        user_name[i]=u[i];
         	for(int i=0;i<strlen(p);i++)
        	password[i]=p[i];
        	for(int i=0;i<strlen(n);i++)
        	name[i]=n[i];
         	for(int i=0;i<strlen(w);i++)
	        workplace[i]=w[i];
        	tel=t;
	        ableb=a;
	        hadb=h;
	        temp.set(u,p,n,w,t,a,h);
		}
		lt.push_back(temp);
	}
	in.close();
	ofstream out("user.txt",ios::out|ios::binary);
	while(!lt.empty())
	{
	    user temp(lt.front().getname(),lt.front().getpw(),lt.front().rname(),lt.front().getwp(),lt.front().gettel(),lt.front().geta(),lt.front().geth());
		out.write((char*)&temp,sizeof(user));
		lt.pop_front();
	}
	out.close();
}

void user::mdf_pw() //
{
	cout<<"请输入新密码\n";
	char p[10],u[20],n[10],w[20];
	cin>>p;
	strcpy(u,this->getname());
	strcpy(n,this->rname());
	strcpy(w,this->getwp());
	setvalue(u,p,n,w,gettel(),geta(),geth());
    cout<<"你的密码修改完毕\n";
}

void user::show() //
{
    cout<<"读者"<<name<<endl;
	cout<<"您的用户名为\n"<<user_name<<endl;
	cout<<"您的密码为\n"<<password<<endl;
	cout<<"您的单位\n"<<workplace<<endl;
	cout<<"电话号码\n"<<tel<<endl;
	cout<<"可借书数\n"<<ableb<<endl;
	cout<<"已借书数\n"<<hadb<<endl;
}

bool user::operator<(user a) //
{
    return strcmp(this->rname(),a.rname());
}

void user::sortshow() //
{
    ifstream inf("user.txt",ios::in|ios::binary);
	inf.seekg(0,ios::end);
	int ncnt=inf.tellg();
	ncnt/=sizeof(user);
	inf.close();
	ifstream in("user.txt",ios::in|ios::binary);
	list<user> lt;
	int cnt=ncnt;
	while(ncnt--)
	{
		user temp;
		in.read((char*)&temp,sizeof(user));
		lt.push_back(temp);
	}
	cout<<"所有的读者信息如下\n";
	lt.sort();
	while(cnt--)
    {
        lt.front().show();
        lt.pop_front();
    }
}
char* user::getname()
{
    char *u=new char[strlen(user_name)];
    strcpy(u,user_name);
	return u;
}

char *user::getpw()
{
	char *u=new char[strlen(password)];
    strcpy(u,password);
	return u;
}

char* user::rname()
{
    char *u=new char[strlen(name)];
    strcpy(u,name);
	return u;
}

char* user::getwp()
{
    char *u=new char[strlen(workplace)];
    strcpy(u,workplace);
	return u;
}

long user::gettel()
{
    return this->tel;
}

int user::geta()
{
    return ableb;
}

int user::geth()
{
    return hadb;
}
void user::query()
{
    cout<<"请输入你要查询的读者用户名和密码\n";
    int flag=0;
    char u[20],p[10];
    cin>>u>>p;
    ifstream inf("user.txt",ios::in|ios::binary);
	inf.seekg(0,ios::end);
	int ncnt=inf.tellg();
	ncnt/=sizeof(user);
	inf.close();
	ifstream in("user.txt",ios::in|ios::binary);
	list<user> lt;
	while(ncnt--)
	{
		user temp;
		in.read((char*)&temp,sizeof(user));
		if(scmp(u,temp.getname()) && scmp(p,temp.getpw()))
		{
		    flag=1;
            cout<<"请输入你要对该读者进行的操作1 删除 2 修改\n";
            int tint;
            cin>>tint;
            if(tint==1)
            {
                cout<<"该读者信息已被删除\n";
                continue;
            }
            else if(tint==2)
            {
                char tu[20],tp[10],tn[10],tw[20];
                memset(tu,0,sizeof(tu));
                memset(tp,0,sizeof(tp));
                memset(tn,0,sizeof(tn));
                memset(tw,0,sizeof(tw));
                long tt;
                int ta,th;
                int anx=0;
                cout<<"是否修改用户名 1 是 0 否\n";
                cin>>anx;
                if(anx==1)
                {
                    cout<<"请输入\n";
                    cin>>tu;
                    memset(user_name,0,sizeof(user_name));
                    strcpy(user_name,tu);
                }
                anx=0;
                cout<<"是否修改密码 1 是 0 否\n";
                cin>>anx;
                if(anx==1)
                {
                    cout<<"请输入\n";
                    cin>>tp;
                    memset(password,0,sizeof(password));
                    strcpy(password,tp);
                }
                anx=0;
                cout<<"是否修改姓名 1 是 0 否\n";
                cin>>anx;
                if(anx==1)
                {
                    cout<<"请输入\n";
                    cin>>tn;
                    memset(name,0,sizeof(name));
                    strcpy(name,tn);
                }
                anx=0;
                cout<<"是否修改单位 1 是 0 否\n";
                cin>>anx;
                if(anx==1)
                {
                    cout<<"请输入\n";
                    cin>>tw;
                    memset(workplace,0,sizeof(workplace));
                    strcpy(workplace,tw);
                }
                anx=0;
                cout<<"是否修改电话号码 1 是 0 否\n";
                cin>>anx;
                if(anx==1)
                {
                    cout<<"请输入\n";
                    cin>>tt;
                    tel=tt;
                }
                anx=0;
                cout<<"是否修改可借书数 1 是 0 否\n";
                cin>>anx;
                if(anx==1)
                {
                    cout<<"请输入\n";
                    cin>>ta;
                    ableb=ta;
                }
                anx=0;
                cout<<"是否修改已借书数 1 是 0 否\n";
                cin>>anx;
                if(anx==1)
                {
                    cout<<"请输入\n";
                    cin>>th;
                    hadb=th;
                }
                temp.set(this->getname(),this->getpw(),this->rname(),this->getwp(),this->gettel(),this->geta(),this->geth());
                lt.push_back(temp);
            }
		}
		else lt.push_back(temp);
	}
	in.close();
	if(flag==0)
    {
        cout<<"该读者信息不存在\n";
        return;
    }
    ofstream out("user.txt",ios::out|ios::binary);
	while(!lt.empty())
	{
	    user temp(lt.front().getname(),lt.front().getpw(),lt.front().rname(),lt.front().getwp(),lt.front().gettel(),lt.front().geta(),lt.front().geth());
		out.write((char*)&temp,sizeof(user));
		lt.pop_front();
	}
	out.close();
}

void user::mdf_s()
{
    char tu[20],tp[10],tn[10],tw[20];
    memset(tu,0,sizeof(tu));
    memset(tp,0,sizeof(tp));
    memset(tn,0,sizeof(tn));
    memset(tw,0,sizeof(tw));
    long tt;
    int ta,th;
    int anx=0;
    cout<<"是否修改用户名 1 是 0 否\n";
    cin>>anx;
    if(anx==1)
    {
        cout<<"请输入\n";
        cin>>tu;
    }
    else strcpy(tu,user_name);
    anx=0;
    cout<<"是否修改密码 1 是 0 否\n";
    cin>>anx;
    if(anx==1)
    {
        cout<<"请输入\n";
        cin>>tp;
    }
    else strcpy(tp,password);
    anx=0;
    cout<<"是否修改姓名 1 是 0 否\n";
    cin>>anx;
    if(anx==1)
    {
        cout<<"请输入\n";
        cin>>tn;
    }
    else strcpy(tn,name);
    anx=0;
    cout<<"是否修改单位 1 是 0 否\n";
    cin>>anx;
    if(anx==1)
    {
        cout<<"请输入\n";
        cin>>tw;
    }
    else strcpy(tw,workplace);
    anx=0;
    cout<<"是否修改电话号码 1 是 0 否\n";
    cin>>anx;
    if(anx==1)
    {
        cout<<"请输入\n";
        cin>>tt;
    }
    else tt=tel;
    anx=0;
    cout<<"是否修改可借书数 1 是 0 否\n";
    cin>>anx;
    if(anx==1)
    {
        cout<<"请输入\n";
        cin>>ta;
    }
    else ta=ableb;
    anx=0;
    cout<<"是否修改已借书数 1 是 0 否\n";
    cin>>anx;
    if(anx==1)
    {
        cout<<"请输入\n";
        cin>>th;
    }
    else th=hadb;
    setvalue(tu,tp,tn,tw,tt,ta,th);
}

user::~user()
{

}

book.h

#ifndef BOOK_H
#define BOOK_H


class book
{
    public:
        void cinbook();
        void mof_book();
        book();
        book(const book& other);
        void show();
    public:
        int rec;
        int book_num;
        char book_name[20];
        char aut[10];
        char ph[50];
        int sum;
        int bor;
        int p1,p2,p3;
};

#endif // BOOK_H

book.cpp

#include "book.h"
#include<iostream>
#include<fstream>
#include<vector>
#include<string.h>
bool scmp(char *a,char *b);
using namespace std;
struct bname
{
    char b_name[20];
    int len;
    int v[10];
    bname()
    {
        len=1;
        for(int i=0;i<10;i++)
        v[i]=0;
        memset(b_name,0,sizeof(b_name));
    }
};
struct baut
{
    char b_aut[10];
    int len;
    int v[10];
    baut()
    {
        len=1;
        for(int i=0;i<10;i++)
        v[i]=0;
        memset(b_aut,0,sizeof(b_aut));
    }
};
struct bph
{
    char b_ph[20];
    int len;
    int v[10];
    bph()
    {
        len=1;
        for(int i=0;i<10;i++)
        v[i]=0;
        memset(b_ph,0,sizeof(b_ph));
    }
};
book::book()
{
    memset(book_name,0,sizeof(book_name));
    memset(aut,0,sizeof(aut));
    memset(ph,0,sizeof(ph));
    book_num=0;
    rec=0;
    p1=0;
    p2=0;
    p3=0;
    bor=0;
    sum=0;
}

book::book(const book& other)
{
    memset(book_name,0,sizeof(book_name));
    memset(aut,0,sizeof(aut));
    memset(ph,0,sizeof(ph));
    strcpy(book_name,other.book_name);
    strcpy(aut,other.aut);
    strcpy(ph,other.ph);
    rec=other.rec;
    this->book_num=other.book_num;
    this->sum=other.sum;
    bor=other.bor;
    p1=other.p1;
    p2=other.p2;
    p3=other.p3;
}

void book::cinbook()
{
    memset(book_name,0,sizeof(book_name));
    memset(aut,0,sizeof(aut));
    memset(ph,0,sizeof(ph));
    cout<<"请输入该书的记录号\n";
    cin>>rec;
    cout<<"请输入该书的书号\n";
    cin>>book_num;
    cout<<"请输入该书的书名\n";
    cin>>book_name;
    cout<<"请输入该书的作者\n";
    cin>>aut;
    cout<<"请输入该书的出版社\n";
    cin>>ph;
    cout<<"请输入该书的藏书量\n";
    cin>>sum;
    // bname
    {
        int flag=0;
        ifstream in("name.txt",ios::in|ios::binary);
        in.seekg(0,ios::end);
        int n=in.tellg();
        if(n<0) n=0;
        n/=sizeof(bname);
        bname btemp[n];
        in.close();
        ifstream inf("name.txt",ios::in|ios::binary);
        for(int i=0;i<n;i++)
        {
            inf.read((char*)&btemp[i],sizeof(bname));
            if(scmp(btemp[i].b_name,book_name))
            {
                flag=1;
                p1=btemp[i].v[btemp[i].len-1];
                btemp[i].len++;
                btemp[i].v[btemp[i].len-1]=rec;
            }
        }
        inf.close();
        ofstream out("name.txt",ios::out|ios::binary);
        for(int i=0;i<n;i++)
        {
            out.write((char*)&btemp[i],sizeof(bname));
        }
        if(flag==0)
        {
            bname btem;
            btem.v[0]=rec;
            strcpy(btem.b_name,book_name);
            out.write((char*)&btem,sizeof(bname));
        }
        out.close();
    }
    {
     // baut
        int flag=0;
        ifstream in("aut.txt",ios::in|ios::binary);
        in.seekg(0,ios::end);
        int n=in.tellg();
        if(n<0) n=0;
        n/=sizeof(baut);
        baut btemp[n];
        in.close();
        ifstream inf("aut.txt",ios::in|ios::binary);
        for(int i=0;i<n;i++)
        {
            inf.read((char*)&btemp[i],sizeof(baut));
            if(scmp(btemp[i].b_aut,aut))
            {
                flag=1;
                p2=btemp[i].v[btemp[i].len-1];
                btemp[i].len++;
                btemp[i].v[btemp[i].len-1]=rec;
            }
        }
        inf.close();
        ofstream out("aut.txt",ios::out|ios::binary);
        for(int i=0;i<n;i++)
        {
            out.write((char*)&btemp[i],sizeof(baut));
        }
        if(flag==0)
        {
            baut btem;
            btem.v[btem.len-1]=rec;
            strcpy(btem.b_aut,aut);
            out.write((char*)&btem,sizeof(baut));
        }
        out.close();
    }
    {
    // bph
        int flag=0;
        ifstream in("ph.txt",ios::in|ios::binary);
        in.seekg(0,ios::end);
        int n=in.tellg();
        if(n<0) n=0;
        n/=sizeof(bph);
        bph btemp[n];
        in.close();
        ifstream inf("ph.txt",ios::in|ios::binary);
        for(int i=0;i<n;i++)
        {
            inf.read((char*)&btemp[i],sizeof(bph));
            if(scmp(btemp[i].b_ph,ph))
            {
                flag=1;
                p3=btemp[i].v[btemp[i].len-1];
                btemp[i].len++;
                btemp[i].v[btemp[i].len-1]=rec;
            }
        }
        inf.close();
        ofstream out("ph.txt",ios::out|ios::binary);
        for(int i=0;i<n;i++)
        {
            out.write((char*)&btemp[i],sizeof(bph));
        }
        if(flag==0)
        {
            bph btem;
            btem.v[btem.len-1]=rec;
            strcpy(btem.b_ph,ph);
            out.write((char*)&btem,sizeof(bph));
        }
        out.close();
    }
    cout<<"正在将该书注册到文件中\n";
    ofstream out("book.txt",ios::out|ios::binary|ios::app);
    book temp(*this);
    out.write((char*)&temp,sizeof(book));
    out.close();
    cout<<"注册成功\n";
}

void book::mof_book()
{
    int r;
    cout<<"请输入你想修改书的记录号\n";
    cin>>r;
    ifstream inf("book.txt",ios::in|ios::binary);
	inf.seekg(0,ios::end);
	int ncnt=inf.tellg();
	ncnt/=sizeof(book);
	inf.close();
	ifstream in("book.txt",ios::in|ios::binary);
	vector<book>vt;
	while(ncnt--)
    {
        book temp;
        in.read((char*)&temp,sizeof(book));
        if(temp.rec==r)
        {
            cout<<"接下来请按照指示修改\n";
            int cnt=0;
            cout<<"是否修改该书的书号 0 否 1是\n";
            cin>>cnt;
            if(cnt==1)cin>>temp.book_num;
            cnt=0;
            cout<<"是否修改该书的藏书量 0 否 1是\n";
            cin>>cnt;
            if(cnt==1)cin>>temp.sum;
            vt.push_back(temp);
        }
        else vt.push_back(temp);
    }
    in.close();
    ofstream out("book.txt",ios::out|ios::binary);
    for(int i=0;i<vt.size();i++)
    {
        book temp(vt[i]);
        out.write((char*)&temp,sizeof(book));
    }
    vt.clear();
    out.close();
}

void book::show()
{
    cout<<"该书的信息如下\n";
    cout<<"记录号  "<<rec;
    cout<<" 书号  "<<book_num;
    cout<<" 书名  "<<book_name;
    cout<<" 作者  "<<aut<<endl;
    cout<<"出版社  "<<ph;
    cout<<" 总书量  "<<sum;
    cout<<" 已借出量  "<<bor<<endl;
}

main.cpp

#include <iostream>
#include <fstream>
#include <cstring>
#include "user.h"
#include <termios.h>
#include <unistd.h>
#include "book.h"
#include <vector>
#include <time.h>
using namespace std;
void search_rec(int x);
void BC();  //图书流通系统
struct BR
{
    int rthis;
    int byear,bmouth,bday,bhour,bmin,bsec;
    int ryear,rmouth,rday,rhour,rmin,rsec;
    BR()
    {
        rthis=0;
        byear=0,bmouth=0,bday=0,bhour=0,bmin=0,bsec=0;
        ryear=0,rmouth=0,rday=0,rhour=0,rmin=0,rsec=0;
    }
    BR(const BR&b)
    {
        rthis=b.rthis;
        byear=b.byear,bmouth=b.bmouth,bday=b.bday,bhour=b.bhour,bmin=b.bmin,bsec=b.bsec;
        ryear=b.ryear,rmouth=b.rmouth,rday=b.rday,rhour=b.rhour,rmin=b.rmin,rsec=b.rsec;
    }
    void set(BR b)
    {
        rthis=b.rthis;
        byear=b.byear,bmouth=b.bmouth,bday=b.bday,bhour=b.bhour,bmin=b.bmin,bsec=b.bsec;
        ryear=b.ryear,rmouth=b.rmouth,rday=b.rday,rhour=b.rhour,rmin=b.rmin,rsec=b.rsec;
    }
    int sum_BR()
    {
        ifstream inf("BR.txt",ios::in|ios::binary);
        inf.seekg(0,ios::end);
        int n=inf.tellg();
        n/=sizeof(BR);
        return n;
    }
    void show()
    {
        cout<<rthis;
        cout<<rday<<" \n";
    }
};
struct ubr
{
    char un[10];
    int len;
    BR v[10];
    ubr()
    {
        memset(un,0,sizeof(un));
        len=0;
    }
    int sum_ubr()
    {
        ifstream inf("UBR.txt",ios::in|ios::binary);
        inf.seekg(0,ios::end);
        int n=inf.tellg();
        n/=sizeof(ubr);
        return n;
    }
};
struct bname
{
    char b_name[20];
    int len;
    int v[10];
    bname()
    {
        len=1;
        for(int i=0;i<10;i++)
        v[i]=0;
        memset(b_name,0,sizeof(b_name));
    }
};
struct baut
{
    char b_aut[10];
    int len;
    int v[10];
    baut()
    {
        len=1;
        for(int i=0;i<10;i++)
        v[i]=0;
        memset(b_aut,0,sizeof(b_aut));
    }
};
struct bph
{
    char b_ph[20];
    int len;
    int v[10];
    bph()
    {
        len=1;
        for(int i=0;i<10;i++)
        v[i]=0;
        memset(b_ph,0,sizeof(b_ph));
    }
};
user now;
void B_a(); //图书管理系统
int sum_book();
void search_book();
int getch()
{
    struct termios oldt,newt;
    int ch;
    tcgetattr( STDIN_FILENO, &oldt );//获得标准输入的终端参数,将获得的信息保存在oldt变量中
    newt = oldt;
    newt.c_lflag &= ~( ICANON | ECHO );
    tcsetattr( STDIN_FILENO, TCSANOW, &newt );
    ch = getchar();
    tcsetattr( STDIN_FILENO, TCSANOW, &oldt );
    return ch;
}
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
bool pwcnt(char *u,char *p); // 判断用户名,密码函数
void HZ(); //汇总
void N_r();  //读者界面
void S_a(); // 系统管理员界面
void regs(); //注册函数
bool scmp(char *a,char *b); // strcmp 函数
int main(int argc, char** argv)
{
    cout<<"按 1 表示登录系统\n";
	cout<<"按 2 表示注册用户\n";
	int x;
	cin>>x;
	if(x==2)
	{
		regs();
		cout<<"你已经成功注册了一个账号,请登录\n";
	}
	int t=3;
    if(t<=0)
    {
	    cout<<"您已输错3次用户名密码,该系统将自动退出\n";
	    return 0;
	}
	while(t)
    {
    	char u[20],p[10];
        cout<<"请输入您的用户名\n";
        memset(u,0,sizeof(u));
	    cin>>u;
	    getchar();
	    memset(p,0,sizeof(p));
	    cout<<"请输入您的密码\n";
	    {
            for(int i=0;i<6;i++)
            {
                p[i]=getch();
                cout<<'*';
            }
			cout<<endl;
	    }
		if(pwcnt(u,p))
	    {
		    cout<<"你以成功进入系统\n";
			cout<<"请选择你的身份类型\n";
		    cout<<"1.普通读者\n";
		    cout<<"2.图书管理员\n";
		    cout<<"3.系统管理员\n";
		    cout<<"4.退出主菜单\n";
		    int n;
		    cin>>n;
		    if(n==1)
		    {
		        N_r();
		        t=3;
			}
		    if(n==2)
		    {
		        B_a();
		        t=3;
		    }
		    if(n==3)
		    {
		        S_a();
		        t=3;
		    }
		    if(n==4)
            {
                cout<<"您已退出主菜单\n";
                t=3;
                break;
            }
	    }
	    else
	    {
		    cout<<"您的用户名密码错误,请重新输入\n";
		    t--;
		}
	}
	return 0;
}
bool scmp(char *a,char *b)
{
	for(unsigned int i=0;i<min(strlen(a),strlen(b));i++)
	if(a[i]!=b[i]) return false;
	return true;
}
bool pwcnt(char *u,char *p) //
{
	ifstream in("user.txt",ios::in|ios::binary);
	in.seekg(0,ios::end);
	int n=in.tellg();
	n/=sizeof(user);
	in.close();
	ifstream inf("user.txt",ios::in|ios::binary);
	while(n--)
	{
		user temp;
		inf.read((char*)&temp,sizeof(user));
	    if(scmp(u,temp.getname()) && scmp(p,temp.getpw()))
		{
		    now.set(temp.getname(),temp.getpw(),temp.rname(),temp.getwp(),temp.gettel(),temp.geta(),temp.geth());
			inf.close();
			return true;
		}
	}
	inf.close();
	return false;
}
void regs()  //
{
	char u[20],p[10],n[10],w[20];
	long t;
	memset(n,0,sizeof(n));
	memset(p,0,sizeof(p));
	memset(u,0,sizeof(u));
	memset(w,0,sizeof(w));
	cout<<"请输入你想创建的用户名\n";
	cin>>u;
	cout<<"请输入你的密码\n";
	cin>>p;
	cout<<"请输入您的姓名\n";
	cin>>n;
	cout<<"请输入您的单位\n";
	cin>>w;
	cout<<"请输入您的电话号码\n";
	cin>>t;
    user temp(u,p,n,w,t,10,0);
	ofstream out("user.txt",ios::out|ios::binary|ios::app);
	out.write((char*)&temp,sizeof(user));
	out.close();
	ofstream outb("UBR.txt",ios::out|ios::binary|ios::app);
	ubr ti;
	strcpy(ti.un,u);
	outb.write((char*)&ti,sizeof(ubr));
	outb.close();
}
void N_r()
{
    cout<<"请输入你要执行的操作\n";
    int x;
    while(true)
    {
        cout<<"1.密码修改\n";
        cout<<"2.图书查询\n";
        cout<<"3.借还书系统\n";
        cout<<"4.退出系统\n";
        cin>>x;
        if(x==1)
        {
            now.mdf_pw();
        }
        if(x==2)
        {
            search_book();
        }
        if(x==3)
        {
            BC();
        }
        if(x==4)
        {
            cout<<"您已成功退出系统\n";
            return;
        }
    }
}
void S_a()
{
    int x;
    while(true)
    {
        cout<<"1.用户管理系统\n";
        cout<<"2.读者管理系统\n";
        cout<<"3.返回主系统\n";
        cin>>x;
        if(x==1)
        {
            while(true)
            {
                int y;
                cout<<"1.用户信息修改\n";
                cout<<"2.用户信息删除\n";
                cout<<"3.用户信息显示\n";
                cout<<"4.用户密码修改\n";
                cout<<"5.退出\n";
                cin>>y;
                if(y==1)
                {
                    now.mdf_s();
                }
                if(y==2)
                {
                    now.delete_();
                    return;
                }
                if(y==3)
                {
                    now.show();
                }
                if(y==4)
                {
                    now.mdf_pw();
                }
                if(y==5)
                {
                    cout<<"您已退出用户管理系统\n";
                    break;
                }
            }
        }
        if(x==2)
        {
            while(true)
            {
                int y;
                cout<<"1.读者信息修改\n";
                cout<<"2.读者信息删除\n";
                cout<<"3.读者信息查询\n";
                cout<<"4.读者信息显示\n";
                cout<<"5.退出\n";
                cin>>y;
                if(y==1)
                {
                    now.mdf_s();
                }
                if(y==2)
                {
                    now.delete_();
                    return;
                }
                if(y==3)
                {
                    now.query();
                }
                if(y==4)
                {
                    now.sortshow();
                }
                if(y==5)
                {
                    cout<<"您已退出读者管理系统\n";
                    break;
                }
            }
        }
        if(x==3) break;
    }
}

void B_a()
{
    int bcnt;
    while(true)
    {
        book temp;
        cout<<"你已成功进入图书管理员系统\n";
        cout<<"1. 图书信息输入\n";
        cout<<"2. 图书信息修改\n";
        cout<<"3. 图书信息查询\n";
        cout<<"4. 汇总统计\n";
        cout<<"5. 退出\n";
        cin>>bcnt;
        if(bcnt==1)
        {
            temp.cinbook();
        }
        if(bcnt==2)
        {
            temp.mof_book();
        }
        if(bcnt==3)
        {
            search_book();
        }
        if(bcnt==4)
        {
            HZ();
        }
        if(bcnt==5) break;
    }
}
void search_book()
{
    int nt;
    while(true)
    {
        cout<<"请输入你的查询方式\n";
        cout<<"1,按书号查询\n";
        cout<<"2,按书名查询\n";
        cout<<"3,按作者查询\n";
        cout<<"4,按出版社查询\n";
        cout<<"5.退出\n";
        cin>>nt;
        if(nt==1)
        {
            int ncnt=sum_book();
            int num;
            cout<<"请输入书号\n";
            cin>>num;
            ifstream in("book.txt",ios::binary|ios::in);
            while(ncnt--)
            {
                book temp;
                in.read((char*)&temp,sizeof(book));
                if(temp.book_num==num)
                {
                    temp.show();
                }
            }
            in.close();
        }
        if(nt==2)
        {
            ifstream inf("name.txt",ios::in|ios::binary);
            inf.seekg(0,ios::end);
            int ncnt=inf.tellg();
            if(ncnt<0) ncnt=0;
            ncnt/=sizeof(bname);
            inf.close();
            ifstream in("name.txt",ios::in|ios::binary);
            char Tname[20];
            memset(Tname,0,sizeof(Tname));
            cout<<"请输入书名\n";
            cin>>Tname;
            int flag=0;
            while(ncnt--)
            {
                bname Ttemp;
                in.read((char*)&Ttemp,sizeof(bname));
                if(scmp(Tname,Ttemp.b_name))
                {
                    flag=1;
                    for(int i=0;i<10;i++)
                    if(Ttemp.v[i]!=0) search_rec(Ttemp.v[i]);
                    cout<<endl;
                }
            }
            if(flag==0) cout<<"无名为"<<Tname<<"的书\n";
            in.close();
        }
        if(nt==3)
        {
            ifstream inf("aut.txt",ios::in|ios::binary);
            inf.seekg(0,ios::end);
            int ncnt=inf.tellg();
            if(ncnt<0) ncnt=0;
            ncnt/=sizeof(baut);
            inf.close();
            ifstream in("aut.txt",ios::in|ios::binary);
            char Tname[10];
            memset(Tname,0,sizeof(Tname));
            cout<<"请输入作者\n";
            cin>>Tname;
            int flag=0;
            while(ncnt--)
            {
                baut Ttemp;
                in.read((char*)&Ttemp,sizeof(baut));
                if(scmp(Tname,Ttemp.b_aut))
                {
                    flag=1;
                    for(int i=0;i<10;i++)
                    if(Ttemp.v[i]!=0) search_rec(Ttemp.v[i]);
                    cout<<endl;
                }
            }
            if(flag==0) cout<<"无作者为"<<Tname<<"的书\n";
            in.close();
        }
        if(nt==4)
        {
            ifstream inf("ph.txt",ios::in|ios::binary);
            inf.seekg(0,ios::end);
            int ncnt=inf.tellg();
            if(ncnt<0) ncnt=0;
            ncnt/=sizeof(bph);
            inf.close();
            ifstream in("ph.txt",ios::in|ios::binary);
            char Tname[20];
            memset(Tname,0,sizeof(Tname));
            cout<<"请输入出版社名称\n";
            cin>>Tname;
            int flag=0;
            while(ncnt--)
            {
                bph Ttemp;
                in.read((char*)&Ttemp,sizeof(bph));
                if(scmp(Tname,Ttemp.b_ph))
                {
                    flag=1;
                    for(int i=0;i<10;i++)
                    if(Ttemp.v[i]!=0) search_rec(Ttemp.v[i]);
                    cout<<endl;
                }
            }
            if(flag==0) cout<<"无出版社为"<<Tname<<"的书\n";
            in.close();
        }
        if(nt==5) break;
    }
}

void BC()
{
    cout<<"您已进入图书流通子系统\n";
    int cnt;
    while(true)
    {
        cout<<"1.借书处理\n";
        cout<<"2.还书处理\n";
        cout<<"3.逾期处理\n";
        cout<<"4.返回主菜单\n";
        cin>>cnt;
        if(cnt==1)
        {
            search_book();
            cout<<"请输入您可借的书的记录号(该书的已借出数小于总数)\n";
            int ans=0;
            cin>>ans;
            ifstream inf("book.txt",ios::in|ios::binary);
	        inf.seekg(0,ios::end);
	        int ncnt=inf.tellg();
	        ncnt/=sizeof(book);
	        inf.close();
	        if(ans<=0 || ans>ncnt) cout<<"该系统无该书\n";
	        vector<book>vt;
	        ifstream in("book.txt",ios::binary|ios::in);
            for(int i=1;i<=ncnt;i++)
            {
                book temp;
                in.read((char*)&temp,sizeof(book));
                if(i==ans)
                {
                    temp.bor++;
                }
                vt.push_back(temp);
            }
            in.close();
            ofstream out("book.txt",ios::out|ios::binary);
            for(int i=0;i<ncnt;i++)
            {
                book temp(vt[i]);
                out.write((char*)&temp,sizeof(book));
            }
            out.close();
            BR newbr;
            {
                newbr.rthis=ans;
                time_t tt;
                time(&tt);
                tt=tt+8*3600;  // transform the time zone
                tm* t= gmtime(&tt);
                newbr.byear=t->tm_year+1900,
                newbr.bmouth=t->tm_mon+1,
	            newbr.bday=t->tm_mday,
	            newbr.bhour=t->tm_hour,
	            newbr.bmin=t->tm_min,
	            newbr.bsec=t->tm_sec;
            }
            int ry,rm,rd;
            cout<<"请输入您的还书日期 (年月日)\n";
            cin>>ry>>rm>>rd;
            ubr ti;
            int rcnt=ti.sum_ubr();
            vector<ubr>vbr;
            ifstream inb("UBR.txt",ios::in|ios::binary);
            for(int i=0;i<rcnt;i++)
            {
                ubr temp;
                inb.read((char*)&temp,sizeof(ubr));
                if(scmp(temp.un,now.getname()))
                {
                    newbr.ryear=ry;
                    newbr.rmouth=rm;
                    newbr.rday=rd;
                    temp.v[temp.len].set(newbr);
                    temp.len++;
                }
                vbr.push_back(temp);
            }
            inb.close();
            ofstream outb("UBR.txt",ios::out|ios::binary);
            for(int i=0;i<rcnt;i++)
            {
                ubr temp(vbr[i]);
                outb.write((char*)&temp,sizeof(ubr));
            }
            outb.close();
            cout<<"借书成功\n";
        }
        if(cnt==2)
        {
            cout<<"请输入您还的书的记录号\n";
            int ans=0;
            cin>>ans;
            ifstream inf("book.txt",ios::in|ios::binary);
	        inf.seekg(0,ios::end);
	        int ncnt=inf.tellg();
	        ncnt/=sizeof(book);
	        inf.close();
	        vector<book>vt;
	        ifstream in("book.txt",ios::binary|ios::in);
            for(int i=1;i<=ncnt;i++)
            {
                book temp;
                in.read((char*)&temp,sizeof(book));
                if(i==ans)
                {
                    temp.bor--;
                }
                vt.push_back(temp);
            }
            in.close();
            ofstream out("book.txt",ios::out|ios::binary);
            for(int i=0;i<ncnt;i++)
            {
                book temp(vt[i]);
                out.write((char*)&temp,sizeof(book));
            }
            out.close();
            BR newbr;
            {
                newbr.rthis=ans;
                time_t tt;
                time(&tt);
                tt=tt+8*3600;  // transform the time zone
                tm* t= gmtime(&tt);
                newbr.ryear=t->tm_year+1900,
                newbr.rmouth=t->tm_mon+1,
	            newbr.rday=t->tm_mday,
	            newbr.rhour=t->tm_hour,
	            newbr.rmin=t->tm_min,
	            newbr.rsec=t->tm_sec;
            }
            ubr ti;
            int rcnt=ti.sum_ubr();
            vector<ubr>vbr;
            ifstream inb("UBR.txt",ios::in|ios::binary);
            for(int i=0;i<rcnt;i++)
            {
                ubr temp;
                inb.read((char*)&temp,sizeof(ubr));
                if(scmp(temp.un,now.getname()))
                {
                    for(int i=0;i<temp.len;i++)
                    {
                        if(temp.v[i].rthis==newbr.rthis)
                        {
                            for(int j=i+1;j<temp.len;j++)
                            {
                                temp.v[j].set(temp.v[j+1]);
                            }
                            BR tj;
                            temp.len--;
                            temp.v[temp.len].set(tj);
                            break;
                        }
                    }
                }
                vbr.push_back(temp);
            }
            inb.close();
            ofstream outb("UBR.txt",ios::out|ios::binary);
            for(int i=0;i<rcnt;i++)
            {
                ubr temp(vbr[i]);
                outb.write((char*)&temp,sizeof(ubr));
            }
            outb.close();
            cout<<"还书成功\n";
        }
        if(cnt==3)
        {
            BR newbr;
            cout<<"正在查询您的借书记录\n";
            time_t tt;
            time(&tt);
            tt=tt+8*3600;  // transform the time zone
            tm* t= gmtime(&tt);
            newbr.ryear=t->tm_year+1900,
            newbr.rmouth=t->tm_mon+1,
            newbr.rday=t->tm_mday,
            newbr.rhour=t->tm_hour,
            newbr.rmin=t->tm_min,
            newbr.rsec=t->tm_sec;
            ubr ti;
            int rcnt=ti.sum_ubr();
            int flag=0;
            ifstream inb("UBR.txt",ios::in|ios::binary);
            for(int i=0;i<rcnt;i++)
            {
                ubr temp;
                inb.read((char*)&temp,sizeof(ubr));
                if(scmp(temp.un,now.getname()))
                {
                    for(int i=0;i<temp.len;i++)
                    {
                        if(temp.v[i].ryear<=newbr.ryear &&
                           temp.v[i].rmouth<=newbr.rmouth &&
                           temp.v[i].rday<=newbr.rday)
                        {
                            flag++;
                            cout<<"你的记录号为"<<temp.v[i].rthis<<"的书已逾期,请尽快归还\n";
                        }
                    }
                }
            }
            if(flag==0) cout<<"你无书逾期!!\n";
            inb.close();
        }
        if(cnt==4)
        {
            break;
        }
    }
}
void search_rec(int x)
{
    ifstream in("book.txt",ios::binary|ios::in);
    for(int i=1;i<=x;i++)
    {
        book temp;
        in.read((char*)&temp,sizeof(book));
        if(i==x)temp.show();
    }
    in.close();
}
int sum_book()
{
    ifstream inf("book.txt",ios::in|ios::binary);
	inf.seekg(0,ios::end);
	int ncnt=inf.tellg();
	ncnt/=sizeof(book);
	inf.close();
	return ncnt;
}

void HZ()
{
    cout<<"图书主文件\n";
    int n=sum_book();
    ifstream in("book.txt",ios::in|ios::binary);
    cout<<"记录号  ";
    cout<<"书号  ";
    cout<<"书名  ";
    cout<<"作者  ";
    cout<<"出版社  ";
    cout<<"总书量  ";
    cout<<"已借出量  "<<endl;
    while(n--)
    {
        book temp;
        in.read((char*)&temp,sizeof(temp));
        cout<<"  "<<temp.rec;
        cout<<"     ";
        if(temp.book_num<1000) cout<<"0";
        cout<<temp.book_num;
        cout<<"  "<<temp.book_name;
        cout<<"  "<<temp.aut;
        cout<<"  "<<temp.ph;
        cout<<"  "<<temp.sum;
        cout<<"  "<<temp.bor<<endl;
    }
    in.close();
    cout<<"书名索引\n";
    {
        ifstream in("name.txt",ios::in|ios::binary);
        in.seekg(0,ios::end);
        int n=in.tellg();
        if(n<0) n=0;
        n/=sizeof(bname);
        in.close();
        ifstream inf("name.txt",ios::in|ios::binary);
        for(int i=0;i<n;i++)
        {
            bname btemp;
            inf.read((char*)&btemp,sizeof(bname));
            cout<<"书名"<<btemp.b_name<<"记录号数量为"<<btemp.len<<"如下\n";
            for(int i=0;i<btemp.len;i++)
            cout<<btemp.v[i]<<" ";
            cout<<endl;
        }
        inf.close();
    }
    cout<<"作者索引\n";
    {
     // baut
        ifstream in("aut.txt",ios::in|ios::binary);
        in.seekg(0,ios::end);
        int n=in.tellg();
        if(n<0) n=0;
        n/=sizeof(baut);
        in.close();
        ifstream inf("aut.txt",ios::in|ios::binary);
        for(int i=0;i<n;i++)
        {
            baut btemp;
            inf.read((char*)&btemp,sizeof(baut));
            cout<<"作者"<<btemp.b_aut<<"记录号数量为"<<btemp.len<<"如下\n";;
            for(int i=0;i<btemp.len;i++)
            cout<<btemp.v[i]<<" ";
            cout<<endl;
        }
        inf.close();
    }
    cout<<"出版社索引\n";
    {
    // bph
        ifstream in("ph.txt",ios::in|ios::binary);
        in.seekg(0,ios::end);
        int n=in.tellg();
        if(n<0) n=0;
        n/=sizeof(bph);
        in.close();
        ifstream inf("ph.txt",ios::in|ios::binary);
        for(int i=0;i<n;i++)
        {
            bph btemp;
            inf.read((char*)&btemp,sizeof(bph));
            cout<<"出版社"<<btemp.b_ph<<"记录号数量为"<<btemp.len<<"如下\n";;
            for(int i=0;i<btemp.len;i++)
            cout<<btemp.v[i]<<" ";
            cout<<endl;
        }
        inf.close();
    }
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章