资源预览内容
第1页 / 共29页
第2页 / 共29页
第3页 / 共29页
第4页 / 共29页
第5页 / 共29页
第6页 / 共29页
第7页 / 共29页
第8页 / 共29页
第9页 / 共29页
第10页 / 共29页
亲,该文档总共29页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
程序设计说明书(图书销售管理系统)图书销售系统:程序代码#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 *bklist,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); /排除了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号 价格 库存 销售量 是否促销 书名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-price),&(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-sale; 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(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 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 flag=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;
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号