程序设计大作业代码及说明书-图书销售管理系统

上传人:简****9 文档编号:97055261 上传时间:2019-09-01 格式:DOC 页数:29 大小:46.40KB
返回 下载 相关 举报
程序设计大作业代码及说明书-图书销售管理系统_第1页
第1页 / 共29页
程序设计大作业代码及说明书-图书销售管理系统_第2页
第2页 / 共29页
程序设计大作业代码及说明书-图书销售管理系统_第3页
第3页 / 共29页
程序设计大作业代码及说明书-图书销售管理系统_第4页
第4页 / 共29页
程序设计大作业代码及说明书-图书销售管理系统_第5页
第5页 / 共29页
点击查看更多>>
资源描述

《程序设计大作业代码及说明书-图书销售管理系统》由会员分享,可在线阅读,更多相关《程序设计大作业代码及说明书-图书销售管理系统(29页珍藏版)》请在金锄头文库上搜索。

1、程序设计说明书(图书销售管理系统)图书销售系统:程序代码#include stdio.h#include stdlib.h#includestring.hstruct bookchar ISBN50; /ISBN号char name50; /图书名称float price; /价格int store0; /最初书店中的库存int store; /当前存货量int sale; /销售量char discount; /是否促销struct book *next; /单链表中指向下一结构体首地址的指针;int n; /图书数量,需要在录入时从文件第一行读取static struct book *bk

2、list,bk100; /图书单链表的首地址,和图书数组int judge(char a) / 要考虑到输入非数字的的影响,若输入的是正确的非负整数则返回该数,否则返回-1。在main函数中,将输入内容转化为字符串 int i,b,trns;if(a0=0&a1!=0) printf(请输入正整数或0。); return -1; /1:排出输入内容中第一个字符为0,之后还有别的内容的情况for (i=0;ai!=0;i+) b=ai; if (b57) printf(请输入正整数或0。nn); return -1; /2:若含数字外的字符,则返回-1,说明用户输入有误 trns=atoi(a)

3、; /排除了1、2的情况后,将字符串转化为整型数,将该整型数返回return trns;void show(struct book *k) /用于显示图书的相关信息 fprintf(stdout,%-25s%-10.2f%-5d%-10d%-5c%-30snn,k-ISBN,k-price,k-store,k-sale,k-discount,k-name);void ordershow(const char order) /用于提示用户当前所在的命令操作界面printf(nn-%s-nnn,order);void column(void) /用于显示图书信息表格的表头 printf( ISBN

4、号 价格 库存 销售量 是否促销 书名n);struct book *create(FILE *p)struct book *mylist,*tempnode,*cursor;int i;mylist=(struct book *)malloc(sizeof(struct book);if (mylist=NULL)printf(error1);exit(1);mylist-next=NULL;cursor=mylist;fscanf(p,%d,&n);for(i=0;inext=NULL; fscanf(p,%s %f %d %d %c,tempnode-ISBN,&(tempnode-pr

5、ice),&(tempnode-store0),&(tempnode-store),&(tempnode-discount); fgets(tempnode-name,30,p); tempnode-sale=tempnode-store0-tempnode-store; strcpy(bki.ISBN,tempnode-ISBN);strcpy(bki.name,tempnode-name); bki.price=tempnode-price; bki.store0=tempnode-store0;bki.store=tempnode-store; bki.sale=tempnode-sal

6、e; bki.discount=tempnode-discount; /内容录入数组,数组是全局的,无需返回 cursor-next=tempnode; cursor=tempnode; /创建单链表,对数据进行录入,同时录入数组cursor=NULL;tempnode=NULL;return mylist; /返回单链表首地址void freellist(struct book *head) struct book *ptr; while (head!=NULL) / 遍历链表 ptr=head; head = head-next; / 指向下一节点 ptr-next=NULL; free(

7、ptr); / 释放结构体 int search(char *l) struct book *booksearch; for(booksearch=bklist-next;booksearch!=NULL;booksearch=booksearch-next) if(strcmp(l,booksearch-ISBN)=0) column();show(booksearch);booksearch=NULL; return 0; printf(抱歉,没有找到相应的图书。nn); booksearch=NULL; return 1; /利用单链表进行ISBN查找void keyword(char

8、a)int i,j,k;int length,lengthi,flag=0,flag1=0,temp,temp0; length=strlen(a); /关键词的长度 flag=0;flag1=0;column(); for(i=0;in;i+) lengthi=strlen(bki.name);for(j=0;j+lengthlengthi;j+) for(k=0;klength;k+) temp=ak;temp0=bki.namej+k; flag+=(temp0-temp)*(temp0-temp); if(flag=0) flag1+;show(&bki);break; else fl

9、ag=0; if(flag1=0)printf(抱歉,没有找到相应的图书。nn); /关键词查找:查找结果为书名中包含查找内容(作为整体)的相应书籍的全部内容void bubblesort(void) int i; struct book *a,*b,*c; ordershow(销量由高到低排序); for(i=0;inext-next!=NULL;a=a-next) b=a-next;c=b-next-next; if (b-salenext-sale) a-next=b-next; a-next-next=b; b-next=c; column();for(c=bklist-next;c!=NULL;c=c-next) show(c); c=NULL;b=NULL;a=NULL; /用单链表进行冒泡排序,打印出按照销量由高到低的排行榜void selectsort(struct book a)int i,j,min;struct book *pb50,*tempb;ordershow(价格由低到高排行);for (i=0;in;i+) pbi=&ai;

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 商业/管理/HR > 管理学资料

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号