目录

  • 一、功能描述
  • 二、设计要求
  • 三、实现的功能
  • 四、代码

一、功能描述

设计一个图书管理程序满足图书馆基本业务需求。


二、设计要求

  1. 每种书的登记内容包括书号、书名、著作者、现存量和库存量等;
  2. 对书号建立索引表(线性表)以提高查找效率;
  3. 实现图书管理系统的主要功能描述。
  4. 用数据文件存储。

三、实现的功能

对图书信息进行增、删、改、差查询所有
运行结果大概就是这个样子:


四、代码

Tip:主要运用的是链表和文件的读写,注释很详细。

#include<stdio.h>
#include<stdlib.h>
#include "book.h"
#define len 20
#define size 20/*1、建立一个链表2、将.dat文件中读出的数据放入链表中3、进行业务操作4、业务操作后将链表中数据存回.dat文件中*///定义一个图书类型
struct oneBook
{char isbn[size];char bookname[size];char author[size];int stocknum;float price;int flag;
}bookarr[len];//定义链表
typedef struct Book
{char isbn[size];char bookname[size];char author[size];int stocknum;float price;int flag;struct Book* next;
} ListBook;//定义一个输入字符,判断使用者需要的功能
char inNeed;//编写程序首页方法
void indexPage() {//首先写出程序的首页面printf("|***********************************************************|\n");printf("|---------welcome to the Library Management System----------|\n");printf("|-------------------添加图书信息请输入1---------------------|\n");printf("|-------------------删除图书信息请输入2---------------------|\n");printf("|-------------------修改图书信息请输入3---------------------|\n");printf("|-------------------查询图书信息请输入4---------------------|\n");printf("|-------------------查询书目信息请输入5---------------------|\n");printf("|-----------------退出图书管理系统请输入6-------------------|\n");printf("|***********************************************************|\n");printf("请输入要进行的操作:");
}//编写读取文件内容的方法  ,每次用程序之前将数据从文件中读取,放入链表中
ListBook* readFile(ListBook *head) {//定义一个指向文件的指针FILE* fp;char content;ListBook* temp,*book;//这里的r是只读的意思if ((fp = fopen("file1.dat", "r")) == NULL) {//打开文件失败printf("cannot open this file\n");exit(0);}//将文件中数据拿出来,方进书的结构体数组中for (int i = 0; i < len; i++) {fread(&bookarr[i], sizeof(struct oneBook), 1, fp);//加一个判断跳出循环if (bookarr[i].flag == 0) {break;}//把结构体数据方进链表,success,用的是头插法if (head == NULL) {book = (ListBook*)malloc(sizeof(ListBook));//字符串赋值给字符数组用strncpystrncpy(book->isbn, bookarr[i].isbn, size);strncpy(book->bookname, bookarr[i].bookname, size);strncpy(book->author, bookarr[i].author, size);book->stocknum = bookarr[i].stocknum;book->price = bookarr[i].price;book->flag = bookarr[i].flag;head = book;;head->next = NULL;}else {temp = head;book = (ListBook*)malloc(sizeof(ListBook));strncpy(book->isbn, bookarr[i].isbn, size);strncpy(book->bookname, bookarr[i].bookname, size);strncpy(book->author, bookarr[i].author, size);book->stocknum = bookarr[i].stocknum;book->price = bookarr[i].price;book->flag = bookarr[i].flag;head = book;head->next = temp;}}//关闭文件输入流fclose(fp);return head;}//编写   添加图书信息方法
ListBook* insertMessage(ListBook* head) {printf("输入想要录入的图书信息,并以#结束:\n");printf("    *录入的模板为:ISBN码 书名 著作者 库存量 金额\n");ListBook* book,*temp;//把添加的数据放入链表,用的是头插法for (int i = 0; i < len; i++) {if (head == NULL) {book = (ListBook*)malloc(sizeof(ListBook));scanf("%s %s %s %d %f", &book->isbn, &book->bookname, &book->author, &book->stocknum, &book->price);book->flag = 1;head = book;;head->next = NULL;if (getchar() == '#') {break;}}else {temp = head;book = (ListBook*)malloc(sizeof(ListBook));scanf("%s %s %s %d %f", &book->isbn, &book->bookname, &book->author, &book->stocknum, &book->price);book->flag = 1;head = book;head->next = temp;if (getchar() == '#') {break;}}}//打印链表,没啥用printf("这是刚刚添加的数据\n");temp = head;while (temp != NULL) {printf("isbn:%s\t", temp->isbn);printf("bookname:%s\t", temp->bookname);printf("author:%s\t", temp->author);printf("stocknum:%d\t", temp->stocknum);printf("price:%.2f\t", temp->price);printf("flag:%d\n", temp->flag);temp = temp->next;}printf("\n添加成功!\n");return head;
}//编写储存数据方法,   每次程序使用结束,将数据存入文件中
void saveFile(ListBook *book) {//先将链表中数据放回结构体数组,成功int i = 0;while (book != NULL) {strncpy(bookarr[i].isbn, book->isbn, size);strncpy(bookarr[i].bookname, book->bookname, size);strncpy(bookarr[i].author, book->author, size);bookarr[i].stocknum = book->stocknum;bookarr[i].price = book->price;bookarr[i].flag = book->flag;book = book->next;i++;}//重新写入文件FILE* fp;if ((fp = fopen("file1.dat", "wb")) == NULL) {printf("cannot open file\n");return;}for (int j = 0; j < i; j++) {if (fwrite(&bookarr[j], sizeof(struct oneBook), 1, fp) != 1) {printf("file write error\n");}}fclose(fp); printf("~程序已退出,欢迎下次使用~");return;
}//编写查询所有图书信息的方法
void selectAll(ListBook* book) {ListBook* print;print = book;while (print != NULL) {printf("isbn:%s\t", print->isbn);printf("bookname:%s\t", print->bookname);printf("author:%s\t", print->author);printf("stocknum:%d\t", print->stocknum);printf("price:%.2f\n", print->price);print = print->next;}
}//编写删除图书信息方法
ListBook* deleteMessage(ListBook* head,char isbn[size]) {ListBook* temp, * pre,*book;book = temp = head;pre = head->next;while (head != NULL) {//在头上if (0 == strcmp(head->isbn, isbn)) {head = head->next;book = head;free(temp);printf("删除成功\n");break;}//如果链表中只有一个值,但是不是要找的值,pre指针的strcmp会空指针if (head->next == NULL) {printf("没有isbn码为%s的图书\n", isbn);break;}//不在头上if (0 == strcmp(pre->isbn, isbn)) {temp = pre;head->next = pre->next;free(temp);printf("删除成功\n");break;}pre = pre->next;head = head->next;if (head == NULL || pre == NULL) {printf("没有isbn码为%s的图书\n", isbn);}}return book;
}//编写修改图书信息的方法
ListBook* updataMessage(ListBook* head,char isbn[size]) {ListBook* temp;temp = head;//首先把要修改的图书找出来while (head != NULL) {if (0 == strcmp(head->isbn, isbn)) {printf("请输入要修改的值:");scanf("%s %s %s %d %f", &head->isbn, &head->bookname, &head->author, &head->stocknum, &head->price);printf("修改成功");break;}head = head->next;if (head == NULL) {printf("没有isbn码为:%s的图书\n", isbn);}}return temp;
}//编写查询图书信息方法
void selectOne(ListBook* head,char isbn[size]) {ListBook* temp;temp = head;while (temp != NULL) {//printf("打印:%s\n", temp->isbn);if (0 == strcmp(temp->isbn, isbn)) {printf("查询结果为:\n");printf("isbn:%s\t", temp->isbn);printf("bookname:%s\t", temp->bookname);printf("author:%s\t", temp->author);printf("stocknum:%d\t", temp->stocknum);printf("price:%.2f\n", temp->price);break;}temp = temp->next;if (temp == NULL) {printf("没有isbn码为:%s的图书\n", isbn);}}}void main() {//定义一个链表ListBook* head=NULL;//调用程序首页方法indexPage();//调用读取文件内容的方法head = readFile(head);inNeed = getchar();//编写一个大循环,使程序一直跑下去while (inNeed!='6') {if (inNeed == '1') {head = insertMessage(head);//输入下一步操作printf("请输入下一步操作:\n");//用来接收最后输入的回车符inNeed = getchar();//接收下一步操作的信号inNeed = getchar();}else if (inNeed == '2') {printf("请输入要删除图书的ISBN码:\n");//调用删除方法,需要输入要删除图书的isbnchar isbn[size];scanf("%s", isbn);head = deleteMessage(head,isbn);//输入下一步操作printf("请输入下一步操作:\n");//用来接收最后输入的回车符inNeed = getchar();//接收下一步操作的信号inNeed = getchar();}else if (inNeed == '3') {printf("请输入要修改的图书的ISBN码:\n");//调用删除方法,需要输入要删除图书的isbnchar isbn[size];scanf("%s", isbn);head = updataMessage(head, isbn);//输入下一步操作printf("请输入下一步操作:\n");//用来接收最后输入的回车符inNeed = getchar();//接收下一步操作的信号inNeed = getchar();}else if (inNeed == '4') {printf("请输入要查询的图书的ISBN码:\n");//调用删除方法,需要输入要删除图书的isbnchar isbn[size];scanf("%s", isbn);selectOne(head, isbn);//输入下一步操作printf("请输入下一步操作:\n");//用来接收最后输入的回车符inNeed = getchar();//接收下一步操作的信号inNeed = getchar();}else if(inNeed == '5'){printf("查询书目信息\n");//编写查询书目方法selectAll(head);//输入下一步操作printf("请输入下一步操作:\n");//用来接收最后输入的回车符inNeed = getchar();//接收下一步操作的信号inNeed = getchar();}}//调用存数据方法,结束程序 saveFile(head);return;
}

不知道是因为我自己的电脑还是vs什么的原因,第一次运行特别慢 卡,但是运行成功之后,下次运行就飞快。希望对做这个课设的小伙伴有帮助吧。
欢迎指导纠错~

数据结构课程设计图书管理系统,C语言版。相关推荐

  1. 数据结构课程设计—同学录管理系统(c语言)

    数据结构课程设计-同学录管理系统(c语言) 文章目录 前言 一.需求分析 二.总体设计 三.代码实现 四.代码说明 前言 计算机相关专业在学习数据结构这门课程时会有课程设计,我被分配到的是同学录管理系 ...

  2. 汽车销售管理系统 c语言版 课程设计,汽车销售管理系统c语言版.docx

    Document serial number[NL89WT-NY98YT-NC8CB-NNUUT-NUT108] Document serial number[NL89WT-NY98YT-NC8CB- ...

  3. 课程设计图书管理系统c语言,图书管理系统c语言课程设计c语言课程设计作业获得95分全院第一......

    > 下载中心  >   > 图书管理系统 c语言课程设计 english version 图书管理系统 c语言课程设计 所属分类: 开发工具:c/c++ 文件大小:2720kb 下载 ...

  4. 汽车销售管理系统 c语言版 课程设计,汽车销售管理系统C语言版.doc

    实用文档 文案大全 西安郵電大學 C语言课程设计报告 题 目:汽车销售管理系统 院系名称: 专业名称: 班 级: 学生姓名: 学号(8位): 指导教师: 设计起止时间: 设计目的 1. 对c语言基本知 ...

  5. 数据结构课程设计--图书管理系统

    //主函数模块#include "library.h" int main() {FILE *fp_book,*fp_reader; /*创建文件型指针*/Denglu();if(( ...

  6. python通讯录管理系统设计_数据结构课程设计-通讯录管理系统(C语言版)

    ##数据结构课程设计-通讯录管理系统 一,前言 自从上次C语言课设写完后,这次数据结构课设就写的游刃有余了,很快啊,不足三天就写完了它(年轻人不讲武德),如果你认真看过我之前写的C语言课程设计-球队管 ...

  7. c语言课程设计图书管理系统

    数据结构c语言课程设计 图书管理系统 我做的是百度文库的第28题,目前没有报错,正常运行,但是还有一点小bug.代码很多地方写的不是很好,请多多包涵. 账号1,密码1,为管理员账号:其他账号2,3,4 ...

  8. C语言课程设计-图书管理系统

    实训项目名称:图书管理系统的设计与实现 1.实训目的 开发一个小型的图书管理应用软件,使用该软件可以实现图书信息的登记.浏览.借书.还书.删除和更新等操作.通过该系统的实现可以了解C++连接数据库的原 ...

  9. RFID课程设计-图书管理系统用户端设计

    RFID课程设计-图书管理系统用户端设计课程设计题目课程设计任务内容题目设计基本原理NFC开发概述标签调度系统如何将 NFC 标签映射到 MIME 类型和 URI如何将 NFC 标签分发到应用在 An ...

最新文章

  1. python基础07_tuple_dict
  2. SqlHelper数据库操作辅助类
  3. c语言float m1 m2什么意思,m1和m2的区别,一文带你秒懂这两者的关联
  4. Linux open函数使用方法记录
  5. 会话管理 轻量php框架_SpringSecurity+JWT权限管理训练营-1基于RBAC模型的权限管理系统...
  6. CSS从大图中抠取小图完整教程(background-position应用)【转】
  7. 【Flutter】IOS打包
  8. Javascript学习1 - Javascript中的类型对象
  9. PHP+node搞一下58微聊的聊天内容的获取
  10. html如何在表单里加虚线,大佬,表格下方的虚线怎么添加?
  11. 如何成为一名程序员?
  12. 315晚会给我们的几点启示
  13. 至简设计系列_按键控制数字时钟
  14. 云和恩墨大讲堂-Thinking in SQL,这是一次烧脑的课程
  15. php xmp,xmp可以一直开着吗
  16. 干货!如何在训练中自动识别数据中潜在的不同分布并自适应?——以空间数据为例,应用不限于空间数据...
  17. python爬取旅游信息_用Python爬取分析全国旅游数据-Go语言中文社区
  18. “操作必须使用一个可更新的查询”故障解决
  19. Python scrapy环境搭建
  20. 基于三维GIS的集中供热平台的三维数字化

热门文章

  1. 让你的 Drupal 7 支持多字节 UTF-8
  2. revit的常用插件出图有哪些?怎么快速局部平面?
  3. 论准备的重要性——常德两天调研生活
  4. 附珍藏模板 | Python 中还可以学到 PPT?
  5. C语言中判断语句if
  6. 4月4日网站变灰色的效果是怎么实现的?
  7. 鼠标光标变成了黑色方块
  8. HTTP请求报文和响应报文
  9. 【社区图书馆】如何唤醒数学脑
  10. 机械图样解读——柱面和锥面