用mysql数据库实现的C++图书管理系统

合集下载

数据库课程设计——图书管理系统

数据库课程设计——图书管理系统

借阅管理模块
实现图书的借阅、归还和 续借功能,记录借阅历史 和当前借阅状态。
系统管理模块
实现用户管理、权限管理 、日志管理等功能,保障 系统的安全性和稳定性。
04
系统实现
开发环境搭建
开发工具
Visual Studio Code、MySQL Workbench
运行环境
Windows 10、MySQL 5.7
息。
借阅数据
包括借阅编号、读者 编号、图书编号、借 阅日期、归还日期等
信息。
系统用户数据
包括用户编号、用户 名、密码、角色和权
限等信息。
性能需求
响应时间
01
系统响应时间应小于2秒。
并发用户数
02
系统应支持至少100个并发用户。
数据备份与恢复
03
系统应具备定期自动备份和手动备份功能,同时能够在需要时
数据库课程设计— —图书管理系统
2024-01-09
目录
• 引言 • 系统需求分析 • 系统设计 • 系统实现 • 系统测试与优化 • 课程设计总结与展望
01
引言
课程设计目的
01 掌握数据库设计的基本步骤和方法
通过课程设计,使学生熟悉数据库设计的流程, 包括需求分析、概念设计、逻辑设计、物理设计 等阶段,并掌握各个阶段的主要任务和方法。
模块实现
图书管理模块
实现图书的录入、修改、删除等功能 ,提供对图书信息的全面管理。
借阅管理模块
实现图书的借阅、归还等功能,记录 借阅历史,方便管理员和读者查看。
读者管理模块
实现读者的注册、登录、个人信息管 理等功能,提供对读者信息的全面管 理。
系统管理模块
实现用户权限管理、系统日志查看等 功能,保障系统的安全性和稳定性。

图书管理系统数据库设计说明书

图书管理系统数据库设计说明书

图书管理系统数据库设计说明书图书管理系统数据库设计说明书1、引言本文档旨在对图书管理系统的数据库设计进行详细说明,包括数据库架构、表结构设计、数据流图等内容,以便于系统开发人员进行系统开发和维护。

2、数据库架构设计2.1 数据库类型本系统将采用关系型数据库,具体使用的数据库管理系统为MySQL。

2.2 数据库服务器架构本系统将采用分布式数据库架构,包括一个主数据库服务器和多个副本数据库服务器。

2.3 数据库服务器部署主数据库服务器和副本数据库服务器将部署在不同的物理机器上,以实现数据的冗余备份和负载均衡。

3、数据库表设计3.1 用户表(User)字段:用户ID、用户名、密码、姓名、年龄、性别、联系方式、电子邮箱、注册时间3.2 图书表(Book)字段:图书ID、图书名称、作者、出版社、出版日期、图书类别、价格、库存数量3.3 图书借阅表(Borrow)字段:借阅ID、用户ID、图书ID、借阅日期、归还日期、借阅状态3.4 图书类别表(Category)字段:类别ID、类别名称、类别描述3.5 出版社表(Publisher)字段:出版社ID、出版社名称、联系方式、地质4、数据流图设计4.1 用户注册流程图描述用户注册过程,包括用户输入信息、系统验证信息、保存用户信息等流程。

4.2 用户借阅图书流程图描述用户借阅图书的过程,包括用户查找图书、用户借阅图书、系统更新库存数量等流程。

4.3 用户归还图书流程图描述用户归还图书的过程,包括用户查找借阅记录、用户归还图书、系统更新借阅状态等流程。

5、附件本文档附带的相关附件包括:- 数据库表结构设计文档- 数据流图设计文档- ER图设计文档6、法律名词及注释本文档涉及的法律名词及其注释如下:- 数据库管理系统(Database Management System,简称DBMS):是一种管理和整理数据库的软件系统。

- 关系型数据库(Relational Database):是一种基于关系模型的数据库,采用表格来组织和管理数据。

大工14秋《软件工程》图书管理系统--可直接上交

大工14秋《软件工程》图书管理系统--可直接上交

大工14秋《软件工程》图书管理系统--可直接上交随着计算机技术的飞速发展,各个领域都在不断地应用计算机技术来提高工作效率。

然而,我校图书馆仍然采用传统的手工管理方式,效率低下,易出错,手续繁琐,耗费大量人力。

为了提高图书馆的管理效率,我们特别编写了这个图书管理系统软件。

本需求的编写目的是为了研究图书管理系统软件的开发途径和应用方法,并为项目策划、概要设计和详细设计提供基础,同时也为维护人员进行内部维护、信息更新、验收和测试提供依据。

本需求的预期读者包括与图书管理系统软件开发有联系的决策人、开发组成员和软件验证者。

2.需求分析2.1功能需求本系统主要包括以下功能模块:图书信息管理模块、读者信息管理模块、借还书管理模块、系统管理模块和统计查询模块。

2.1.1图书信息管理模块该模块主要用于实现对图书信息的录入、修改、查询和删除等操作。

其中,图书信息包括图书编号、图书名称、作者、出版社、出版日期、价格、分类号、馆藏数量等。

2.1.2读者信息管理模块该模块主要用于实现对读者信息的录入、修改、查询和删除等操作。

其中,读者信息包括读者编号、姓名、性别、年龄、联系方式等。

2.1.3借还书管理模块该模块主要用于实现对借阅信息的录入、修改、查询和删除等操作。

其中,借阅信息包括借阅编号、读者编号、图书编号、借阅日期、应还日期、归还日期等。

2.1.4系统管理模块该模块主要用于实现对系统用户、权限、日志等信息的管理。

2.1.5统计查询模块该模块主要用于实现对图书、读者、借阅等信息的统计查询功能,包括图书借阅排行榜、读者借阅排行榜、借阅信息统计等。

2.2性能需求本系统应满足以下性能需求:2.2.1响应时间系统在任何时候都应该有较快的响应速度,用户在进行各种操作时不应该出现明显的卡顿现象。

2.2.2并发处理能力系统应该具有较强的并发处理能力,能够同时处理多个用户的请求。

2.2.3数据安全性系统应该具有较高的数据安全性,能够保护图书馆的图书、读者和借阅等信息不被非法获取、篡改或破坏。

