收藏 分销(赏)

C语言程序课程设计报告商品进销存管理程序.doc

上传人:二*** 文档编号:4519448 上传时间:2024-09-26 格式:DOC 页数:46 大小:625KB 下载积分:5 金币
下载 相关 举报
C语言程序课程设计报告商品进销存管理程序.doc_第1页
第1页 / 共46页
本文档共46页,全文阅读请下载到手机保存,查看更方便
资源描述
.. - 一 题目及运行说明 商品进销存管理程序 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 goods {int number; char name[20]; 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是否是0~6? 根据k的值调用各功能模块函数 完毕 开场 k 图2. 主函数流程图 具体设计如下: 构造体设计 struct goods {int number; char name[20]; 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,"%d\n%s\n%d\n%f\t",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("%d\t\t%s\t\t%d\t\t%f\n",p1->number,p1->name,p1->shumu,p1->jiage); printf("请输入该商品经货个数:"); scanf("%d",&c); p1->shumu=p1->shumu+c; printf("该商品经货个数:%d\n",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(" %d\t\t%s\t\t%d\t\t%.2f\n",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 t[20]; 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(" %d\t %s\t %d\t %.2f\n",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(" %d\t %s\t %d\t %f\n",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(" %d\t %s\t %d\t %f\n",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("%d\t\t%s\t\t%d\t\t%f\n",p1->number,p1->name,p1->shumu,p1->jiage); printf("请输入该商品售货个数:"); scanf("%d",&c); p1->shumu=p1->shumu-c; printf("该商品经货个数:%d\n",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 name[20]; 商品名 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,"%d\n%s\n%d\n%f\t",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 t[20]; 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(" %d\t %s\t %d\t %.2f\n",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(" %d\t %s\t %d\t %f\n",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("%d\t\t%s\t\t%d\t\t%f\n",p1->number,p1->name,p1->shumu,p1->jiage); printf("请输入该商品经货个数:"); scanf("%d",&c); p1->shumu=p1->shumu+c; printf("该商品经货个数:%d\n",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(" %d\t\t%s\t\t%d\t\t%.2f\n",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("%d\t\t%s\t\t%d\t\t%f\n",p1->number,p1->name,p1->shumu,p1->jiage); printf("请输入该商品售货个数:"); scanf("%d",&c); p1->shumu=p1->shumu-c; printf("该商品经货个数:%d\n",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(" %d\t %s\t %d\t %f\n",p1->number,p1->name,p1->shumu,p1->jiage); printf("请输入要修改的新商品编号 "); scanf("%d",&p1->number); i=1; } if(i
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传

当前位置:首页 > 学术论文 > 其他

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2026 宁波自信网络信息技术有限公司  版权所有

客服电话:0574-28810668  投诉电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服