本文实例为大家分享了vue + element ui实现锚点定位的具体代码,供大家参考,具体内容如下
1.录入书籍:将书籍录入图书管理系统
2.浏览书籍:查看图书管理系统里的所有书籍
3.借阅书籍:书籍存在可以借阅,库存-1,书的库存不足则无泰国电视剧丘比特的圈套法借阅
4.归还书籍:库存+1,如果该书不是图书馆里的书籍,则无法录入
5.删除书籍:以书名为基础从图书管理系统中删除该书籍
6.查找书籍:按书名查找书籍,显示书籍的基本信息
7.排序书籍:按价格将书籍排序(降序)
使用函数、指针和链表编写。
#include<stdio.h>#include<stdlib.h>#include<string.h>struct bookinfo{ char name[20]; //书名 char author[10]; //作者 char date[20]; //出版日期 float price; //价格 int num; //数量};struct node{ struct bookinfo data; struct node* next;};/*全局链表*/struct node* list = null;/*创建表头*/struct node* createhead(){ /*动态内存申请*/ struct node* headnode = (struct node*)malloc(sizeof(struct node)); headnode->next = null; return headnode;}/*创建节点*/struct node* createnode(struct bookinfo data){ struct node* newnode = (struct node*)malloc(sizeof(struct node)); newnode->data = data; newnode->next = null; return newnode;}void printlist();void display_menu();void sav百草园与三味书屋ebookfile();void inrtbook();void readbookfile();void deletebook();struct node* archbook();void sortbook();void lectkey();/*打印链表*/void printlist(struct node* headnode){ struct node* bmove = headnode->next; printf("书名\t作者\t出版日期\t价格\t库存\n"); while(bmove != null) { printf("%s\t%s\t%s\t%.1f\t%d\n",bmove->data.name,bmove->data.author,bmove->data.date,bmove->data.price,bmove->data.num); bmove = bmove->next; }}/*菜单登录界面*/void display_menu(){ char str[100]; file *fp; char *txt; fp = fopen("menu.txt","r"); txt = fgets(str,100,fp); while(txt != null) { printf("%s",str); txt = fgets(str,100,fp); } fclo(fp);}/*将信息存到文件中*/void savebookfile(const char* filename,struct node* headnode){ file* fp = fopen(filename,"w"); struct node* bmove = headnode->next; while(bmove != null) { fprintf(fp,"%s\t%s\t%s\t%.1f\t%d\n",bmove->data.name,bmove->data.author,bmove->data.date,bmove->data.price,bmove->data.num);可爱游戏名字 bmove = bmove->next; } fclo(fp);}/*录入书籍*/void inrtbook(struct node* headnode,struct bookinfo data){ struct node* newnode = createnode(data); newnode->next = headnode->next; headnode->next = newnode;}/*读取文件*/void readbookfile(const char* filename, struct node* headnode){ file* fp = fopen(filename,"r"); if(fp == null) { fp = fopen(filename,"w+"); } struct bookinfo tempinfo; while(fscanf(fp, "%s\t%s\t%s\t%.1f\t%d\n",tempinfo.name,&tempinfo.author,&tempinfo.date,&tempinfo.price,&tempinfo.num ) != eof) { inrtbook(list,tempinfo); } fclo(fp);}/*删除书籍*/void deletebook(struct node* headnode,char *bookname){ struct node* leftnode = headnode; struct node* rightnode = headnode->next; while(rightnode != null && strcmp(rightnode->data.name,bookname)) { leftnode = rightnode; rightnode = leftnode->next; } if(leftnode == null) { return; } el { printf("删除书籍成功!\n"); leftnode->next = rightnode->next; free(rightnode); rightnode = null; }}/*查找书籍*/struct node* archbook(struct node* headnode, char* bookname){ struct node* rightnode = headnode->next; while (rightnode != null && strcmp(rightnode->data.name, bookname)) { rightnode = rightnode->next; } return rightnode;}/*排序书籍*/void sortbook(struct node* headnode){ for(struct node* i = headnode->next; i != null; i = i->next) { for(struct node* j = headnode->next;j->next != null;j = j->next) { /*排序书籍(按价格降序)*/ if (j->data.price < j->next->data.price) { /*交换值*/ struct bookinfo tempdata = j->data; j->data = j->next->data; j->next->data = tempdata; } } } /*排序后查看效果*/ printlist(headnode);}/*交互界面*/void lectkey(){ int urkey = 0; struct bookinfo tempbo浩如烟海的意思ok; //生成一个临时的变量存储书籍信息 struct node* archname = null; //生成一个临时变量存储查找的书名 struct node* borrowbook = null; //生成一个临时变量存储要借阅的书名 struct node* returnbook = null; //生成一个临时变量存储要归还的书名 scanf("%d",&urkey); switch(urkey) { ca 1: printf("[ 录入书籍 ]\n"); printf("输入书籍的信息(name,author,date,price,num):"); scanf("%s%s%s%f%d",tempbook.name,&tempbook.author,&tempbook.date,&tempbook.price,&tempbook.num); inrtbook(list,tempbook); /*把书籍信息保存到booksinfo文本文件里*/ savebookfile("bookinfo.txt",list); break; ca 2: printf("[ 浏览书籍 ]\n"); printlist(list); break; ca 3: printf("[ 借阅书籍 ]\n"); /*书籍存在可以借阅,库存-1,书的库存不足则无法借阅*/ printf("请输入要借阅的书名:"); scanf("%s",tempbook.name); borrowbook = archbook(list,tempbook.name); if(borrowbook == null) { printf("不存在该书,无法借阅!\n"); } el { if(borrowbook->data.num > 0) { borrowbook->data.num--; printf("借阅成功!\n"); printlist(list); } el { printf("当前书籍库存不足,借阅失败!\n"); } } break; ca 4: printf("[ 归还书籍 ]\n"); //库存+1 printf("请输入要归还的书名:"); scanf("%s",tempbook.name); returnbook = archbook(list,tempbook.name); if(returnbook == null) { printf("该书不是图书馆里的书籍!\n"); } el { returnbook->data.num++; printf("书籍归还成功!\n"); printlist(list); } break; ca 5: printf("[ 删除书籍 ]\n"); printf("请输入要删除的书名:"); scanf("%s",tempbook.name); deletebook(list,tempbook.name); /*按书名删除书籍*/ printlist(list); break; ca 6: printf("[ 查找书籍 ]\n"); printf("请输入要查询的书名:"); scanf("%s",tempbook.name); archname = archbook(list,tempbook.name); if(archname == null) { printf("不存在该书,请加购录入!\n"); } el { /*输出该书的信息*/ printf("书名\t作者\t出版日期\t价格\t库存\n"); printf("%s\t%s\t%s\t%.1f\t%d\n",archna宋江的特点me->data.name,archname->data.author,archname->data.date,archname->data.price,archname->data.num); } break; ca 7: printf("[ 排序书籍 ]\n"); /*按价格排序(降序)*/ sortbook(list); break; ca 8: printf("[ 退出系统 ]\n"); printf("退出成功\n"); system("pau"); exit(0); /*关闭整个程序*/ break; default: printf("[ 错误 ]\n"); break; }}/*主界面*/int main(){ list = createhead(); readbookfile("bookinfo.txt",list); while(1) { display_menu(); lectkey(); system("pau"); system("cls"); } system("pau"); return 0;}
1.录入书籍
2.浏览书籍
3.借阅书籍
存在该书时,借阅成功,库存-1:
不存在该书时,无法借阅:
4.归还书籍
当图书管理系统里本不存在该书,则归还失败:
5.查找书籍
不存在该书时,则查找失败:
6.排序书籍
再录入书籍:
排序(降序):
7.删除书籍
以上为该程序的所有功能。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持www.887551.com。
本文发布于:2023-04-06 03:07:02,感谢您对本站的认可!
本文链接:https://www.wtabcd.cn/fanwen/zuowen/460c312a38c948a513379e1b3f50dfbc.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文word下载地址:C++使用链表实现图书管理系统.doc
本文 PDF 下载地址:C++使用链表实现图书管理系统.pdf
留言与评论(共有 0 条评论) |