图书管理系统数据库设计-MYSQL实现

图书管理系统数据库设计-MYSQL实现

图书管理系统数据库设计-MYSQL实现这是一个简单的图书管理系统的MYSQL设计,包含了数据插入,删除,定时器,触发器设计一、系统概述1、系统简介图书管理是每个图书馆都需要进行的工作。

一个设计良好的图书管理系统数据库能够给图书管理带来很大的便利。

2、需求分析1.学生可以直接通过借阅终端来查阅书籍信息,同时也可以查阅自己的借阅信息。

2.当学生需要借阅书籍时,通过账号密码登陆借阅系统,借阅系统处理学生的借阅,同时修改图书馆保存的图书信息,修改被借阅的书籍是否还有剩余,同时更新学生个人的借阅信息。

3.学生借阅图书之前需要将自己的个人信息注册,登陆时对照学生信息。

4.学生直接归还图书,根据图书编码修改借阅信息5.管理员登陆管理系统后,可以修改图书信息,增加或者删除图书信息6.管理员可以注销学生信息。

通过需求定义,画出图书管理系统的数据流图:这是一个简单的图书管理系统的MYSQL设计,包含了数据插入,删除,定时器,触发器设计数据流图2这是一个简单的图书管理系统的MYSQL设计,包含了数据插入,删除,定时器,触发器设计三、数据库设计方案图表1、系统E-R模型总体E-R图:3这是一个简单的图书管理系统的MYSQL设计,包含了数据插入,删除,定时器,触发器设计4这是一个简单的图书管理系统的MYSQL设计,包含了数据插入,删除,定时器,触发器设计给出设计的表名、结构以及表上设计的完整性约束。

tudent:5这是一个简单的图书管理系统的MYSQL设计,包含了数据插入,删除,定时器,触发器设计book:book_ort:borrow:存储学生的借书信息return_table:存储学生的归还信息6这是一个简单的图书管理系统的MYSQL设计,包含了数据插入,删除,定时器,触发器设计ticket:存储学生的罚单信息manager:3、设计索引给出在各表上建立的索引以及使用的语句。

tudent:7这是一个简单的图书管理系统的MYSQL设计,包含了数据插入,删除,定时器,触发器设计1.为tu_id创建索引,升序排序ql:createinde某inde某_idontudent(tu_idac);2.为tu_name创建索引,并且降序排序ql:altertabletudentaddinde某inde某_name(tu_name,dec);插入索引操作和结果如下所示:myql>createinde某inde某_idontudent(tu_idac);QueryOK,0rowaffectedRecord:0Duplicate:0Warning:0myql>altertabletudentaddinde某inde某_name(tu_namedec);QueryOK,0rowaffectedRecord:0Duplicate:0Warning:0myql>book:1.为book_id创建索引,升序排列ql:createinde某inde某_bidonbook(book_id);2.为book_record创建索引,以便方便查询图书的登记日期信息,升序:ql:createinde某inde某_brecordonbook(book_record);8这是一个简单的图书管理系统的MYSQL设计,包含了数据插入,删除,定时器,触发器设计插入索引的操作和结果如下所示:myql>createinde某inde某_bidonbook(book_id);QueryOK,0rowaffectedRecord:0Duplicate:0Warning:0myql>createinde某inde某_brecordonbook(book_record);QueryOK,0rowaffectedRecord:0Duplicate:0Warning:0borrow:1.为tu_id和book_id创建多列索引:ql:createinde某inde某_id_bidonborrow(tu_idac,book_idac);插入索引的操作和结果如下所示:myql>createinde某inde某_id_bidonborrow(tu_idac,book_idac);QueryOK,0rowaffected Record:0Duplicate:0Warning:0return_table:1.为tu_id和book_id创建多列索引:9这是一个简单的图书管理系统的MYSQL设计,包含了数据插入,删除,定时器,触发器设计ql:createinde某inde某_id_bidonreturn_table(tu_idac,book_idac);插入索引的操作和结果如下所示:myql>createinde某inde某_id_bid_ronreturn_table(tu_idac,book_idac);QueryOK,0rowaffected Record:0Duplicate:0Warning:0ticket:1.为tu_id和book_id创建多列索引:ql:createinde某inde某_id_bidonticket(tu_idac,book_idac);插入索引的操作和结果如下所示:myql>createinde某inde某_id_bidonticket(tu_idac,book_idac);QueryOK,0rowaffected Record:0Duplicate:0Warning:0manager:1.为manager_id创建索引:ql:createinde某inde某_midonmanager(manager_id);插入索引的操作和结果如下所示:10这是一个简单的图书管理系统的MYSQL设计,包含了数据插入,删除,定时器,触发器设计myql>createinde某inde某_midonmanager(manager_id);QueryOK,0rowaffectedRecord:0Duplicate:0Warning:04、设计视图给出在各表上建立的视图以及使用的语句。

mysql数据表案例

mysql数据表案例

mysql数据表案例MySQL数据表是MySQL数据库中的一个重要组成部分,用于存储和组织数据。

下面列举了一些常见的MySQL数据表案例,以帮助读者更好地理解和应用MySQL数据库。

1. 学生信息表(Student)学生信息表用于存储学生的基本信息,包括学生ID、姓名、性别、年龄、班级等字段。

通过该表可以方便地查询和管理学生的信息。

2. 课程信息表(Course)课程信息表用于存储学校开设的课程信息,包括课程ID、课程名称、学分、教师ID等字段。

该表可以帮助学校管理课程的开设情况和教师的分配情况。

3. 教师信息表(Teacher)教师信息表用于存储教师的基本信息,包括教师ID、姓名、性别、年龄、职称等字段。

通过该表可以方便地查询和管理教师的信息。

4. 学生成绩表(Score)学生成绩表用于存储学生的各科成绩信息,包括学生ID、课程ID、成绩等字段。

该表可以方便地查询和分析学生的成绩情况。

5. 图书信息表(Book)图书信息表用于存储图书的基本信息,包括图书ID、书名、作者、出版社等字段。

通过该表可以方便地查询和管理图书的信息。

