单链表实现图书管理系统
- 格式:doc
- 大小:69.50 KB
- 文档页数:10
第1篇一、引言随着计算机技术的飞速发展,程序设计已成为现代社会中不可或缺的一部分。
为了提高自己的编程能力,我选择了一门程序设计课程进行实践学习。
本文将详细记录我在课程中的实践过程、心得体会以及遇到的问题和解决方法。
二、实践过程1. 课程背景本课程旨在培养学生的程序设计能力,让学生掌握基本的编程思想、算法和编程语言。
课程内容主要包括C语言、数据结构、算法分析等。
2. 实践内容(1)C语言编程:学习C语言的基础语法、数据类型、运算符、控制结构、函数、指针等。
(2)数据结构:掌握数组、链表、栈、队列、树、图等基本数据结构及其应用。
(3)算法分析:学习算法的基本概念、时间复杂度、空间复杂度、排序算法、查找算法等。
(4)项目实践:结合所学知识,完成一个小型项目,如制作一个简单的计算器、学生信息管理系统等。
3. 实践步骤(1)课前预习:提前阅读教材,了解课程内容,为课堂学习做好准备。
(2)课堂学习:认真听讲,做好笔记,积极回答问题,与同学交流心得。
(3)课后练习:完成课后习题,巩固所学知识。
(4)项目实践:查阅资料,设计项目方案,编写代码,调试程序,直至项目完成。
三、心得体会1. 程序设计需要良好的逻辑思维能力在程序设计过程中,需要具备良好的逻辑思维能力,以便正确地分析问题、设计算法和编写代码。
通过本课程的学习,我意识到逻辑思维能力在编程中的重要性,并在实践中不断锻炼自己的思维能力。
2. 编程需要耐心和细心编程过程中,会遇到各种问题和错误。
只有具备耐心和细心,才能及时发现并解决问题。
在课程实践中,我学会了如何耐心地调试程序,细心地检查代码,确保程序的正常运行。
3. 团队合作的重要性在项目实践中,我与同学们分工合作,共同完成项目。
通过团队合作,我学会了如何与他人沟通、协调,提高了自己的团队协作能力。
4. 持续学习的重要性程序设计领域不断发展,新技术、新算法层出不穷。
为了跟上时代的步伐,我们需要持续学习,不断提高自己的编程能力。
程序设计实践信息类 1110开辟一个图书信息管理系统,图书信息包括:图书编号、书名、作者、出版社、类别、出版时间、价格等基本信息(也可以根据自己情况进行扩充,比如是否借出、库存量等)(1)图书信息录入功能(图书信息用文件保存)--输入(2)图书信息浏览功能--输出(3)查询功能(至少一种查询方式)、排序功能(至少一种排序方式):①按书名查询②按作者名查询③ 按照价钱排序④按出版时间排序等等(4)图书信息的删除与修改(1)简单的权限处理 (2)报表打印功能(3)甚至根据自己情况,可以加之学生信息,并扩充为图书借阅系统。
(4) 含糊查询 (5)综合查询 (6)统计功能比如统计处某一类别的图书信息或者筛选出小于指定数量库存的图书信息等等,总之,可以根据自己需求进行分析功能。
一、提交材料应包括: (1)系统源代码 (2)课程报告二、整个设计过程具体要求(1要求学生对案例系统进行分析,设计出需要完成的功能,完善各个模块的调用关系;(2要求学生进一步明确各模块调用关系,进一步完善模块函数细节(函数名、参数、返回值等)(3要求学生养成良好的编码习惯、完成各个模块并进行测试,最终完成系统整体测试;(4按照要求完成系统设计和实现报告,并进行总结、答辩。
1 需求分析这是一个能简单管理图书的小型图书管理系统,其中图书信息包括:书名,作者名,书编号,分类,出版单位,出版时间,价格等。
通过这些信息使之提供以下功能:(1)图书信息创建功能。
其中图书信息包括:书名,作者名,书编号,分类,出版单位,出版时间,价格等。
(图书信息用文件保存)。
(2)图书信息查看功能。
用来查看各项图书信息。
(3)图书信息查找功能。
通过已知信息来查找想要的图书。
(4)图书信息的删除。
可以删除特定图书。
(5)图书信息的修改。
可以修改图书的各项信息。
(6)图书信息的排序功能。
按图书信息对录入的图书进行排序。
(7)菜单选择功能,此功能也是图书信息信息管理系统的入口,用户所要进行的各种操作均需在此模块中进行选择并进而调用其他模块实现相应的功能2 概要设计图书管理系统中主要的数据结构包含书名、图书书号、作者名、分类、出版社、出版时间、价格等;在处理过程中各项可以作为一本图书的不同属性来进行处理。
图书管理系统流程图一、引言图书管理系统是一种用于管理图书馆馆藏图书和读者借阅信息的软件系统。
本文将通过流程图来展示图书管理系统的主要功能和流程。
二、流程图下面是一个基本的图书管理系统流程图:graph TDA[开始] --> B[登录]B --> C{是否登录成功?}C -- 是 --> D[显示主菜单]D --> E{用户选择的操作}E -- 借阅图书 --> F[验证读者信息和图书是否可借]F -- 可借阅 --> G[记录借书信息并更新库存]G --> H[显示借书成功提示]E -- 归还图书 --> I[验证读者信息和图书是否借阅]I -- 已借阅 --> J[更新借书信息和库存]J --> K[显示归还成功提示]E -- 查询图书 --> L[显示可借阅图书列表]E -- 查询借阅记录 --> M[显示读者借阅记录]E -- 退出 --> N[结束]C -- 否 --> O[显示登录失败提示]O --> BH --> EK --> E三、流程说明1.开始:系统启动时,进入初始状态。
2.登录:用户输入用户名和密码进行登录。
3.是否登录成功?:判断用户输入的用户名和密码是否正确。
–若登录成功,则进入显示主菜单步骤;–若登录失败,则返回登录步骤。
4.显示主菜单:展示用户可以选择的操作,如借阅图书、归还图书、查询图书、查询借阅记录、退出。
5.用户选择的操作:根据用户选择的操作,进行相应的处理。
–借阅图书:用户输入借阅的图书编号,系统验证读者信息和图书是否可借,若可借阅,则记录借书信息并更新库存,提示借书成功。
–归还图书:用户输入归还的图书编号,系统验证读者信息和图书是否已借阅,若已借阅,则更新借书信息和库存,提示归还成功。
–查询图书:显示可借阅的图书列表。
–查询借阅记录:显示读者的借阅记录。
–退出:结束系统运行。
数据结构课程设计说明书年月日1设计目的(小标题黑体五号字)设计一个计算机管理系统完成图书管理基本业务(数据可以存储在一个数据文件中,数据结构、具体数据自定)。
2.设计内容与要求具体功能有:1)每种书的登记内容包括书号、书名、著作者、出版单位、现存量与库存量;2)对书号建立索引表(线性表)以提高查找效率;3)采编入库:新购一种书,确定书号后,登记到图书帐目表中,如果表中已有,则只将库存量增加;4)借阅:如果一种书的现存量大于0,则借出一本,登记借阅者的书证号与归还期限,改变现存量;5)归还:注销对借阅者的登记,改变该书的现存量。
3.本设计所采用的数据结构所用数据结构:线性表、查找、排序链表:用一组地址任意的存储单元存放线性表中的数据元素。
以元素(数据元素的映象) + 指针(指示后继元素存储位置)= 结点(表示数据元素或数据元素的映象)以“结点的序列”表示线性表称作线性链表(单链表)单链表就是一种链式存取的结构,为找第 i 个数据元素必须先找到第 i-1 个数据元素。
因此,查找第 i 个数据元素的基本操作为:移动指针,比较 j 与 i。
(1)malloc(size)在内存的动态存储区申请一个长度为size字节的连续空间。
(2)calloc(n,size)在内存的动态存储区申请n个长度为size字节的连续空间,函数返回值为分配空间的首地址。
若此函数未被成功执行,函数返回值为0。
(3)free(p)释放由指针p所指向的存储单元,而存储单元的大小就是最近一次调用malloc()或calloc()函数时所申请的存储空间。
运用了单链表的插入、删除、排序、修改等一些操作!4.功能模块详细设计4、1 详细设计思想(一)基本思想:(二)图书信息录入、图书信息的查询、图书信息的排序、图书信息的修改、图书信息的删除、图书的借阅、图书的归还、退出图书管理系统。
(三)程序中的主要函数有:void main() //主函数int CreateListR(LinkList *L) //尾插法建表void LocateElem(LinkList *L) //查询int Sort(LinkList *L) //递增有序排序(直接插入排序法) void Display(LinkList *L) //输出排序结果ModifyList(LinkList *L) //修改int ListDelete(LinkList *L) //删除void Borrow(LinkList *L) //借阅void Return(LinkList *L) //归还4、2 核心代码#include <stdio、h>#include <string、h>#include<stdlib、h>#include<malloc、h>typedef struct {int num;char name[20];char author[20];char press[20];int count;char price[10];} ElemType;typedef struct LNode //定义单链表结点类型{ElemType data;struct LNode *next;} LinkList;void InitList(LinkList *L) //初始化线性表{L = (LinkList *) malloc(sizeof(LinkList)); //创建头结点L->next = NULL;}int CreateListR(LinkList *L) //尾插法建表{int i, n;LinkList *s, *q, *p;p = L;while (p->next != NULL )p = p->next;printf("请输入需要录入的图书信息的个数:n=");scanf("%d", &n);for (i = 1; i < n + 1; i++) {s = (LinkList *) malloc(sizeof(LinkList));printf("书号书名作者出版社名称存馆数量定价\n");scanf("%d%s%s%s%d%s", &s->data、num, s->data、name, s->data、author,s->data、press, &s->data、count, s->data、price);q = L->next;if (q == NULL ) {p->next = s;p = s;p->next = NULL;printf("录入成功!\n");continue;}while (q != NULL ) {if (strcmp(s->data、name, q->data、name) == 0) {printf("此图书已存在!");printf("请重新输入:\n");scanf("%d%s%s%s%d%s", &p->data、num, p->data、name,p->data、author, p->data、press, &p->data、count,p->data、price);}q = q->next;}p->next = s;p = s;p->next = NULL;printf("录入成功!\n");}return 0;}void LocateElem(LinkList *L) //查询{LinkList *p = L->next; //p指向第一个数据结点int c;int x = 0;char name1[10], author1[10], press1[10];printf(" 1 按书名查询:\n");printf(" 2 按作者名查询:\n");printf(" 3 按出版社名称:\n");printf(" 4 返回\n");printf(" 请选择1--4进行操作:\n");scanf("%d", &c);if (c > 4 || c < 1) {printf("您的输入有误!\n");scanf("%d", &c);}switch (c) {case 1:printf("请输入图书书名: \n");scanf("%s", name1);while (p != NULL ) {if (strcmp(name1, p->data、name) != 0) //查找图书书名p = p->next;else {printf("书号书名作者出版社名称存馆数量定价\n");printf("%d\t%s\t%s\t%s\t%d\t%s", p->data、num, p->data、name,p->data、author, p->data、press, p->data、count,p->data、price);printf("\n");p = p->next;x++;}}if (p == NULL && x == 0)printf("对不起,不存在此图书!\n");break;case 2:printf("请输入图书作者:\n");scanf("%s", author1);while (p != NULL ) {if (strcmp(author1, p->data、author) != 0) //查找图书作者p = p->next;else {printf("书号书名作者出版社名称存馆数量定价\n");printf("%d\t%s\t%s\t%s\t%d\t%s", p->data、num, p->data、name,p->data、author, p->data、press, p->data、count,p->data、price);printf("\n");p = p->next;x++;}}if (p == NULL && x == 0)printf("对不起,不存在此图书!\n");break;case 3:printf("请输入图书的出版社名称: \n");scanf("%s", press1);while (p != NULL ) {if (strcmp(press1, p->data、press) != 0) //查找图书出版社名称p = p->next;else {printf("书号书名作者出版社名称存馆数量定价\n");printf("%d %s %s %s %d %s",p->data、num, p->data、name, p->data、author,p->data、press, p->data、count, p->data、price);printf("\n");p = p->next;x++;}}if (p == NULL && x == 0)printf("对不起!不存在此图书\n");break;case 4:break;}}int Sort(LinkList *L) //递增有序排序(直接插入排序法){LinkList *p = L->next, *q, *r; //p指向第一个数据结点if (p != NULL ) //若原单链表中有一个或以上的数据结点{r = p->next; //r保存*p结点直接后继结点的指针p->next = NULL; //构造只含一个数据结点的有序表p = r;while (p != NULL ) {r = p->next; //r保存*p结点的直接后继结点的指针q = L;while (q->next != NULL && q->next->data、num < p->data、num) q = q->next; //在有序表中找插入*p的直接前驱结点*q的位置p->next = q->next; //将*p插入到*q之后q->next = p;p = r; //扫描原单链表余下的结点}}return 0;}void Display(LinkList *L) //输出排序结果{LinkList *p = L->next;while (p != NULL ) {printf("书号书名作者出版社名称存馆数量定价\n");printf("%d \t %s \t %s\t %s\t%d\t %s", p->data、num,p->data、name, p->data、author, p->data、press, p->data、count,p->data、price);printf("\n");p = p->next;}}int ModifyList(LinkList *L) //修改{LinkList *p = L;char name1[10];printf("请输入要修改的图书的书名:\n");scanf("%s", name1);while (p != NULL ) {if (strcmp(name1, p->data、name) == 0) //查找所要修改的书名{printf("请输入修改后的信息!\n");printf("书号书名作者出版社名称存馆数量定价\n");scanf("%d%s%s%s%d%s", &p->data、num, p->data、name, p->data、author, p->data、press, &p->data、count, p->data、price);printf("修改成功!\n");return 0;}p = p->next;}printf("不存在此图书\n");return 0;}int ListDelete(LinkList *L) //删除{LinkList *p = L->next, *q = L;char name1[10];if (p != NULL ) {printf("请输入要删除的书名:");scanf("%s", name1);}while (p->next != NULL && strcmp(p->data、name, name1) != 0) {p = p->next;q = q->next;}if (p->next != NULL ) //如果p此时不就是最后一个节点,说明此时已经找到书{q->next = p->next;printf("删除成功!\n");return 0;}if (p->next == NULL && strcmp(name1, p->data、name) != 0) //如果p此时为最后一个结点并且没有找到与之相符的书名{printf("您输入的书名不存在,请核实后重新输入!\n");} else {q->next = NULL;printf("删除成功!\n");}return 0;}void Borrow(LinkList *L) //借阅{LinkList *p = L->next;char name1[10];printf("请输入要借阅的图书的书名:\n");scanf("%s", name1);while (p->next != NULL && strcmp(name1, p->data、name) != 0) p = p->next;if (p->next == NULL && strcmp(name1, p->data、name) != 0) printf("此图书不存在!\n");else if (p->data、count < 1)printf("此书已借完!\n");else if (strcmp(name1, p->data、name) == 0) {printf("借书成功!\n");p->data、count--;}}void Return(LinkList *L) //归还{LinkList *p = L->next;char name1[10];printf("输入归还书的书名: \n");scanf("%s", name1);while (p->next != NULL && strcmp(name1, p->data、name) != 0) p = p->next;if (p->next == NULL && strcmp(name1, p->data、name) != 0)printf("错误!此图书不存在!\n");else if (strcmp(name1, p->data、name) == 0) {printf("该书归还成功!\n");p->data、count++;}}void menu() { //菜单函数printf("---------------------------------------------------------- \n");printf(" 欢迎光临图书管理系统! \n");printf("----------------------------------------------------------- \n");printf("1、图书信息录入添加功能:\n");printf("2、图书信息查询功能:\n");printf("3、图书信息排序功能:\n");printf("4、图书的修改功能:\n");printf("5、图书的删除功能:\n");printf("6、图书借阅功能:\n");printf("7、图书归还功能:\n");printf("0、退出系统:\n");printf("请选择您需要的操作:\n");}int main() //主函数{int s;LinkList *L;L = (LinkList *) malloc(sizeof(LinkList));InitList(L);menu();printf("请输入编号:\n");scanf("%d", &s);while (s != 0) {switch (s) {case 1:CreateListR(L);break;case 2:LocateElem(L);break;case 3:Sort(L);Display(L);break;case 4:ModifyList(L);break;case 5:ListDelete(L);break;case 6:Borrow(L);break;case 7:Return(L);break;case 0:printf("谢谢使用\n");break;}scanf("%d", &s);}return 0; }。
图书馆管理系统代码。
txt男人偷腥时的智商仅次于爱因斯坦。
美丽让男人停下,智慧让男人留下.任何东西都不能以健康做交换.#include<stdio.h〉#include<math。
h〉#include<string。
h>#include<stdlib.h>struct books_list{char author[20]; /*作者名*/char bookname[20]; /*书名*/char publisher[20]; /*出版单位*/char pbtime[15]; /*出版时间*/char loginnum[10]; /*登陆号*/float price; /*价格*/char classfy[10]; /*分类号*/struct books_list * next; /*链表的指针域*/};struct books_list * Create_Books_Doc(); /*新建链表*/void InsertDoc(struct books_list * head); /*插入*/void DeleteDoc(struct books_list * head , int num);/*删除*/void Print_Book_Doc(struct books_list * head);/*浏览*/void search_book(struct books_list * head); /*查询*/void info_change(struct books_list * head);/*修改*/void save(struct books_list * head);/*保存数据至文件*//*新建链表头节点*/struct books_list * Create_Books_Doc(){struct books_list * head;head=(struct books_list *)malloc(sizeof(struct books_list)); /*分配头节点空间*/head—>next=NULL; /*头节点指针域初始化,定为空*/return head;}/*保存数据至文件*/void save(struct books_list * head){struct books_list *p;FILE *fp;p=head;fp=fopen("data.txt","w+"); /*以写方式新建并打开 data。
第1篇一、项目背景随着计算机技术的飞速发展,数据结构作为计算机科学的基础,其重要性日益凸显。
为了更好地理解和掌握数据结构,提高自己的编程能力,我选择了一个数据结构项目进行实践。
本项目旨在实现一个基于链表的数据结构,包括单链表、双向链表和循环链表,并对这些链表进行操作,如插入、删除、查找等。
二、项目目标1. 理解并掌握链表的基本概念和操作。
2. 实现单链表、双向链表和循环链表的数据结构。
3. 编写相应的操作函数,包括插入、删除、查找等。
4. 通过项目实践,提高自己的编程能力和数据结构知识。
三、项目实施1. 环境搭建为了实现项目,我选择了Java作为编程语言,并使用IntelliJ IDEA作为开发工具。
首先,在IntelliJ IDEA中创建一个新的Java项目,命名为“数据结构项目”。
2. 数据结构设计(1)单链表单链表由节点组成,每个节点包含数据和指向下一个节点的指针。
为了实现单链表,定义一个Node类,包含数据域data和指针域next。
```javapublic class Node {public int data;public Node next;public Node(int data) {this.data = data;this.next = null;}}```(2)双向链表双向链表与单链表类似,但每个节点包含两个指针,分别指向前一个节点和后一个节点。
定义一个DoubleNode类,包含数据域data、前指针prev和后指针next。
```javapublic class DoubleNode {public int data;public DoubleNode prev;public DoubleNode next;public DoubleNode(int data) {this.data = data;this.prev = null;this.next = null;}}```(3)循环链表循环链表是一种特殊的链表,最后一个节点的指针指向头节点,形成一个环。
图书馆库存信息管理一、系统描述图书馆库存信息管理的基础强化训练要求学生自己设计并编制一个小型并具有一定功能的图书管理系统,该系统要求能对图书的库存信息进行一定的统计,不要求采用数据库和图形化界面,只要求在命令提示符的界面下对图书的入库、出库、修改、增加进行操作即可,对数据的存储以文件的形式存储在外存中。
二、需求分析1、功能需求(1)图书入库(一本书的各个信息,书名ISBN等)(2)图书出库(3)修改一条图书记录(4)查询图书记录2、数据物理存储结构以及逻辑存储结构(1)每本书采用一个结构体来定义其特点如struct LNode{ 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)逻辑结构采用一个单链表来对每本书进行索引,单链表的节点为书本信息的结构体,当对一个节点进行操作是,若是打印节点的信息,则从文件中首先取出信息写到内存中,然后再在命令提示符中打印出来;若是进行图书出库或者图书信息的修改,则是先写到节点中,然后在保存到文件中。
三、详细设计#include<windows.h>//获取系统日期#include<fstream>#include<iostream>#include<string>#include<sstream>//istringstream#include<cstdlib>#include<stdio.h>using namespace 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(); //增加记录void Modify(); //修改记录void Delete(); //删除记录void query(int choice_of_query,string query_keyword); //查询记录string get_date()//获取当前系统日期并转换成yyyy-mm-dd格式{string str;char s[10];SYSTEMTIME st;GetSystemTime(&st);sprintf(s,"%d",st.wYear); str= s;str+="-";sprintf(s,"%d",st.wMonth); str+=s; str+="-";sprintf(s,"%d",st.wDay);str+=s;return str;}/*类型定义*/struct LNode{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; //指向下一个图书};/*链表基本操作*/LNode * CreateDefaultLink( )//创建以默认数据建立的链表{ifstream book("Bookmanagement.txt");if(!book){cerr<<"打开文件失败!"<<endl;char * s="Bookmanagement.txt";cout<<"请重新输入完整文件路径及文件名(盘符:\\路径\\文件名.txt):"<<endl;cin>>s;book.open(s);}LNode *p1,*p2,*head=NULL;p1=p2=new LNode;p1->next =NULL;int i=0,j=1;string read,r[11]; //read用来读取每一行关键字,r[1]-r[9]依次用来保存每个结点的关键字getline(book,read);read.append(1,'\n');while(j<10){string temp;while( read[i]!= '\n'&& read[i++]!='\t'){temp.append(1,read[i-1]);//依次分离一个单词,每个单词之间用垂直制表符分割}r[j]=temp;j++;}from_string<in、t>(p1->sequenceNum, r[1], dec);p1->ISBN = r[2];p1->BookName = r[3];p1->author = r[4];p1->press = r[5];from_string<int>(p1->store_number, r[6], dec);from_string<double>(p1->price, r[7], dec);p1->date_of_in=r[8];p1->date_of_out=r[9];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(read[i]!='\n' && read[i++]!='\t'){temp.append(1,read[i-1]);//依次将一个单词}r[j]=temp;j++;}from_string<int>(p1->sequenceNum, r[1], dec);//将r[1]转换成int型,序号p1->ISBN = r[2];p1->BookName = r[3];p1->author = r[4];p1->press = r[5];from_string<int>(p1->store_number, r[6], dec);//将r[6]转换成int型,库存数from_string<double>(p1->price, r[7], dec);//将r[7]转换成double型,单价p1->date_of_in=r[8];p1->date_of_out=r[9];}return head;book.close();}void main(){system("color f1"); //改变当前控制台窗口的背景颜色为F(白色),字体颜色为1(蓝色) menu();system("pause");}/*函数实现*/void menu(){cout<<"******************************************************************** ************"<<endl;cout<<"* "<<endl;cout<<"* 图书库存管理系统"<<endl;cout<<"* 选择一个操作:*"<<endl;cout<<"* <1> 图书入库*"<<endl;cout<<"* <2> 修改一条图书记录*"<<endl;cout<<"* <3> 图书出库*"<<endl;cout<<"* <4> 查询图书记录*"<<endl;cout<<"* <5> 清屏*"<<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之间的整数:"<<endl;cin>>choice;cout<<"\n\n\n\n";}switch(choice){case 1:cout<<"\n\n\n\n";ADD();break;case 2:cout<<"\n\n\n\n";Modify();break;case 3:cout<<"\n\n\n\n";Delete();break;case 4:cout<<"\n\n\n\n";sub_menu_Query();break;case 5:system("cls");menu();break;case 6:exit(0);}}void ADD(){cout<<"请依次按照顺序输入图书的信息: ISBN编号书名作者出版社单价"<<endl;LNode *new_book=new LNode;char t[60];cin>>new_book->ISBN;cin>>new_book->BookName;cin.get();gets(t); new_book->author=t;cin>>new_book->press;cin.get();gets(t);new_book->price=atof(t);new_book->date_of_in=get_date();new_book->sequenceNum=0;//初始化图书的序号,后面再修改。
#include "stdio.h"#include "stdlib.h"#include "conio.h"#include "string.h"#include "math.h"#define LEN sizeof(struct library)#define LEN1 sizeof(struct reader)#define NULL 0struct library//图书馆构造体{int shuhao,xcl;char name[20],author[20],chuban[20];struct library *next;};struct reader//读者构造体{int zhenghao;char mingzi[20],riqi[20],zname[20];struct reader *next;};void mainmenu() //显示主菜单{ system ("cls");printf("\n");printf("\t\t\t\t####################\n\n"); printf("\t\t\t\t 1.图书馆信息\n\n");printf("\t\t\t\t 2.借阅系统\n\n");printf("\t\t\t\t 3.退出系统\n\n");printf("\t\t\t 请按键选择, 回车拟定\n"); printf("\t\t\t\t######################\n"); printf("\n");return ;}void menu1() //显示图书馆信息菜单{ system ("cls");printf("");printf("\t\t\t\t####################\n\n"); printf("\t\t\t\t 1.采编入库\n\n");printf("\t\t\t\t 2.清除库存\n\n");printf("\t\t\t\t 3.图书查询\n\n");printf("\t\t\t\t 4.库存一览\n\n");printf("\t\t\t\t 5.返回上一层\n\n");printf("\t\t\t 请按键选择, 回车拟定\n");printf("\t\t\t\t#######################\n");printf("\n");return ;}void menu2() //显示查询菜单{ system ("cls");//printf("");printf("\t\t\t\t#######################\n");printf("\t\t\t\t 1.书号查询\n\n");printf("\t\t\t\t 2.书名查询\n\n");printf("\t\t\t\t 3.作者查询\n\n");printf("\t\t\t\t 4.出版社查询\n\n");printf("\t\t\t 请按键选择, 回车拟定\n");printf("\t\t\t\t#######################\n");//printf("");return ;}void main()//主函数, 调用main1{void main1();main1();}void main1()//main1函数{void tsgxx();//声明void jieshuxitong();//声明char choose;mainmenu();scanf("%c",&choose);switch(choose)//功能函数选择{ case '1':tsgxx();break;case '2':jieshuxitong();break;case '3':system ("cls");printf("\n\n\n\n\n\n\n\n\n\t\t\t Byebye...");printf("\n\n\n\n\n\n\n\n\n\t\t\t 欢迎使用本软件!!!");getch();exit(0);system ("cls");break;}}void tsgxx()//图书馆信息函数{ void tsjinku();void shanchu();void chaxunts();void xianshikucun();//函数声明char choose;menu1();//调用菜单函数scanf("%c",&choose);scanf("%c",&choose);for (;;)switch(choose)//功能函数选择{ case '1':tsjinku();break;case '2':shanchu();break;case '3':chaxunts();break;case '4':xianshikucun();break;case '5':main1();break;}}int tjzs()//记录文本个数函数{ FILE *fp;int tshuhao=0,txcl=0,n;char tname[20]={'\0'},tauthor[20]={'\0'},tchuban[20]={'\0'};fp=fopen("library.txt","r");//打开文献for (n=0;!feof(fp);n++)//逐个读文献fscanf(fp,"%d %s %s %s %d",&tshuhao,tname,tauthor,tchuban,&txcl);n--;fclose(fp);//关闭文献return (n);//返回个数}int tjdzzs()//记录文本个数函数{ FILE *fp;int zhenghao=0,n;char mingzi[20]={'\0'},riqi[20]={'\0'},zname[20]={'\0'};fp=fopen("reader.txt","r");//打开文献for (n=0;!feof(fp);n++)//逐个读文献fscanf(fp,"%d %s %s %s ",&zhenghao,&mingzi,&riqi,&zname);fclose(fp);//关闭文献return (n);//返回个数}void tsjinku()//图书进库函数{ FILE *fp;int shuhao=0,xcl=0,n=0;char name[20]={'\0'},author[20]={'\0'},chuban[20]={'\0'};char hitkey;system ("cls");if ((fp=fopen("library.txt","r"))==NULL)//打开图书馆文献, 不存在此文献则新建{ fp=fopen("library.txt","w");fclose(fp);}fp=fopen("library.txt","a");printf("\n\n\n\n\n\n\t\t\t请按如下格式输入图书信息: \t\t\t\t\t\t 书号书名作者出版社进库量\n请输入: ");//按格式输入图书馆信息for (;hitkey!=27;)//循环输入{ if (n!=0)printf("请输入:");scanf("%d%s%s%s%d",&shuhao,name,author,chuban,&xcl);fprintf(fp,"%d %s %s %s %d\n",shuhao,name,author,chuban,xcl);printf("继续输入请按回车, 结束输入请按esc\n");n++;hitkey=getch();for (;hitkey!=13&&hitkey!=27;)hitkey=getch();}fclose(fp);printf("\n\n\n\n\n\n\t\t\t保存成功, 按任意键返回上一层!");getch();tsgxx();//返回上一层}void shanchu()//删除图书信息函数{ struct library *head=NULL;struct library *p,*p1,*p2;int tshuhao=0,txcl=0,n=0,j,i;char tname[20]={'\0'},tauthor[20]={'\0'},tchuban[20]={'\0'}, ttname[20]={'\0'};char hitkey;FILE *fp;if ((fp=fopen("library.txt","r"))==NULL)//打开文献{ system ("cls");printf("\n\n\n\n\n\n\n\n\n\t\t\t记录文献不存在!按任意键返回...");getch();tsgxx();}else{ system ("cls");printf("\n\n\n\n\n\n\n\n\t\t请输入你要删除旳书名:");//输入删除图书书名scanf("%s",&ttname);printf("\t\t确认删除请回车, 取消请按esc\n");hitkey=getch();for (;hitkey!=13&&hitkey!=27;)hitkey=getch();if (hitkey==27)tsgxx();fp=fopen("library.txt","r");for (j=0;!feof(fp);)//读文献夹信息, 记录个数{ j++;fscanf(fp,"%d%s%s%s%d",&tshuhao,tname,tauthor,tchuban,&txcl);}fclose(fp);fp=fopen("library.txt","r");for (i=1;i<j;i++){ fscanf(fp,"%d%s%s%s%d",&tshuhao,tname,tauthor,tchuban,&txcl); if (strcmp(ttname,tname))//比较名字, 将不同名字旳信息复制到链表{ n++;if (n==1)//建立链表{ p1=p2=(struct library*)malloc(LEN);head=p1;}else{ p2->next=p1;p2=p1;p1=(struct library*)malloc(LEN);//新建链表}p1->shuhao=tshuhao;//复制书号strcpy(p1->name,tname);//复制书名strcpy(p1->author,tauthor);//复制作者名子strcpy(p1->chuban,tchuban);//复制出版社p1->xcl=txcl;//复制个数}}if (n==0){ head=NULL;}else{p2->next=p1;p1->next=NULL;fclose(fp);}}fp=fopen("library.txt","w");//清空文献fclose(fp);fp=fopen("library.txt","a");//追加文献p=head;for (;p!=NULL;)//把链表内容覆盖到文献{fprintf(fp,"%d %s %s %s %d \n",p->shuhao,p->name,p->author,p->chuban,p->xcl);p=p->next;}fclose(fp);//关闭文献system ("cls");printf("\n\n\n\n\n\n\n\n\t\t 删除成功\n\t\t按任意键返回上一层\n");getch();//返回上一层tsgxx();}void chaxunts()//查询函数{FILE *fp;char choose;int ttshuhao=0,tshuhao=0,txcl=0,n=0,k=0,i,l;chartname[20]={'\0'},ttauthor[20]={'\0'},tauthor[20]={'\0'},ttchuban[20]={'\0'},tchuban[20]={'\0'}, ttname[20]={'\0'};if ((fp=fopen("library.txt","r"))==NULL)//打开文献{ system ("cls");printf("\n\n\n\n\n\n\n\n\n\t\t\t记录文献不存在!按任意键返回...");getch();tsgxx();}l=tjzs();//获得文献个数menu2();//调用菜单函数scanf("%c",&choose);scanf("%c",&choose);//选择查询方式if (choose=='5')return;else if (choose=='1')//书号查询{ system ("cls");printf("请输入书号:");scanf("%d",&ttshuhao);}elseif (choose=='2')//书名查询{ system ("cls");printf("请输入书名:");scanf("%s",ttname);}elseif (choose=='3')//作者查询{ system ("cls");printf("请输入作者:");scanf("%s",ttauthor);}elseif (choose=='4')//出版社查询{ system ("cls");printf("请输入出版社:");scanf("%s",ttchuban);}system ("cls");for (i=0;i<l;i++){ fscanf(fp,"%d%s%s%s%d",&tshuhao,tname,tauthor,tchuban,&txcl);//读文献信息if(ttshuhao==tshuhao||!strcmp(ttname,tname)||!strcmp(ttauthor,tauthor)||!strcmp(ttchuban,tch uban))//输出查询信息{if (k==0){printf("\t\t\t\t查询成果:\n\n");printf("\t 书号书名作者出版社现存量\n");}printf("\t %-4d %-8s %-8s %-8s %-4d \n",tshuhao,tname,tauthor,tchuban,txcl);k++;}}if (k==0)//文献夹为空则输出无记录{ system ("cls");printf("\n\n\n\n\n\n\n\t\t\t\t无符合记录!\n");getch();tsgxx();}fclose(fp);getch();//返回tsgxx();}void xianshikucun()//现实库存信息{FILE *fp;int shuhao=0,xcl=0,n=0,i=0,j=0;char name[20]={'\0'},author[20]={'\0'},chuban[20]={'\0'};if ((fp=fopen("library.txt","r"))==NULL)//打开文献夹{system ("cls");printf("\n\n\n\n\n\n\n\n\n\t\t\t记录文献不存在!");n= tjzs();if (n==0){ system ("cls");printf("\n\n\n\n\n\n\n\n\n\t\t\t无任何记录!");}fp=fopen("library.txt","r");system ("cls");printf("************************************************************************* *******");printf("\t 书号书名作者出版社库存量\n");printf("************************************************************************* *******");for (i=0;i<n;i++)//输出信息{fscanf(fp,"%d%s%s%s%d",&shuhao,name,author,chuban,&xcl);printf("\t %-4d %-8s %-8s %-8s %-4d \n",shuhao,name,author,chuban,xcl);}fclose(fp);printf("\t\t\t\t按任意键返回\n");getch();//返回tsgxx();}void menu3() //显示借书系统主菜单{ system ("cls");//printf("*********************************************************************** *********");printf("\t\t\t\t#######################\n");printf("\t\t\t\t 1.借书登记\n\n");printf("\t\t\t\t 2.还书登记\n\n");printf("\t\t\t\t 3.借阅状况查看\n\n");printf("\t\t\t\t 4.返回上一层\n\n");printf("\t\t\t 请按键选择, 回车拟定\n");printf("\t\t\t\t#######################\n");//printf("*********************************************************************** *********");return ;}void jieshuxitong()//借书系统函数{ void jieshu();void huanshu();void duzheyilang();//函数声明char choose;menu3();scanf("%c",&choose);scanf("%c",&choose);//选择功能for (;;)switch(choose)//调用函数{ case '1':jieshu();break;case '2':huanshu();break;case '3':duzheyilang();break;case '4':main1();break;}}void jieshu()//借书函数{FILE *fp,*fp3;struct library *head=NULL;struct library *p,*p1,*p2;int tshuhao=0,txcl=0,i,loop,zhenghao=0,n=0,k=0,t=0,flag=0;char tname[20]={'\0'},tauthor[20]={'\0'},tchuban[20]={'\0'}, ttname[20]={'\0'},mingzi[20]={'\0'},riqi[20]={'\0'},zname[20]={'\0'};char hitkey=0;system ("cls");{if ((fp=fopen("library.txt","r"))==NULL)//打开图书馆文献{system ("cls");printf("\n\n\n\n\n\n\n\n\n\t\t 图书馆无库存!按任意键退出!");getch();exit (0);}else{{printf("\n\n\n\n\n\n\t\t\t请输入借阅书名: \t\t\t\t\t\t \n请输入: ");//输入书名scanf("%s",zname);k= tjzs();//记录图书馆文献个数for (i=0;i<k;i++)//读入图书馆信息, 存储到链表{fscanf(fp,"%d%s%s%s%d",&tshuhao,tname,tauthor,tchuban,&txcl);n++;if (n==1){ p1=p2=(struct library*)malloc(LEN);head=p1;}else{ p2->next=p1;p2=p1;p1=(struct library*)malloc(LEN);//新建链表}p1->shuhao=tshuhao;//复制书号strcpy(p1->name,tname);//复制书名strcpy(p1->author,tauthor);//复制作者strcpy(p1->chuban,tchuban);//复制出版社p1->xcl=txcl;//复制现存量}if (n==0)head=NULL;else{p2->next=p1;p1->next=NULL;fclose(fp);}}}p=head;for (;p!=NULL;)//读链表{if(!(strcmp(p->name,zname)))//名字相似{flag=1;//标记取1loop=p->xcl;//现存量减1(p->xcl)--;}p=p->next;}if(flag&&(loop>0))//存在借书书名且现存量大于0{ fp=fopen("library.txt","w");fclose(fp);fp=fopen("library.txt","a");p=head;for (;p!=NULL;){fprintf(fp,"%d %s %s %s %d \n",p->shuhao,p->name,p->author,p->chuban,p->xcl);p=p->next;}free(p);//把链表内容覆盖文献fclose(fp);}if(flag&&(loop>0))//存在借书书名且现存量大于0{{if ((fp3=fopen("reader.txt","r"))==NULL)//建读者文献夹{ fp3=fopen("reader.txt","w");fclose(fp3);}fp3=fopen("reader.txt","a");}{{ if (n!=0)printf("\n\n\n\n\n\n\t\t\t请按如下格式输入读者信息: \t\t\t\t\t\t 证号姓名归还日期借书书名\n请输入: ");//录入读者信息scanf("%d %s %s %s",&zhenghao,&mingzi[20],&riqi[20],&zname[20]);fprintf(fp3,"%d %s %s %s \n",zhenghao,&mingzi[20],&riqi[20],&zname[20]);fp=fopen("library.txt","w");//删除图书馆文献信息fclose(fp);fp=fopen("library.txt","a");//重新追加信息p=head;for (;p!=NULL;)//把链表内容覆盖图书馆文献{fprintf(fp,"%d %s %s %s %d \n",p->shuhao,p->name,p->author,p->chuban,p->xcl);p=p->next;}fclose(fp);fclose(fp3);printf("成功!按任意键返回\n");getch();//返回jieshuxitong();}}jieshuxitong();}elseprintf("此书已被借完!按任意键返回!");//否则输出此书已被接完getch();//返回jieshuxitong();}}void huanshu()//还书函数{FILE *fp,*fp3;struct reader *head=NULL;struct reader *p,*p1,*p2;struct library *lhead1=NULL;struct library *zp1,*lp1,*lp2;int tshuhao=0,txcl=0,i;char tname[20]={'\0'},tauthor[20]={'\0'},tchuban[20]={'\0'}, ttname[20]={'\0'};int ttzhenghao=0,tzhenghao=0,n=0,k=0,t=0,flag=0;char tmingzi[20]={'\0'},triqi[20]={'\0'},tzname[20]={'\0'},ttzname[20]={'\0'};char hitkey=0;system ("cls");{if ((fp=fopen("reader.txt","r"))==NULL)//不存在读者文献, 则输出不能还书{system ("cls");printf("\n\n\n\n\n\n\n\n\n\t\t 不存在借书者!按任意键退出!");getch();exit (0);}else{{printf("\n\n\n\n\n\n\t\t\t请输入读者证号和书名: \t\t\t\t\t\t \n请输入: ");scanf("%d %s",&ttzhenghao,ttzname);//输入还书证号和书名k= tjdzzs();//获取读者文献夹信息个数for (i=0;i<k;i++)//读取读者文献夹信息{fscanf(fp,"%d%s%s%s\n ",&tzhenghao,tmingzi,triqi,tzname);if((ttzhenghao==tzhenghao)&&!strcmp(ttzname,tzname))//如果证号书名存在, 则标记为1flag=1;}fclose(fp);fp=fopen("reader.txt","r");//打开读者文献if(flag){for (i=0;i<k;i++)//将读者文献复制到链表{fscanf(fp,"%d%s%s%s\n ",&tzhenghao,tmingzi,triqi,tzname);//读取文献信息if(!((ttzhenghao==tzhenghao)&&!strcmp(ttzname,tzname))){ n++;if (n==1){ p1=p2=(struct reader*)malloc(LEN1);//新建链表head=p1;}else{ p2->next=p1;p2=p1;p1=(struct reader*)malloc(LEN1);//新建链表}p1->zhenghao=tzhenghao;//复制证号strcpy(p1->mingzi,tmingzi);//复制读者名字strcpy(p1->riqi,triqi);//复制日期strcpy(p1->zname,tzname);//复制书名}}if (n==0)head=NULL;else{p2->next=p1;p1->next=NULL;fclose(fp);}fp=fopen("reader.txt","w");//清空读者文献fclose(fp);fp=fopen("reader.txt","a");//追加信息p=head;for (;p!=NULL;)//把链表内容覆盖读者文献{fprintf(fp,"%d %s %s %s \n",p->zhenghao,p->mingzi,p->riqi,p->zname);p=p->next;}free(p);fclose(fp);}}}if(flag)//标记为1, 既还书时{{{printf("确认还书请按回车!");for (;hitkey!=13&&hitkey!=27;)hitkey=getch();if (hitkey==13)printf("成功!按任意键返回!");n=0;flag=0;fp3=fopen("library.txt","r");//打开图书馆文献k= tjzs();//获取图书馆文献个数for (i=0;i<k;i++)//将图书馆文献复制到链表{fscanf(fp3,"%d%s%s%s%d",&tshuhao,tname,tauthor,tchuban,&txcl);//读取信息n++;if (n==1){ lp1=lp2=(struct library*)malloc(LEN);//新建链表lhead1=lp1;}else{ lp2->next=lp1;lp2=lp1;lp1=(struct library*)malloc(LEN);//新建链表}lp1->shuhao=tshuhao;//复制书号strcpy(lp1->name,tname);//复制书名strcpy(lp1->author,tauthor);//复制作者strcpy(lp1->chuban,tchuban);//复制出版社lp1->xcl=txcl; //复制现存量}if (n==0){ lhead1=NULL;}else{lp2->next=lp1;lp1->next=NULL;fclose(fp3);}}}zp1=lhead1;for (;zp1!=NULL;)if(!(strcmp(zp1->name,ttzname)))//寻找书名相似++(zp1->xcl);//现存量加1zp1=zp1->next;}fp3=fopen("library.txt","w");//清空图书馆文献fclose(fp);fp3=fopen("library.txt","a");//追加信息zp1=lhead1;for (;zp1!=NULL;)//把链表内容覆盖图书馆文献{fprintf(fp3,"%d %s %s %s %d \n",zp1->shuhao,zp1->name,zp1->author,zp1->chuban,zp1->xcl);//录入信息zp1=zp1->next;}fclose(fp3);getch();//返回jieshuxitong();}elseprintf("不存在此信息!按任意键返回!");getch();//返回jieshuxitong();}void duzheyilang()//显示借书状况函数{FILE *fp;int zhenghao=0,xcl=0,n=0,i=0,j=0;char mingzi[20]={'\0'},riqi[20]={'\0'},zname[20]={'\0'};if ((fp=fopen("reader.txt","r"))==NULL)//打开读者文献夹{system ("cls");printf("\n\n\n\n\n\n\n\n\n\t\t\t记录文献不存在!");}n=tjdzzs();if (n==0){ system ("cls");printf("\n\n\n\n\n\n\n\n\n\t\t\t无任何记录!");}fp=fopen("reader.txt","r");system ("cls");printf("************************************************************************* *******");printf("\t 证号读者姓名还书日期书名\n");printf("************************************************************************* *******");for (i=0;i<n;i++)//输出文献信息{fscanf(fp,"%d%s%s%s\n ",&zhenghao,mingzi,riqi,zname);printf("\t %-4d %-8s %-8s %-8s \n", zhenghao,mingzi,riqi,zname);}fclose(fp);printf("\t\t\t\t按任意键返回\n");getch();//返回jieshuxitong();}。
竭诚为您提供优质文档/双击可除数据结构图书管理系统实验报告篇一:数据结构-图书管理系统实验报告数据结构课程设计报告课程名称_________题目名称学生学院专业班级学号学生姓名指导教师20XX年7月8日一、需求分析1.图书管理系统中图书管理模块包括图书类型定义:书号、现存量、总存量,出版时间为整型,定价为浮点型,书名、著者名为字符型,借阅指针、预约指针为读者类型;读者类型定义:证号为整型、姓名为字符型,另外借阅类型和预约类型组合成其中的共用体类型。
b树(2-3树)类型定义:关键字个数和关键字数组为整型、另外还有指向双亲的指针、指向子树的指针、记录单元指针;b树查找结果类型定义:节点指针、关键字序号和查找标志变量为整型。
2.演示程序以用户和计算机的对话方式进行,在计算机终端上显示“提示信息”之后,由用户在键盘上输入演示程序中规定的运算命令,相应的输入数据和运算结果显示在后面。
该演示系统,没有使用文件,全部数据放在内存存放。
四项基本业务都以书号为关键字进行的,采用了b树(2-3树)对书号建立索引,以提高效率。
3.图书管理系统实现功能:①采编入库:新书购入,将书号、书名、著者、册数、出版时间添加入图书账目中去,如果这种书在帐中已有,则只将总库存量增加,每新增一个书号则以凹入表的形式显示b树现状。
②清除库存:实现某本书的全部信息删除操作,每清除一个书号则已以凹入表的形式显示b树现状。
③图书借阅:如果书的库存量大于零时则执行出借,登记借阅者的图书证号和姓名,系统自动抓取当前借阅时间和计算归还时间。
④图书预约:如果某书库存为零,则记录预约者姓名和证号,系统自动抓取当前预约时间和取书时间。
⑤图书归还:注销借阅者信息,并改变该书的现存量。
⑥作者专区:输入作者名字,系统将查找相应作者全部著作并显示出来。
⑦图书信息:可以根据书号查阅此书基本信息、借阅信息和预约信息,亦可以查找全部图书基本信息。
二、概要设计1.抽象数据类型b树定义:ADTbTree{数据对象:D是具有相同特性的数据元素的集合。
图书管理系统c语言
本文将介绍如何使用C语言来构建基于控制台的图书管理系统。
首先,我们需要定义一些需要使用到的数据结构,用来保存图书信息,包括书名,作者,出版日期,类型,页数等关键信息。
然后,我们可以给每本书分配一个唯一的ISBN(国际标准书号)。
接着,我们应该编写两个函数,第一个函数的作用是维护图书信息,该函数可以添加新的图书,删除旧的图书;第二个函数可以实现基于ISBN的搜索。
最后,我们需要实现一个主函数,它负责管理整个系统,显示菜单以供用户选择,包括添加图书,删除图书,查询图书,显示所有图书,等等。
总而言之,在C语言中编写图书管理系统代码,无非是定义数据结构,编写功能函数和主函数,即可实现所需功能。
数据结构严蔚敏C语言版 ISBN1. 引言本文将介绍数据结构中的一个重要概念:ISBN(International Standard Book Number,国际标准书号)。
ISBN是一种用于标识图书的唯一编码方式,它可以帮助图书馆、书店和出版商等机构对图书进行管理和识别。
在本文中,我们将通过C语言编写一个简单的ISBN管理系统,以展示如何使用数据结构来处理ISBN。
我们将使用严蔚敏编著的《数据结构(C语言版)》作为参考。
2. 数据结构设计为了实现ISBN管理系统,我们需要设计适当的数据结构来存储和操作图书信息。
在这里,我们可以使用链表作为主要的数据结构。
2.1 图书信息结构体首先,我们需要定义一个用于表示图书信息的结构体。
该结构体应包含以下字段:•char title[100]:图书标题•char author[50]:图书作者•int year:出版年份•long long isbn:ISBN编码typedef struct {char title[100];char author[50];int year;long long isbn;} Book;2.2 链表节点结构体接下来,我们需要定义一个链表节点的数据结构,以便在链表中存储图书信息。
该节点应包含以下字段:•Book book:存储的图书信息•struct Node* next:指向下一个节点的指针typedef struct Node {Book book;struct Node* next;} Node;2.3 链表结构体最后,我们需要定义一个链表的数据结构,以便管理和操作链表节点。
该链表应包含以下字段:•Node* head:指向链表头节点的指针•int size:链表中节点的数量typedef struct {Node* head;int size;} LinkedList;3. ISBN管理系统实现有了上述定义的数据结构,我们可以开始实现ISBN管理系统了。
#include<stdio。
h〉#include<stdlib.h〉#include〈string。
h〉struct tushu{ /*图书结构体*/ char num[10]; /*编号*/char name[20];/*书名*/char writer[20];/*作者*/char press[20];/*出版社*/char kind[20];/*类别*/double time; /*时间*/double price;/*价格*/struct tushu *next;};struct stu /*学生结构体*/ {int snum;/*学号*/char mima[10]; /*密码*/struct stu *next;};FILE *fp; /*图书文件*/FILE *fp1; /*管理员信息文件*/ FILE *fp2; /*学生信息文件*/void menu();/*管理员主菜单(管理员进入对图书及学生信息进行管理操作)*/void xmenu();/*学生主菜单(学生进入可对图书,密码进行操作)*/void gfind(); /*管理员查询(管理员可按一定的方式查询图书)*/void xfind();/*学生查询(学生可按一定的方式查询图书)*/ void secret();/*管理员权限(管理员登陆所用,输入错误次数过多自动退出)*/void sort();/*排序(管理员可按一定的方式对图书进行排序,排序完之后可选择文件进行保存)*/void fprint(struct tushu *head);/*保存(可追加的保存,如添加可用)*/void fprint_(struct tushu *head);/*保存(可覆盖保存如修改,删除,排序后用)*/void hfprint(struct tushu *head); /*还书保存(还书成功后自动保存到文件)*/void jfprint_(struct tushu *head);/*借书保存(借书成功之后自动从图书馆删除)*/struct tushu * Input(); /*图书添加(可进行图书的添加)*/struct tushu *create(); /*从文件创建链表(从文件中读出信息,建立单链表)*/void gBrowse(struct tushu *head);/*管理员浏览(对图书进行遍历)*/void xBrowse(struct tushu *head);/*学生浏览(学生对图书进行遍历)*/void count(struct tushu *head); /*统计数量(管理员可对图书进行统计)*/void Findofname(struct tushu *head); /*按书名查找*/ void Findofwriter(struct tushu *head); /*按作者查找*/void Findofkind(struct tushu *head); /*按类别查找*/void xFindofname(struct tushu *head);/*学生按书名查找*/void xFindofwriter(struct tushu *head);/*学生按作者查找*/ void xFindofkind(struct tushu *head); /*学生按类别查找*/ void Sort_time(struct tushu * head); /*按时间排序(管理员按时间对图书进行排序,排序完之后可选择文件进行保存)*/ void Sort_price(struct tushu *head); /*按价格排序*/void Sort_num(struct tushu * head);/*按编号排序*/ void Delete(struct tushu * head,char m[15]);/*按编号删除(管理员可按编号删除图书)*/void Revise(struct tushu *head);/*修改(管理员可对图书进行修改,并选择是否保存)*/void borrow(struct tushu *head); /*借书*/void huanshu(); /*还书(学生借完书之后进行还书,若没有图书则不能借)*/void gxinxi(); /*管理员信息(有管理员的账号及密码,可进行修改)*/void xmima(struct stu *head1);/*学生密码修改(学生可对自己的密码进行修改)*/struct stu *xcreate();/*从文件创建学生信息(从文件读出学生信息,建立学生链表)*/void xsecret(struct stu *head1);/*学生权限(学生登陆所用)*/void menu() /*管理员主菜单(管理员进入对图书及学生信息进行管理操作)*/{int choice,n=0;struct tushu *head;struct stu *head1,*p;char m[15];there:printf("┏━┓━━━━━━━━━━━━━━━━━━━┏━┓\n"); printf(" ┃┃socat 图书管理系统printf(” ┃┗━━━━━━━━━━━━━━━━━━━┛┃\n"); printf(" ┃●[0]退出系统┃\n");printf(” ┃┃\n”);prin tf(” ┃●[1]帮助┃\n");printf(” ┃┃\n”);printf(” ┃●[2]浏览图书┃\n");printf(” ┃┃\n");printf(” ┃●[3]统计图书数目┃\n”);printf(" ┃┃\n”);printf(” ┃●[4]查询┃\n”);printf(” ┃printf(” ┃●[5]添加┃\n");printf(” ┃┃\n”);printf(” ┃●[6]排序┃\n");printf(” ┃┃\n");printf(" ┃●[7]修改┃\n”);printf(” ┃┃\n");printf(" ┃●[8]删除┃\n”);printf(" ┃┃\n”);printf(" ┃●[9]修改账号及密码┃\n");printf(” ┃┃\n”);printf(” ┃●[10]学生信息printf(”┗━━━━━━━━━━━━━━━━━━━━━━━┛\n");printf(” 请选择:”);fflush(stdin);head=create();scanf("%d”,&choice);if(choice==1){//help();printf(”没有内容!\n”);system("pause”);system(”cls”);menu();}else if(choice==2){system(”cls");if(head==NULL){printf(”没有图书,请先添加图书!\n”);system("pause");system("cls");menu();}gBrowse(head);}else if(choice==3){system(”cls");count(head);}else if(choice==4){system("cls");if(head==NULL){printf(”没有图书,请先添加图书!\n”);system("pause”);system(”cls”);menu();}gfind();}else if(choice==5){Input();}else if(choice==6){system("cls");if(head==NULL){printf(”没有图书,请先添加图书!\n”); system("pause”);system(”cls”);menu();}sort(head);}else if(choice==7){system("cls”);if(head==NULL){printf(”没有图书,请先添加图书!\n”);system("pause");system("cls”);menu();}Revise(head);}else if(choice==8){if(head==NULL){printf("没有图书,请先添加图书!\n");system(”pause");system(”cls");menu();}printf(" 请输入想要删除的图书编号:”);scanf(”%s",m);Delete(head,m);}else if(choice==9){gxinxi();else if(choice==10){system(”cls”);head1=xcreate();if(head1==NULL){printf("没有学生信息,请到xuesheng_list.txt添加!\n”); sys tem(”pause”);system(”cls”);menu();}for(p=head1;p!=NULL;p=p—>next){printf(”学生学号密码\n”);printf("%d %s\n",p->snum,p—>mima);}system(”pause”);system("cls”);menu();}else if(choice==0)system(”cls");printf(”\n\n\n\n”);printf(” ━━━━━━━━感谢使用图书管理系统━━━━━━━━\n\n\n”);exit(0);}else{system("cls");printf(”\n\n\n\n ━━━━输入错误,请重新输入!━━━━\n\n\n ");system("pause”);system(”cls”);n++;if(n==3){printf(” \n\n\n ━━━━━━━━你错误次数太多,自动退出!━━━━━━━━\n\n\n”);printf(" ━━━━━━━━感谢使用图书管理系统━━━━━━━━\n\n\n");system(”pause");exit(0);}goto there;}}void xmenu()/*学生主菜单(学生进入可对图书,密码进行操作)*/{struct tushu *head;struct stu *head1;int choice,n=0;there:printf(”┏━┓━━━━━━━━━━━━━━━━━━━┏━┓\n");printf(” ┃┃socat 图书借阅系统┃┃\n");printf(” ┃┗━━━━━━━━━━━━━━━━━━━┛┃\n"); printf(” ┃●[0]退出系统┃\n”);printf(” ┃printf(” ┃●[1]帮助┃\n”);printf(” ┃┃\n”);printf(” ┃●[2]浏览图书┃\n");printf(” ┃┃\n”);printf(" ┃●[3]查询┃\n”);printf(” ┃┃\n”);printf(” ┃●[4]借书┃\n");printf(” ┃┃\n”);printf(" ┃●[5]还书┃\n");printf(" ┃┃\n”);printf(” ┃●[6]修改密码printf("┗━━━━━━━━━━━━━━━━━━━━━━━┛\n”); printf(" 请选择:");fflush(stdin);head=create();scanf("%d”,&choice);if(choice==1){//xhelp();printf(”没有内容!\n");system(”pa use");system(”cls”);xmenu();}else if(choice==2){system("cls");if(head==NULL){printf(”没有图书!\n");system("pause”);xmenu();}xBrowse(head);}else if(choice==3){if(head==NULL){printf(”没有图书!\n”);system(”pause”);system(”cls”);xmenu();}xfind();}else if(choice==4){if(head==NULL){printf(”没有图书!\n");system(”pause”);xmenu();}borrow(head);}else if(choice==5){huanshu(head);}else if(choice==6){system("cls”);head1=xcreate();if(head1==NULL){printf(”学生信息被清空!!\n”);system("pause");system("cls”);xmenu();}xmima(head1); ;}else if(choice==0){system("cls");printf(”\n\n\n\n”);printf(” ━━━━━━━━感谢使用图书管理系统━━━━━━━━\n\n\n");exit(0);}else{system("cls”);printf("\n\n\n\n ━━━━输入错误,请重新输入!━━━━\n\n\n ”);system(”pause”);system(”cls”);n++;if(n==3){printf(” \n\n\n ━━━━━━━━你错误次数太多,自动退出!━━━━━━━━\n\n\n”);printf(” ━━━━━━━━感谢使用图书管理系统━━━━━━━━\n\n\n”);system("pause”);exit(0);}goto there;}}void gfind()/*管理员查询(管理员可按一定的方式查询图书)*/{int choice,n=0;struct tushu *head;there:system(”cls”);printf(” ┏━┓━━━━━━━━━━━━━━━━━━━┏━┓\n”);printf(” ┃┃socat 图书借阅系统┃┃\n”);printf(” ┃┗━━━━━━━━━━━━━━━━━━━┛┃\n");printf(" ┃●[0]返回┃\n");printf(" ┃┃\n”);printf(" ┃●[1]按书名查找┃\n”);printf(" ┃┃\n”);printf(" ┃●[2]按作者查找┃\n”);printf(” ┃┃\n”);printf(" ┃●[3]按类别查找┃\n”);printf(" ┃┃\n”);printf(" ┃● ┃\n”);printf(”┗━━━━━━━━━━━━━━━━━━━━━━━┛\n”);printf(" 请选择:”);fflush(stdin);head=create();scanf(”%d”,&choice);if(choice==1){system(”cls");Findofname(head); }else if(choice==2){system(”cls”); Findofwriter(head); }else if(choice==3){system(”cls");Findofkind(head); }else if(choice==0){system(”cls”);menu();}else{system(”cls”);printf(”\n\n\n\n ━━━━输入错误,请重新输入!━━━━\n\n\n ”);system("pause");system(”cls");n++;if(n==3){printf(" \n\n\n ━━━━━━━━你错误次数太多,自动退出! ━━━━━━━━\n\n\n”);printf(" ━━━━━━━━感谢使用图书管理系统━━━━━━━━\n\n\n”);system(”pause”);exit(0);}goto there;}}void xfind()/*学生查询(学生可按一定的方式查询图书)*/ {struct tushu *head;int choice,n=0;there:system("cls”);printf(” ┏━┓━━━━━━━━━━━━━━━━━━━┏━┓\n”);printf(” ┃┃socat 图书借阅系统┃┃\n”);printf(” ┃┗━━━━━━━━━━━━━━━━━━━┛┃\n");printf(” ┃●[0]返回┃\n”);printf(” ┃┃\n");printf(" ┃●[1]按书名查找┃\n”);printf(” ┃┃\n”);printf(" ┃●[2]按作者查找┃\n”);printf(" ┃┃\n");printf(” ┃●[3]按类别查找┃\n");printf(” ┃┃\n”);printf(" ┃● ┃\n");printf(”┗━━━━━━━━━━━━━━━━━━━━━━━┛\n"); printf(” 请选择:");fflush(stdin);head=create();scanf(”%d",&choice);if(choice==1){system(”cls”);xFindofname(head);}else if(choice==2){system(”cls”);xFindofwriter(head);}else if(choice==3){system("cls");xFindofkind(head);}else if(choice==0){system(”cls");xmenu();}else{system("cls");printf("\n\n\n\n ━━━━输入错误,请重新输入!━━━━\n\n\n ”);system(”pause”);system(”cls");n++;if(n==3){printf(” \n\n\n ━━━━━━━━你错误次数太多,自动退出!━━━━━━━━\n\n\n”);printf(” ━━━━━━━━感谢使用图书借阅系统━━━━━━━━\n\n\n”);system("pause”);exit(0);}goto there;}}void sort(){struct tushu *head;int choice,n=0;there:system("cls”);printf(” ┏━┓━━━━━━━━━━━━━━━━━━━┏━┓\n");printf(” ┃┃socat 图书借阅系统┃┃\n");printf(" ┃┗━━━━━━━━━━━━━━━━━━━┛┃\n”);printf(" ┃●[0]返回┃\n”);printf(” ┃┃\n");printf(” ┃●[1]按时间排序┃\n”);printf(” ┃┃\n”);printf(” ┃●[2]按价格排序┃\n");printf(" ┃┃\n”);printf(” ┃●[3]按编号排序┃\n”);printf(" ┃┃\n”);printf(” ┃●┃\n”);printf(”┗━━━━━━━━━━━━━━━━━━━━━━━┛\n”);printf(" 请选择:”);fflush(stdin);head=create();scanf("%d",&choice);if(choice==1){system("cls”); Sort_time(head);}else if(choice==2){sys tem(”cls");Sort_price(head);}else if(choice==3){system(”cls”);Sort_num(head); }else if(choice==0){system("cls”); menu();}else{system(”cls");printf("\n\n\n\n ━━━━输入错误,请重新输入!━━━━\n\n\n ”);system(”pause”);system(”cls”);n++;if(n==3){printf(” \n\n\n ━━━━━━━━你错误次数太多,自动退出! ━━━━━━━━\n\n\n”);printf(” ━━━━━━━━感谢使用图书借阅系统━━━━━━━━\n\n\n”);system("pause”);exit(0);}goto there;}}struct tushu *Input(){struct tushu *p1,*p2,*head,*ptr;char num;int x,i=0;system("cls”);p1=(struct tushu *)malloc(sizeof(struct tushu));head=p1;p1-〉price=—1;while(i!=1){printf(”请输入编号,以’#’结束\n”);scanf("%s",p1—>num);if(strcmp(p1-〉num,”#")==0)i=1;while(i!=1){printf(”请依次输入书名作者出版社类别出版时间价格\n”); scanf(”%s%s%s%s%lf%lf”,p1—>name,p1—>writer,p1—〉press,p1-〉kind,&p1-〉time,&p1—〉price);p2=p1;p1=(struct tushu *)malloc(sizeof(struct tushu));p2—〉next=p1;break;}}if(p1-〉price!=-1)p2—〉next=NULL;elsehead=NULL;system("cls”);printf("\n\n\n\t\t\t图书信息输入结束!\n\n\n”);system(”pause”);system(”cls”);printf(”\n\n\n\t\t\t是否保存图书信息?(1。
实用文档 单链表:typedef struct {
char num[20]; char name[50]; float pri;
}Book; typedef struct LNode{ //线性表的单链表存储 Book book; //数据域 struct LNode *next; //指针域 }LNode,*LinkList;
void Input(LinkList &L){ //前插法创建图书链表 LinkList p; L=new LNode; L->next=NULL;//初始化单链表
ifstream inFile("book.txt"); if(!inFile){ cerr<<"Cannot open this file!"
while(!inFile.eof()){//到达文件尾部前逐行依次读取所有图书数据 p=new LNode; //生成新结点 inFile>>p->book.num>>p->book.name>>p->book.pri; p->next=L->next; //插入到表头 L->next=p;h } inFile.close(); cout<<"读取完毕!"<} void Output(LinkList &L){//输出 LinkList p; p=L->next; while(p){
cout
cout
j++; p=p->next; } if(!p||j>i){ //第i个元素不存在 cout<<"错误!"< } cout<<"第"<
cout void Max(LinkList &L){ LinkList pmax,p; pmax=L->next; p=L->next->next; while(p){ if(p->book.pri>pmax->book.pri) pmax=p; 实用文档 p=p->next; } cout void Sort(LinkList L){ cout<<"此功能还未实现,研究中"<} void Inverse(LinkList &L){ LinkList p; //待插入到链表的节点 LinkList q; p = L->next; L->next = NULL; //初始化链表 ofstream outFile("bookinverse.txt"); //每一次将p插入到L(头结点)与L->next(链表的第一个结点之间) while (p){ q = p->next; p->next = L->next; L->next = p; p = q; } p=L->next;//循环完后,p指向的是链表末尾,需要重置回首元结点,否则无法写入文件 while(p){ cout outFile void Insert(LinkList L){ Book bk; LinkList p=L; //初始化 LinkList s=new LNode; //新结点s int i; int j=0; cout<<"请输入待插入书籍的位置"< cin>>i; cout<<"请输入待插入的书籍的信息"< cout<<"书号: "< cin>>bk.num; cout<<"书名: "< cin>>bk.name; cout<<"价格: "< cin>>bk.pri; while(p&&j j++; p=p->next; } if(!p||j>i-1){ cout<<"错误!"< } s->book=bk; //将结点s的数据域置为bk s->next=p->next; //将结点s插入L中 p->next=s; //重新写入book.txt文件 ofstream outFile("book.txt"); p=L->next; while(p){ outFile //重新写入book.txt文件 ofstream outFile("book.txt"); p=L->next; while(p){ outFile 顺序表 typedef struct{ Book *book; int length;//图书表的图书记录个数 }SqList; void Input(SqList &L){ int i=0; char book_head1[10],book_head2[10],book_head3[10]; //定义文件中标题 L.book=new Book[MAXSIZE]; ifstream inFile("book.txt"); //打开文件 if(!inFile) {