C语言程序专业课程设计商品进销存管理程序.doc
一 题目及运行说明商品进销存管理程序 1、题目描述设计一个商品进销管理程序,该程序含有以下功效:(1) 录入商品信息;(2) 给定商品编号,修改该商品信息;(3) 给定商品编号,删除该商品信息;(4) 录入商品进货和销售信息;(5) 给定商品编号或商品名,查看该商品及库存信息;(6) 统计功效:提供部分统计各类信息功效。2、题目要求(1) 根据分析、设计、编码、调试和测试过程完成应用程序;(2) 学习并使用步骤图等工具,并在撰写汇报中使用;(3) 程序各项功效在程序运行时,以菜单形式选择并实施;(4) 要求用户输入数据时,要给出清楚、明确提醒,包含:输入数据内容、格式及其结束方法等(5) 全部信息存放在一个文件或多个中,并实现文件读写操作。(6) 程序中用链表存放商品及进销存信息并实现增删减功效。3、提醒(1) 提醒事件信息能够设计一个结构体类型(2) 自己构思并增加除要求功效之外新功效,酌情加分。(1) 程序中关键变量Struct goods *head 结构体指针Int n,k struct goodsint number;char name20;int shumu;float jiage;struct goods *next;int n,k;struct goods *head;等部分变量。(2) 数据输入形式和输入值范围字符不超出20位整型变量输入大于0浮点型 变量也大于0商品编号为四位整数(3) 数据输入形式按程序运行提醒操作(4) 程序所能达成功效及犯错处理该程序含有以下功效:(1) 录入商品信息;(2) 给定商品编号,修改该商品信息;(3) 给定商品编号,删除该商品信息;(4) 录入商品进货和销售信息;(5) 给定商品编号或商品名,查看该商品及库存信息;(6) 统计功效:提供部分统计各类信息功效。二 程序设计思绪依据要求首先设计一个结构体类型,设计好界面,设计好主函数。程序各功效经过调用子函数来实现用switch来实现菜单选择一切数据信息通通存在文件中,并实现文件读写操作。设计子函数来实现查询,保留,读取数据,删除等操作。 【总体设计】商品管理系统数据录入数据修改删除商品销售查找进货图1 系统功效模块图 【具体设计】1. 主函数主函数设计要求简练,只提供部分提醒语和函数调用【程序】 显示一系列功效选项输入k,判定k是否是06?依据k值调用各功效模块函数结束开始k 图2. 主函数步骤图具体设计以下:结构体设计struct goodsint number;char name20;int shumu;float jiage;struct goods *next;主函数设计void main() void jieman(); void luru(); struct goods *shuju(); void shanchu(struct goods *head); void jinghuo(struct goods *head); void xiaoshu(struct goods *head); void xiugai(struct goods *head); void chaxun(struct goods *head); struct goods *head=NULL; int k=0; system("cls"); jieman(); printf("请选择你要功效键:"); scanf("%d",&k);getchar(); while(k!=0) head=shuju(); switch(k) case 1:luru();break; case 2:xiugai(head);break; case 3:chaxun(head);break; case 4:xiaoshu(head);break; case 5:jinghuo(head);break; case 6:shanchu(head);break; case 0:exit(0); default:printf("please try again!n"); jieman(); printf("请选择你要功效键:"); scanf("%d",&k); 界面设计void jieman() printf("*n"); printf("欢迎进入商品管理系统n"); printf("*1 *录入信息*n"); printf("*2 *修改信息*n"); printf("*3 *查询信息*n"); printf("*4 *销售信息*n"); printf("*5 *进货信息*n"); printf("*6 *删除信息*n"); printf("*0 *退出系统*n"); printf("欢迎进入商品管理系统n"); printf("*n");文件保留函数设计struct goods *baocun(struct goods *head) struct goods *shuju(); struct goods *p=NULL; FILE *fp=NULL; char ch='0' getchar(); printf("是否保留到文件?(y/n):"); ch=getchar(); putchar(10); if(ch='y'|ch='Y') fp=fopen("goods.txt","wb"); p=head; if(fp=NULL)&&(p=NULL) printf("读取数据失败!"); exit(0); while(p!=NULL) fprintf(fp,"%dn%sn%dn%ft",p->number,p->name,p->shumu,p->jiage); p=p->next; printf("保留成功!n"); fclose(fp); return(head); else if(ch='n'|ch='N') printf("信息未保留到文件!n"); head=shuju(); return(head); else printf("sorry,please try again(y/n):"); ch=getchar(); putchar(10); return(head);数据读取函数设计struct goods *shuju() int n=0; FILE *fp; struct goods *head=NULL,*p1,*p2; fp=fopen("goods.txt","rb"); if(fp=NULL) printf("nsorry,读取数据失败!n"); exit(0); else p1=p2=(struct goods *)malloc(LEN); fscanf(fp,"%d%s%d%f",&p1->number,p1->name,&p1->shumu,&p1->jiage); while(!feof(fp) n+; if(n=1)head=p1; else p2->next=p1; p2=p1; p1=(struct goods *)malloc(LEN); fscanf(fp,"%d%s%d%f",&p1->number,p1->name,&p1->shumu,&p1->jiage); p2->next=NULL; fclose(fp); return(head); 录入函数设计void luru()struct goods *shuju();struct goods *baocun(struct goods *head);struct goods *p1,*p2,*p3;head=shuju();p1=head;p2=(struct goods *)malloc(LEN);printf("请输入四位编号:");scanf("%d",&p2->number);printf("请输入商品名:");scanf("%s",p2->name);printf("请输入商品数量:");scanf("%d",&p2->shumu);printf("请输入商品价格:");scanf("%f",&p2->jiage);if(p1=NULL)p1=p2;p2->next=NULL;baocun(p2);return;while(p1!=NULL)p3=p1;p1=p1->next;p3->next=p2;p2->next=NULL;baocun(head);进货函数设计void jinghuo(struct goods *head)struct goods *baocun(struct goods *head); int c; int p; struct goods *p1,*p2; system("cls"); printf("请输入四位编号:"); scanf("%d",&p); p1=head; while(p!=p1->number&&p1->next!=NULL) p2=p1; p1=p1->next; if(p=p1->number) printf("n 商品编号 t 商品名 t 数量 t 价格 n"); printf("%dtt%stt%dtt%fn",p1->number,p1->name,p1->shumu,p1->jiage); printf("请输入该商品经货个数:"); scanf("%d",&c); p1->shumu=p1->shumu+c; printf("该商品经货个数:%dn",p1->shumu); baocun(head);删除函数设计void shanchu(struct goods *head)struct goods *p1,*p2;struct goods *baocun(struct goods *head);int p;system("cls");printf("请输入四位编号:");scanf("%d",&p);p1=head;while(p!=p1->number&&p1->next!=NULL)p2=p1;p1=p1->next;if(p=p1->number)printf("n商品编号 t商品名 t 数量 t 价格 n");printf(" %dtt%stt%dtt%.2fn",p1->number,p1->name,p1->shumu,p1->jiage);if(p1=head) head=p1->next;else p2->next=p1->next;n=n-1; printf("删除成功!n"); baocun(head); 查询函数设计void chaxun(struct goods *head) int a,c,i=0; struct goods *p1,*p2; char t20; printf(" 1*商品编号查询n"); printf(" 2*商品名字查询n"); printf("请选择你需要功效键n"); scanf("%d",&a); getchar(); if(a=1) printf("请输入四位编号:"); scanf("%d",&c);getchar(); while(c!=0&&i=0) p1=head; while(c!=p1->number&&p1->next!=NULL) p2=p1;p1=p1->next; if(c=p1->number) printf("n 商品编号 t 名字 t 数目 t 价格:n"); printf(" %dt %st %dt %.2fn",p1->number,p1->name,p1->shumu,p1->jiage);i=1; else printf("系统中无该商品统计!press enter return!n");getchar();system("cls");return; if(a=2&&i=0) system("cls");printf("请输入商品名字:"); scanf("%s",&t);getchar(); while(strcmp(t,"0")!=0&&i=0) p1=head; if(strcmp(t,p1->name)!=0&&p1->next!=NULL) p2=p1;p1=p1->next; if(strcmp(t,p1->name)=0) printf("n 商品编号 t 名字 t 数目 t 价格:n"); printf(" %dt %st %dt %fn",p1->number,p1->name,p1->shumu,p1->jiage);i=1;else printf("系统中无该商品统计!press enter return!n");getchar();system("cls");return; 修改函数设计void xiugai(struct goods *head)struct goods *baocun(struct goods *head); int p,i=0; struct goods *p1,*p2; system("cls"); printf("请输入四位编号:"); scanf("%d",&p); getchar(); if(p!=0) p1=head; while(p!=p1->number&&p1->next!=NULL) p2=p1; p1=p1->next; if(p=p1->number) printf("n 商品编号 t 名字 t 数目 t 价格:n"); printf(" %dt %st %dt %fn",p1->number,p1->name,p1->shumu,p1->jiage); printf("请输入要修改新商品编号 "); scanf("%d",&p1->number); i=1; if(i=1) printf("修改后新商品编号 名字 数目 价格:n"); printf("%d %s %d %f",p1->number,p1->name,p1->shumu,p1->jiage); printf("修改成功!n"); baocun(head); 销售函数设计void xiaoshu(struct goods *head)struct goods *baocun(struct goods *head); int c; int p; struct goods *p1,*p2; system("cls"); printf("请输入四位编号:"); scanf("%d",&p); getchar(); p1=head; while(p!=p1->number&&p1->next!=NULL) p2=p1; p1=p1->next; if(p=p1->number) printf("n 商品编号 t 商品名 t 数量 t 价格 n"); printf("%dtt%stt%dtt%fn",p1->number,p1->name,p1->shumu,p1->jiage); printf("请输入该商品售货个数:"); scanf("%d",&c); p1->shumu=p1->shumu-c; printf("该商品经货个数:%dn",p1->shumu); baocun(head);三 程序清单#include<stdio.h>#include<string.h>#include<stdlib.h>#include<malloc.h>#define LEN sizeof(struct goods)struct goods 结构体int number; 商品编号char name20; 商品名int shumu; 商品数目float jiage;商品价格struct goods *next;int n,k; 全局变量struct goods *head; 全局变量void main() 主函数 void jieman(); 界面函数申明 void luru(); 录入函数申明 struct goods *shuju(); 数据读取函数申明 void shanchu(struct goods *head); 删除函数申明 void jinghuo(struct goods *head); 进货函数申明 void xiaoshu(struct goods *head); 销售函数申明 void xiugai(struct goods *head); 修改函数申明 void chaxun(struct goods *head); 查询函数申明 struct goods *head=NULL; int k=0; system("cls"); jieman(); printf("请选择你要功效键:"); scanf("%d",&k);getchar(); while(k!=0) head=shuju(); switch(k) case 1:luru();break; case 2:xiugai(head);break; case 3:chaxun(head);break; case 4:xiaoshu(head);break; case 5:jinghuo(head);break; case 6:shanchu(head);break; case 0:exit(0); default:printf("please try again!n"); jieman(); printf("请选择你要功效键:"); scanf("%d",&k); struct goods *baocun(struct goods *head) 保留函数 struct goods *shuju(); struct goods *p=NULL; FILE *fp=NULL; char ch='0' getchar(); printf("是否保留到文件?(y/n):");判定是否保留 ch=getchar(); putchar(10); if(ch='y'|ch='Y') fp=fopen("goods.txt","wb"); p=head; if(fp=NULL)&&(p=NULL) printf("读取数据失败!"); exit(0); while(p!=NULL) fprintf(fp,"%dn%sn%dn%ft",p->number,p->name,p->shumu,p->jiage); p=p->next; printf("保留成功!n"); fclose(fp); return(head); else if(ch='n'|ch='N') printf("信息未保留到文件!n"); head=shuju(); return(head); else printf("sorry,please try again(y/n):"); ch=getchar(); putchar(10); return(head); void chaxun(struct goods *head) 查询函数 int a,c,i=0; struct goods *p1,*p2; char t20; printf(" 1*商品编号查询n"); printf(" 2*商品名字查询n"); printf("请选择你需要功效键n"); scanf("%d",&a); getchar(); if(a=1) printf("请输入四位编号:"); scanf("%d",&c);getchar(); while(c!=0&&i=0) p1=head; while(c!=p1->number&&p1->next!=NULL) 查找商品 p2=p1;p1=p1->next; if(c=p1->number) printf("n 商品编号 t 名字 t 数目 t 价格:n"); printf(" %dt %st %dt %.2fn",p1->number,p1->name,p1->shumu,p1->jiage);i=1; else printf("系统中无该商品统计!press enter return!n");getchar();system("cls");return; if(a=2&&i=0) system("cls");printf("请输入商品名字:"); scanf("%s",&t);getchar(); while(strcmp(t,"0")!=0&&i=0) p1=head; if(strcmp(t,p1->name)!=0&&p1->next!=NULL)查找商品 p2=p1;p1=p1->next; if(strcmp(t,p1->name)=0) printf("n 商品编号 t 名字 t 数目 t 价格:n"); printf(" %dt %st %dt %fn",p1->number,p1->name,p1->shumu,p1->jiage);i=1;else printf("系统中无该商品统计!press enter return!n");getchar();system("cls");return; void jinghuo(struct goods *head) 进货函数struct goods *baocun(struct goods *head); int c; int p; struct goods *p1,*p2; system("cls"); printf("请输入四位编号:"); scanf("%d",&p); p1=head; while(p!=p1->number&&p1->next!=NULL) 查找商品 p2=p1; p1=p1->next; if(p=p1->number) printf("n 商品编号 t 商品名 t 数量 t 价格 n"); printf("%dtt%stt%dtt%fn",p1->number,p1->name,p1->shumu,p1->jiage); printf("请输入该商品经货个数:"); scanf("%d",&c); p1->shumu=p1->shumu+c; printf("该商品经货个数:%dn",p1->shumu); baocun(head); 保留数据 void luru()struct goods *shuju(); 调用函数struct goods *baocun(struct goods *head);struct goods *p1,*p2,*p3;head=shuju();p1=head;p2=(struct goods *)malloc(LEN);printf("请输入四位编号:");scanf("%d",&p2->number);printf("请输入商品名:");scanf("%s",p2->name);printf("请输入商品数量:");scanf("%d",&p2->shumu);printf("请输入商品价格:");scanf("%f",&p2->jiage);if(p1=NULL)p1=p2;p2->next=NULL;baocun(p2);return;while(p1!=NULL)p3=p1;p1=p1->next;p3->next=p2;p2->next=NULL;baocun(head); 保留数据 void shanchu(struct goods *head) 删除函数struct goods *p1,*p2;struct goods *baocun(struct goods *head);int p;system("cls");printf("请输入四位编号:");scanf("%d",&p);p1=head;while(p!=p1->number&&p1->next!=NULL) 查找商品p2=p1;p1=p1->next;if(p=p1->number)printf("n商品编号 t商品名 t 数量 t 价格 n");printf(" %dtt%stt%dtt%.2fn",p1->number,p1->name,p1->shumu,p1->jiage);if(p1=head) head=p1->next;else p2->next=p1->next;n=n-1; printf("删除成功!n"); baocun(head); struct goods *shuju() 数据读取函数 int n=0; FILE *fp; struct goods *head=NULL,*p1,*p2; fp=fopen("goods.txt","rb"); if(fp=NULL) printf("nsorry,读取数据失败!n"); exit(0); else p1=p2=(struct goods *)malloc(LEN); fscanf(fp,"%d%s%d%f",&p1->number,p1->name,&p1->shumu,&p1->jiage); while(!feof(fp) n+; if(n=1)head=p1; else p2->next=p1; p2=p1; p1=(struct goods *)malloc(LEN); fscanf(fp,"%d%s%d%f",&p1->number,p1->name,&p1->shumu,&p1->jiage); p2->next=NULL; fclose(fp); return(head); void jieman() 界面函数 printf("*n"); printf("欢迎进入商品管理系统n"); printf("*1 *录入信息*n"); printf("*2 *修改信息*n"); printf("*3 *查询信息*n"); printf("*4 *销售信息*n"); printf("*5 *进货信息*n"); printf("*6 *删除信息*n"); printf("*0 *退出系统*n"); printf("欢迎进入商品管理系统n"); printf("*n"); void xiaoshu(struct goods *head) 销售函数struct goods *baocun(struct goods *head); int c; int p; struct goods *p1,*p2; system("cls"); printf("请输入四位编号:"); scanf("%d",&p); getchar(); p1=head; while(p!=p1->number&&p1->next!=NULL) 查找商品 p2=p1; p1=p1->next; if(p=p1->number) printf("n 商品编号 t 商品名 t 数量 t 价格 n"); printf("%dtt%stt%dtt%fn",p1->number,p1->name,p1->shumu,p1->jiage); printf("请输入该商品售货个数:"); scanf("%d",&c); p1->shumu=p1->shumu-c; printf("该商品经货个数:%dn",p1->shumu); baocun(head); 保留数据 void xiugai(struct goods *head) 修改函数struct goods *baocun(struct goods *head); int p,i=0; struct goods *p1,*p2; system("cls"); printf("请输入四位编号:"); scanf("%d",&p); getchar(); if(p!=0) p1=head; while(p!=p1->number&&p1->next!=NULL) 查找商品 p2=p1; p1=p1->next; if(p=p1->number) printf("n 商品编号 t 名字 t 数目 t 价格:n"); printf(" %dt %st %dt %fn",p1->number,p1->name,p1->shumu,p1->jiage); printf("请输入要修改新商品编号 "); scanf("%d",&p1->number); i=1; if(i=1) print