6. 借阅记录表(Borrow)借阅记录表用于存储图书的借阅情况,包括借阅ID、学生ID、图书ID、借阅日期、归还日期等字段。

该表可以帮助图书馆管理图书的借阅和归还情况。

7. 订单信息表(Order)订单信息表用于存储用户的订单信息,包括订单ID、用户ID、商品ID、数量、总金额等字段。

该表可以方便地查询和管理用户的订单信息。

8. 商品信息表(Product)商品信息表用于存储商家的商品信息,包括商品ID、商品名称、价格、库存等字段。

通过该表可以方便地查询和管理商品的信息。

9. 客户信息表(Customer)客户信息表用于存储客户的基本信息,包括客户ID、姓名、性别、年龄、联系方式等字段。

通过该表可以方便地查询和管理客户的信息。

10. 供应商信息表(Supplier)供应商信息表用于存储供应商的基本信息,包括供应商ID、公司名称、联系人、联系方式等字段。

图书管理系统

图书管理系统

摘要随着计算机网络和Internet的普及,运用先进的管理信息系统及软件开发平台,对信息进行科学化和网络化管理,已经成为当今时代的发展趋势。

世纪是一个信息化的时代,获取信息是现在最重要的事情。

开发基于jsp的图书管理系统主要是基于软件开发的软件工程的原理,结合面向视觉语言来实现的教训对象,根据以往的工作经验,开发自己的系统。

该系统的MyEclipse作为功能强大的开发工具和MySQL数据库设计的背景下,整个系统具有简单,干净的界面展现出来,就这么简单,可行,易于使用的用户,操作简单。

该系统采用了上流社会更先进的技术来建立一个三层MVC的性能,可扩展性和强大的信息管理系统。

关键词:图书管理;MyEclipse;MySQL;jspAbstractWith the popularity of computer network and Internet, the use of advanced management information system and software development platform, to carry on the scientific and the information network management, has become a development trend in today's world. Century is an era of information, access to information is the most important thing now.Development based on JSP household goods sales site is mainly based on the principle of software engineering software development, the visual language to realize the teaching object oriented, based on past experience, develop their own systems. The system MyEclipse as a powerful development tools and design under the background of the MySQL database, the system has a simple, clean interface, it's that simple, feasible and easy to use user, the operation is simple. The system USES a society more advanced technology to set up a three-tier MVC performance, scalability and powerful information management system.Key words: book management; MyEclipse; MySQL; jsp目录1 前言 (1)1.1 课题背景及意义 (1)1.2 管理信息系统发展现状 (1)1.3 课题的研究方法、技术路线 (3)2 相关技术简介 (4)2.1 Jsp技术介绍 (4)2.2 MyEclipse简介 (4)2.3 Tomcat简介 (4)2.4 MySQL数据库 (5)3 系统分析 (7)3.1 系统设计目标 (7)3.2 系统可行性分析 (7)3.4 系统设计规则 (8)3.5 运行环境 (9)4 系统设计 (10)4.1 架构设计 (10)4.2 功能模块设计 (11)4.3 技术架构 (11)4.4 数据库结构设计 (12)4.4.1 数据库设计规范 (12)4.4.2 数据库概念模型 (13)4.4.3 数据表字段设计 (13)4.5 系统架构类图 (16)4.6 系统交互图 (16)5 详细设计 (18)5.1 数据库连接配置 (18)5.2 功能模块实现 (19)5.2.1 登陆界面 (19)5.2.2 管理员主界面 (20)5.2.3 管理员信息维护界面 (20)5.2.4 借书界面 (21)5.2.5 借阅人管理界面 (21)5.2.6 借阅人主界面 (22)5.2.7 图书管理界面 (22)5.2.8 图书类别管理界面 (23)5.2.9业绩管理界面 (23)6 系统的测试 (25)6.1 程序调试 (25)6.2 程序的测试 (25)6.2.1 测试的重要性及目的 (25)6.2.2 测试的步骤 (26)6.2.3 测试的主要内容 (27)总结 (29)致谢 (30)参考文献 (31)1 前言1.1 课题背景及意义如今网络的发展越来越迅猛,人们上网的途径也是越来越方便,网络在人们生活中的应用也越来越广泛,使得在网络上进行图书的管理成为目前深受学校喜欢的一种管理方式。

用PHP+MySQL构架数据库驱动的图书馆网站

用PHP+MySQL构架数据库驱动的图书馆网站
实现对 它们 的访 问 。 ( ) 速 度快 5、
软 件包 解 压 , :uzi aah 如 gna pce一2 0 5 p . .4一sl o7一
s a c—lc 1 g 。 pr o a. z
3 2软件 的安 装及 配置 .
在 Sli系统下 , 以用 p gd 命令安装软 or as 可 kad 件包 , 对于上述软件包 均可用 p gd 命令来完成 kad 安装 。
维普资讯
图书馆研 究与工作
20 0 6年 第 2期 ( 第 16期 ) 总 0
用 P P+M S L构架数据库驱动 的图书馆 网站 H yQ
廖 晓飞 ( 绍兴图 书馆 浙江绍兴 3 00 1 0) 2
摘 要 文章对 中小图书馆使用 P P+ yQ H M S L构 架数据库驱动的网站进行 了阐 述, 分析 了其特 点 并介绍 实现 方 法 。 P My Q 数 据库 驱动 网站 HP SL
P P支 持 面 向对 象 的程 序 设 计 方 法 , 以用 H 可 类来 定义 抽 象 数 据 类 型 , 实 体 的特 性 和 具 体 的 将
操作分开 , 并隐藏实现细节 , 外部 以统一的接 口进 行对象的控制。P P提供一种模板类 ( m l e , H t pt e a)
图 l 数据 库驱动 的 网站运 行机 制 、
台上构架数据库驱动 的网站 , 需要选用一种合适 的数 据 库 系 统 , 用 的 有 Sbs、no x Oal 常 yae Ifmi、 rc r e 等 主流数 据 库 , 类 数 据 库 虽 然 很 好 , 价 格 不 这 但 菲 , 中小 图书 馆 而 言性 价 比并 非 最 好 。选 用 一 对 种 既经济安 全 又稳定 可 靠 的数 据 库 系统 成 为 中小 图书 馆 的 必 然 选 择 。 为 此 , 文 提 出 了 P P 与 本 H M S L这一黄金组合来架构 图书馆 网站 的方案 , yQ 很好 地解决 了这 些 问题 。 2 H .P P+MyQ S L技术 的介 绍

图书馆系统开发背景和意义

图书馆系统开发背景和意义

内容摘要本课题的主要内容在于对本系统能高效、快捷、稳定地管理图书馆的数据信息。

系统主要能实现以下几个功能:查询图书、借还图书、图书管理、读者信息管理等。

操作管理员只需要通过浏览器访问本系统,就可以轻松实现图书查询、图书借还等操作。

超级管理员使用本系统能方便快捷地完成图书馆的信息数据管理工作。

本文介绍了在网络环境下提出实现图书馆信息管理、资源共享的基本目标,从而推动迈向数字化图书馆的步伐,并阐述系统结构设计和功能设计,从图书的入库登记到查询浏览,从读者的登记到图书的借阅,形成了一个整体自动化管理模式。

本文通过对学校图书资料管理室现状和需求的分析研究, 运用 PHP 技术, 以 MySQL 为后台数据库, 设计并实现了学校图书室的图书管理系统。

该系统实现了图书资料管理的数字化,提高了管理工作的效率和规范化水平。

关键词:图书管理设计研究AbstractThe main content of this paper is that the system can efficiently, fast, stable management of library data information. System is mainly to achieve the following functions: search for books, borrow books, books management, reader information management. Operation manager only interview the system through the browser, they can easily search for a book, books borrow also operation. Super administrator using this system can quickly and easily complete library of information data management. This paper introduces the network environment library information management, put forward to realize the basic objectives of resource sharing, thus promoting the digital library into the pace, and introduces the structure design and functional design, the book from the storage register to the query, the reader from the registration to books borrowing, formed a whole automation management mode. This article through to the school library information management room present situation and demand analysis, using PHP technology, using MySQL as background database, design and Realization of class library management system. This system has realized the books information management of digital, enhances the management efficiency and standardization level.Key words: book management design study目录前言 (1)1 系统概述 (2)1.1 系统开发背景和意义 (2)1.2 现有图书管理系统的概述 (2)1.3 开发环境 (3)2 系统分析 (3)2.1 任务概述 (3)2.2 系统可行性分析 (3)2.3 需求分析 (4)2.4 流程分析 (5)2.5 数据字典 (7)3 系统设计 (8)3.1 图书馆管理系统设计指导思想和原则 (8)3.2 总体功能设计 (8)3.3功能模块详细设计 (9)3.4 系统数据库设计 (12)4 系统实现................................... 错误!未定义书签。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

#include<fstream>#include<iostream>#include<stdlib.h>#include<ctime>#include<cmath>#include<termios.h>#include <sstream>#include<string.h>#include<assert.h>#include<mysql/mysql.h>//改变字体颜色#define NONE "\033[m"#define RED "\033[0;32;31m"#define GREEN "\033[0;32;32m"#define BLUE "\033[0;32;34m"#define YELLOW "\033[1;33m"#define LIGHT_RED "\033[1;31m"#define LIGHT_GREEN "\033[1;32m"#define LIGHT_BLUE "\033[1;34m"/*在编译程序之前,请先开启mysql服务器(命令为sudo mysqld_safe &),然后再登录mysql客户端(命令为mysql -u root -p)建立数据库stu;建立数据表reader,book;具体操作语句如下:create database stu;create table reader(stu_name varchar(20),stu_phone varchar(15),stu_password varchar(10),stu_num int,debt float,lend_time double,back_time double,count int);create table book(book_name varchar(40),book_aut varchar(40),book_pre varchar(40),book_num int,book_mux int,book_con int);编译时用如下命令:g++ $(mysql_config --cflags) 110.cpp -o t $(mysql_config --libs)*///定义mysql数据库变量MYSQL mysql;MYSQL_RES * results;MYSQL_FIELD *fileds;MYSQL_ROW rows;char strHost[] = "localhost";char strUser[] = "root";char strPasswd[] = "3335599";char strDb[] = "stu";char strSQL[200];unsigned int num_fields;/*程序导读:1.程序中对书的操作,可通过书名,编号来进行,flag=0按书名来操作,flag=1按书编号来操作2.程序中对用户的操作,也可通过姓名,用户ID号或编号两种方式来进行,flag=0按姓名来操作,flag=1按用户ID号或编号来操作3.本程序分5个部分,具体已标识如(1)图书管理...4.本程序即可实现将数据保存至本地即stu.txt,book.txt,又可将数据保存至mysql数据库,只需稍加修改,具体如何修改,在此就不做说明*/using namespace std;class Book{public:string book_name;string book_num;//编号string book_pre;//出版社string book_aut;//作者int book_con;//这样的书还有几本int book_mux;//这样的书总共有几本public:Book(){book_con=0;book_mux=0;}void show_book();};/****************************************(1)图书管理*******************************************/void Book::show_book(){cout<<"书名:"<<book_name<<endl;cout<<"出版社:"<<book_pre<<endl;cout<<"此书的作者:"<<book_aut<<endl;cout<<"ISBN编号:"<<book_num<<endl;cout<<"此书共有"<<book_mux<<"本"<<endl;cout<<"还有"<<book_con<<"本书未借出!"<<endl;}class BookNode{public:Book book;BookNode *next;};BookNode *headbook=NULL;void savebook(BookNode *p);//保存图书信息到数据库void del_sql_book(BookNode *p);//将图书信息从数据库中删除class BookManage{public:int totolbook;public:BookManage(){totolbook=0;}void addbook();void delbook(string s,int num,int flag);void findbook(string s,int flag);//查询图书};void BookManage::addbook(){string h;cout<<"添加输入0,退出输入-1"<<endl;cin>>h;if(h=="-1")return;else if(h=="0")while(1){if(h=="-1")break;else if(h=="0"){string na,nu,p1,aut;int con;BookNode *p=new BookNode;cout<<"请输入书名:"<<endl;cin>>na;p->book.book_name=na;cout<<"请输入ISBN编号:"<<endl;cin>>nu;p->book.book_num=nu;cout<<"请输入出版社:"<<endl;cin>>p1;p->book.book_pre=p1;cout<<"请输入此书的作者:"<<endl;cin>>aut;p->book.book_aut=aut;cout<<"请输入此书共有几本:"<<endl;cin>>con;p->book.book_con=con;p->book.book_mux=con;p->next=headbook;headbook=p;savebook(p);//添加至数据库BookManage::totolbook+=con;cout<<"继续添加输入0,取消添加输入-1"<<endl;cin>>h;}elsecout<<YELLOW"输入字符无效!"NONE<<endl;}elsecout<<YELLOW"输入字符无效!"NONE<<endl;}void BookManage::delbook(string s,int num,int flag){BookNode *p=headbook;if(headbook!=NULL){switch(flag){case 0:if(headbook->book.book_name==s){if(headbook->book.book_con>1){headbook->book.book_con-=num;headbook->book.book_mux-=num;}else{headbook=p->next;totolbook-=num;del_sql_book(p);//从数据库中删除//delete p;}}else if(p->next){for(p=headbook;p->next!=NULL&&p!=NULL;p=p->next){if(p->next->book.book_name==s){if(p->next->book.book_con>1){p->next->book.book_con-=num;headbook->book.book_mux-=num;break;}else{p->next=p->next->next;totolbook-=num;del_sql_book(p->next);//从数据库中删除//delete p->next;break;}}}if(p->next==NULL)cout<<YELLOW"此书不存在!"NONE<<endl;}break;case 1:if(headbook->book.book_num==s){if(headbook->book.book_con>1){headbook->book.book_con-=num;headbook->book.book_mux-=num;}else{headbook=p->next;totolbook-=num;del_sql_book(p);//从数据库中删除//delete p;}}else if(p->next){for(p=headbook;p->next!=NULL&&p!=NULL;p=p->next){if(p->next->book.book_num==s){if(p->next->book.book_con>1){p->next->book.book_con-=num;headbook->book.book_mux-=num;break;}else{p->next=p->next->next;totolbook-=num;del_sql_book(p->next);//从数据库中删除//delete p->next;break;}}}if(p->next==NULL)cout<<YELLOW"此书不存在!"NONE<<endl;}break;default:cout<<YELLOW"输入数字无效!"NONE<<endl;break;}}}void BookManage::findbook(string s,int flag){BookNode *p; int h=0;switch(flag){case 0:for(p=headbook;p!=NULL;p=p->next)//先查看是否有此书{if(p->book.book_name==s)break;}if(NULL==p)cout<<YELLOW"此书不存在!"NONE<<endl;for(p=headbook;p!=NULL;p=p->next)//查看名为s的图书共有几本{if(p->book.book_name==s)h++;}if(h>0)cout<<GREEN"这种名字的书共有"<<h<<"本"NONE<<endl;for(p=headbook;p!=NULL;p=p->next)//查看图书,把所有名为s的图书的信息都打印出来{if(p->book.book_name==s){p->book.show_book();//显示出图书的基本信息if(p->book.book_con==0)cout<<YELLOW"该书已全被借出!"NONE<<endl;cout<<endl;}}break;case 1:for(p=headbook;p!=NULL;p=p->next){if(p->book.book_num==s){p->book.show_book();if(p->book.book_con==0)cout<<YELLOW"该书已全被借出!"NONE<<endl;break;}}if(NULL==p)cout<<YELLOW"此书不存在!"NONE<<endl;break;default:cout<<YELLOW"输入数字无效!"NONE<<endl;break;}}/****************************************(2)用户管理*******************************************/class Admin//管理员{public:string adm_name;//帐号string adm_passw;//密码public:Admin(){adm_name="adm";adm_passw="123";}};class LendBook{public:string bookname[3];int count;//借多少本数time_t lend_time;time_t back_time;LendBook(){count=0;}};class Stu{public:string stu_name;string stu_phone;//联系方式string stu_num;//学号(登录帐号)string password;//密码float debt;//欠费额LendBook lendbook;//用户借书信息public:void show_stu();//把此人所有信息(包括借书)显示出来};void Stu::show_stu(){cout<<"姓名:"<<stu_name<<endl;cout<<"联系电话:"<<stu_phone<<endl;cout<<"ID:"<<stu_num<<endl;cout<<"欠费额:"<<debt<<endl;cout<<"已借书"<<lendbook.count<<"本"<<endl;}class StuNode{public:Stu stu;StuNode *next;};StuNode *headstu=NULL;void savestu(StuNode *p);//保存读者信息到数据库void del_sql_stu(StuNode *p);//将读者信息从数据库中删除class StuManage:public BookManage{private:int totolstu;//用户总数public:StuManage(){totolstu=0;}void addstu();//增加用户void delstu(string s,int flag);//删除用户void findstu(string s,int flag);//查找用户void lendbook(string ss,string s,int flag);//借书void backbook(string ss,string s,int flag);//还书void paydebt(string s);//还款void mux_stu_book();//查询图书管总的图书量与总的用户量};void StuManage::addstu(){string h;cout<<"添加输入0,退出输入-1"<<endl;cin>>h;if(h=="-1")return;else if(h=="0")while(1){if(h=="-1")break;else if(h=="0"){string na,num,p1,pa,pa1,pa2;StuNode *p=new StuNode;cout<<"请输入姓名:"<<endl;cin>>na;p->stu.stu_name=na;cout<<"请输入联系电话:"<<endl;cin>>p1;p->stu.stu_phone=p1;cout<<"请输入ID:"<<endl;cin>>num;p->stu.stu_num=num;p->stu.lendbook.lend_time=0;p->stu.lendbook.back_time=0;while(1){cout<<"请输入六位密码:"<<endl;cin>>pa1;cout<<"请确认六位密码:"<<endl;cin>>pa2;if(pa1==pa2){pa=pa2;p->stu.password=pa;break;}elsecout<<YELLOW"两次密码不一样,请重行输入!"NONE<<endl;}p->stu.debt=0;p->next=headstu;headstu=p;savestu(p);//保存至数据库(StuManage::totolstu)++;//用户总数加一cout<<"继续添加输入0,取消添加输入-1"<<endl;cin>>h;}elsecout<<YELLOW"输入字符无效!"NONE<<endl;}elsecout<<YELLOW"输入字符无效!"NONE<<endl;}void StuManage::delstu(string s,int flag){StuNode *p=headstu;if(headstu!=NULL){switch(flag){case 0:if(headstu->stu.stu_name==s)//当要删除的用户位于链表的头结点位置{headstu=p->next;StuManage::totolstu--;del_sql_stu(p);//从数据库中删除delete p;}else if(p->next)//非头结点位置{for(p=headstu;p->next!=NULL&&p!=NULL;p=p->next){if(p->next->stu.stu_name==s){p->next=p->next->next;totolstu--;del_sql_stu(p->next);//从数据库中删除//delete p->next;break;}}if(p->next==NULL)cout<<YELLOW"此用户不存在!"NONE<<endl;}break;case 1:if(headstu->stu.stu_name==s){headstu=p->next;totolstu--;del_sql_stu(p);//从数据库中删除delete p;}else if(p->next){for(p=headstu;p->next!=NULL&&p!=NULL;p=p->next){if(p->next->stu.stu_name==s){p->next=p->next->next;totolstu--;del_sql_stu(p->next);//从数据库中删除//delete p->next;break;}}if(p->next==NULL)cout<<YELLOW"此用户不存在!"NONE<<endl;}break;default:cout<<YELLOW"输入数字无效!"NONE<<endl;break;}}}void StuManage::findstu(string s,int flag){StuNode *p; int h=0,m=1;switch(flag){case 0:for(p=headstu;p!=NULL;p=p->next){if(p->stu.stu_name==s)break;}if(p==NULL)cout<<YELLOW"此用户不存在!"NONE<<endl;for(p=headstu;p!=NULL;p=p->next){if(p->stu.stu_name==s)h++;}if(h>0)cout<<GREEN"这种名字的用户共有"<<h<<"个"NONE<<endl;for(p=headstu;p!=NULL;p=p->next){if(p->stu.stu_name==s){p->stu.show_stu();if(p->stu.lendbook.count>=3){cout<<YELLOW"sorry,您已借满3本书,不能再借了!!!"NONE<<endl;int i=p->stu.lendbook.count;if(i>0)cout<<"所借书的名字为:"<<endl;//输出用户所借书的名字while(i){cout<<"\t("<<m++<<"):"<<p->stu.lendbook.bookname[i-1]<<endl;i--;}cout<<endl;}else{int i=p->stu.lendbook.count;if(i>0)cout<<"所借书的名字为:"<<endl;//输出用户所借书的名字while(i){cout<<"\t("<<m++<<"):"<<p->stu.lendbook.bookname[i-1]<<endl;i--;}cout<<"您已借了"<<p->stu.lendbook.count<<"本书!"<<endl;cout<<"您还可以借"<<3-p->stu.lendbook.count<<"本书!"<<endl;cout<<endl;}}}break;case 1:for(p=headstu;p!=NULL;p=p->next){if(p->stu.stu_num==s){p->stu.show_stu();if(p->stu.lendbook.count>=3){cout<<YELLOW"sorry,您已借满3本书,不能再借了!!!"NONE<<endl;int i=p->stu.lendbook.count;cout<<"所借书的名字为:"<<endl;//输出用户所借书的名字while(i){ //输出用户所借书的名字cout<<"\t("<<m++<<"):"<<p->stu.lendbook.bookname[i-1]<<endl;i--;}cout<<endl;}else{int i=p->stu.lendbook.count;cout<<"所借书的名字为:"<<endl;//输出用户所借书的名字while(i){ //输出用户所借书的名字cout<<"\t("<<m++<<"):"<<p->stu.lendbook.bookname[i-1]<<endl;i--;}cout<<"您已借了"<<p->stu.lendbook.count<<"本书!"<<endl;cout<<"您还可以借"<<3-p->stu.lendbook.count<<"本书!"NONE<<endl;cout<<endl;}break;}}if(p==NULL)cout<<YELLOW"此用户不存在!"NONE<<endl;break;default:cout<<YELLOW"输入数字无效!"NONE<<endl;break;}}void StuManage::mux_stu_book(){StuNode *p;BookNode *q;int i=0,j=0,h=0;for(p=headstu;p!=NULL;p=p->next)i++;cout<<"当前图书馆注册用户数为:"<<i<<endl;for(q=headbook;q!=NULL;q=q->next){h+=q->book.book_mux;j+=q->book.book_con;}cout<<"当前图书馆库存的总书数为:"<<j<<endl;cout<<"已借出图书总数为:"<<h-j<<endl;}void StuManage::lendbook(string ss,string s,int flag)//借书{BookNode *p; StuNode *q;for(q=headstu;q!=NULL;q=q->next){if(q->stu.stu_num==ss){del_sql_stu(q);break;}//丛数据库中删除}if(q==NULL){cout<<YELLOW"此用户不存在!"NONE<<endl;return;}switch(flag){case 0:for(p=headbook;p!=NULL;p=p->next){if(p->book.book_name==s){del_sql_book(p);//从数据库中删除int i=q->stu.lendbook.count;if(i>=3||q->stu.debt>0){if((i>=3)&&(q->stu.debt==0)){cout<<YELLOW"对不起,您借书已超过3本,不能再借!"NONE<<endl;}if((i<3)&&(q->stu.debt>0)){cout<<YELLOW"对不起,您因为所借图书超期已欠费,请速交清欠费再借!"NONE<<endl;}if((i>=3)&&(q->stu.debt>0)){cout<<YELLOW"对不起,您借书已超过3本且有欠费,不能再借!"NONE<<endl;}}else{//记录下所借书的名字存入用户信息中q->stu.lendbook.bookname[i]=p->book.book_name;time_t now;time(&now);q->stu.lendbook.lend_time=time(&now);//保存借书时间q->stu.lendbook.count++;//所借书数目加一p->book.book_con--;//同样的书的个数减一}break;}}if(p==NULL)cout<<YELLOW"此书不存在!"NONE<<endl;break;case 1:for(p=headbook;p!=NULL;p=p->next){if(p->book.book_num==s){del_sql_book(p);//从数据库中删除int i=q->stu.lendbook.count;if(i>=3||q->stu.debt>0){if((i>=3)&&(q->stu.debt==0)){cout<<YELLOW"对不起,您借书已超过3本,不能再借!"NONE<<endl;}if((i<3)&&(q->stu.debt>0)){cout<<YELLOW"对不起,您因为所借图书超期已欠费,请速交清欠费再借!"NONE<<endl;}if((i>=3)&&(q->stu.debt>0)){cout<<YELLOW"对不起,您借书已超过3本且有欠费,不能再借!"NONE<<endl;}}else{q->stu.lendbook.bookname[i]=p->book.book_name;time_t now;time(&now);q->stu.lendbook.lend_time=time(&now);q->stu.lendbook.count++;p->book.book_con--;//同样的书的个数减一}break;}}if(p==NULL)cout<<YELLOW"此书不存在!"NONE<<endl;break;default:cout<<YELLOW"输入数字无效!"NONE<<endl;break;}savestu(q);savebook(p);}void StuManage::backbook(string ss,string s,int flag)//还书{BookNode *p; StuNode *q;for(q=headstu;q!=NULL;q=q->next){if(q->stu.stu_num==ss){del_sql_stu(q);break;}//丛数据库中删除}if(q==NULL){cout<<YELLOW"此用户不存在!"NONE<<endl;return;}switch(flag){case 0:for(p=headbook;p!=NULL;p=p->next){if(p->book.book_name==s){del_sql_book(p);//从数据库中删除time_t now;time(&now);q->stu.lendbook.back_time=time(&now);q->stu.lendbook.count--;p->book.book_con++;//同样的书的个数加一time_ts=difftime(q->stu.lendbook.lend_time,q->stu.lendbook.back_time);if(s>2592000)//2592000为一个月的秒数{int t=ceil((s-2592000)/86400);q->stu.debt=t*0.1;}break;}}if(p==NULL)cout<<YELLOW"此书不存在!"NONE<<endl;break;case 1:for(p=headbook;p!=NULL;p=p->next){if(p->book.book_num==s){del_sql_book(p);//从数据库删除time_t now;time(&now);q->stu.lendbook.back_time=time(&now);q->stu.lendbook.count--;p->book.book_con++;//同样的书的个数加一//计算借用图书的时间,超过一个月,开始计费time_ts=difftime(q->stu.lendbook.lend_time,q->stu.lendbook.back_time);if(s>2592000)//2592000为一个月的秒数{int t=ceil((s-2592000)/86400);q->stu.debt=t*0.1;}break;}}if(p==NULL)cout<<YELLOW"此书不存在!"NONE<<endl;break;default:cout<<YELLOW"输入数字无效!"NONE<<endl;break;}savestu(q);savebook(p);}void StuManage::paydebt(string s){StuNode *p;for(p=headstu;p!=NULL;p=p->next)//查找用户{if(p->stu.stu_num==s){p->stu.debt=0;cout<<RED"缴费成功!"NONE<<endl;break;}}if(p==NULL)cout<<YELLOW"该用户不存在!"NONE<<endl;}/****************************************(3)数据保存与下载*******************************************/char stu_str[50];char *change_char(string result){stringstream stream;stream << result; //将string输入流stream >> stu_str; //从i中抽取前面插入的string值return stu_str;}void savestu(StuNode *p)//保存读者信息到数据库{memset((void*)strSQL,0,200);sprintf(strSQL,"insert into reader values(%s,%s,%s,%s,%f,%ld,%ld,%d)",change_char(p->stu.stu_name),change_char(p->stu.stu_ph one),change_char(p->stu.password),change_char(p->stu.stu_num),p->stu.debt,(long)(p->stu.lend book.lend_time),(long)(p->stu.lendbook.back_time),p->stu.lendbook.count);if(mysql_real_query(&mysql,strSQL,strlen(strSQL)) != 0)printf("记录插入失败!\n");}void savebook(BookNode *p)//保存图书信息到数据库{memset((void*)strSQL,0,200);sprintf(strSQL,"insert into book values(%s,%s,%s,%s,%d,%d)",change_char(p->book.book_name),change_char(p->book.book_aut ),change_char(p->book.book_pre),change_char(p->book.book_num),p->book.book_mux,p->boo k.book_con);if(mysql_real_query(&mysql,strSQL,strlen(strSQL)) != 0)printf("记录插入失败!\n");}void del_sql_stu(StuNode *p)//将读者信息从数据库中删除{memset((void*)strSQL,0,200);sprintf(strSQL,"delete from reader where stu_name='%s'",change_char(p->stu.stu_name));if(mysql_real_query(&mysql,strSQL,strlen(strSQL)) != 0)printf("记录删除失败!\n");}void del_sql_book(BookNode *p)//将图书信息从数据库中删除{memset((void*)strSQL,0,200);sprintf(strSQL,"delete from book where book_name='%s'",change_char(p->book.book_name));if(mysql_real_query(&mysql,strSQL,strlen(strSQL)) != 0)printf("记录删除失败!\n");}/*void savestu()//保存读者信息文件{ofstream outfile("./stu.txt",ios::out);if(!outfile){cerr<<"open error!"<<endl;return;}StuNode *p;for(p=headstu;p!=NULL;p=p->next)//数据写入文件{outfile<<p->stu.stu_name<<" "<<p->stu.stu_phone;outfile<<" "<<p->stu.password<<" "<<p->stu.stu_num;outfile<<" "<<p->stu.debt;outfile<<" "<<p->stu.lendbook.lend_time;outfile<<" "<<p->stu.lendbook.back_time;outfile<<" "<<p->stu.lendbook.count;outfile<<" "<<endl;}outfile.close();}void savebook()//保存图书信息文件{ofstream outfile("./book.txt",ios::out);if(!outfile){cerr<<"open error!"<<endl;return;}BookNode *p;for(p=headbook;p!=NULL;p=p->next)//数据写入文件{outfile<<p->book.book_name<<" "<<p->book.book_num;outfile<<" "<<p->book.book_pre<<" "<<p->book.book_aut;outfile<<" "<<p->book.book_mux;outfile<<" "<<p->book.book_con;outfile<<" "<<endl;}outfile.close();}*/void loadstu()//从学生数据数据库reader中读取{int i = 0;memset((void*)strSQL,0,100);strcpy(strSQL,"select * from reader");mysql_query(&mysql,strSQL); //查询results = mysql_store_result(&mysql); //获取记录num_fields = mysql_num_fields(results); //获取字段数fileds = mysql_fetch_fields(results); //获取字段数组while((rows = mysql_fetch_row(results)) != NULL) //循环显示{while(i < num_fields){StuNode *p=new StuNode;p->stu.stu_name = (rows[i]?rows[i++]:"NULL");p->stu.stu_phone = (rows[i]?rows[i++]:"NULL");p->stu.password = (rows[i]?rows[i++]:"NULL");p->stu.stu_num = (rows[i]?rows[i++]:"NULL");p->stu.debt = atof(rows[i]?rows[i++]:"NULL");p->stu.lendbook.lend_time = (time_t)(rows[i]?rows[i++]:"NULL");p->stu.lendbook.back_time = (time_t)(rows[i]?rows[i++]:"NULL");p->stu.lendbook.count = atoi(rows[i]?rows[i++]:"NULL");p->next=headstu;//建立用户链表headstu=p;}i = 0;}}void loadbook()//从书数据库中读取{int i = 0;memset((void*)strSQL,0,100);strcpy(strSQL,"select * from book");mysql_query(&mysql,strSQL); //查询results = mysql_store_result(&mysql); //获取记录num_fields = mysql_num_fields(results); //获取字段数fileds = mysql_fetch_fields(results); //获取字段数组while((rows = mysql_fetch_row(results)) != NULL) //循环显示{while(i < num_fields){BookNode *p=new BookNode;p->book.book_name = (rows[i]?rows[i++]:"NULL");p->book.book_aut = (rows[i]?rows[i++]:"NULL");p->book.book_pre = (rows[i]?rows[i++]:"NULL");p->book.book_num = (rows[i]?rows[i++]:"NULL");p->book.book_mux = atoi(rows[i]?rows[i++]:"NULL");p->book.book_con = atoi(rows[i]?rows[i++]:"NULL");p->next=headbook;//建立用户链表headbook=p;}i = 0;}}/*void loadstu()//从学生数据文件读取{ifstream infile("./stu.txt",ios::in);if(!infile){cout<<YELLOW"数据文件不存在,请先建立该文件"NONE<<endl;return;}if(infile.eof()){cout<<YELLOW"数据库为空,请添加数据"NONE<<endl;infile.close();}else{while(infile.peek()!=EOF)//数据从文件读出{StuNode *p=new StuNode;infile>>p->stu.stu_name>>p->stu.stu_phone;infile>>p->stu.password>>p->stu.stu_num;infile>>p->stu.debt>>p->stu.lendbook.lend_time;infile>>p->stu.lendbook.back_time>>p->stu.lendbook.count;if(p->stu.stu_name!=""){p->next=headstu;//建立用户链表headstu=p;}elsedelete p;}infile.close();}}void loadbook()//从书数据文件读取{ifstream infile("./book.txt",ios::in);if(!infile){cout<<YELLOW"数据文件不存在,请先建立该文件"NONE<<endl;return;}if(infile.eof()){cout<<YELLOW"数据库为空,请添加数据"NONE<<endl;infile.close();}else{while(infile.peek()!=EOF)//数据从文件读出{BookNode *p=new BookNode;infile>>p->book.book_name>>p->book.book_num;infile>>p->book.book_pre>>p->book.book_aut;infile>>p->book.book_mux>>p->book.book_con;if(p->book.book_name!=""){p->next=headbook;//建立图书链表headbook=p;}elsedelete p;}infile.close();}}*//****************************************(4)界面部分*******************************************/void MenuAdmin(){cout<<GREEN">>>>>>>>>>>>>>>>>>>>>>>>>>>>欢迎来到图书管理系统<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"NONE<<endl;cout<<GREEN"$$"NONE<<endl;cout<<GREEN"$ 1 增加新书$"NONE<<endl;cout<<GREEN"$$"NONE<<endl;cout<<GREEN"$ 2 删除书目$"NONE<<endl;cout<<GREEN"$$"NONE<<endl;cout<<GREEN"$ 3 借书$"NONE<<endl;cout<<GREEN"$$"NONE<<endl;cout<<GREEN"$ 4 还书$"NONE<<endl;cout<<GREEN"$$"NONE<<endl;cout<<GREEN"$ 5 查询图书$"NONE<<endl;cout<<GREEN"$$"NONE<<endl;cout<<GREEN"$ 6 增加读者$"NONE<<endl;cout<<GREEN"$$"NONE<<endl;cout<<GREEN"$ 7 删除读者$"NONE<<endl;cout<<GREEN"$$"NONE<<endl;cout<<GREEN"$ 8 查询用户$"NONE<<endl;$"NONE<<endl;cout<<GREEN"$ 9 用户交费$"NONE<<endl;cout<<GREEN"$$"NONE<<endl;cout<<GREEN"$ 10 查询用户总数与图书总数$"NONE<<endl;cout<<GREEN"$$"NONE<<endl;cout<<GREEN"$ 0 退出$"NONE<<endl;cout<<GREEN"$$"NONE<<endl;cout<<GREEN">>>>>>>>>>>>>>>>>>>>>>>>>>[请选择(输入相应数字)]<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"NONE<<endl;}void MenuStu(){cout<<GREEN">>>>>>>>>>>>>>>>>>>>>>>>>>>>欢迎来到图书管理系统<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"NONE<<endl;cout<<GREEN"$$"NONE<<endl;cout<<GREEN"$ 1 借书$"NONE<<endl;cout<<GREEN"$$"NONE<<endl;cout<<GREEN"$ 2 还书$"NONE<<endl;cout<<GREEN"$$"NONE<<endl;cout<<GREEN"$ 3 查询图书$"NONE<<endl;cout<<GREEN"$$"NONE<<endl;cout<<GREEN"$ 4 个人信息$"NONE<<endl;cout<<GREEN"$$"NONE<<endl;cout<<GREEN"$ 0 退出$"NONE<<endl;。

相关文档
最新文档