C语言课程设计设商品管理
- 格式:doc
- 大小:33.50 KB
- 文档页数:4
C语言课程设计商品销售管理系统商品销售管理系统目录一、需求分析 (2)二、概要设计 (2)三、详细设计 (4)四、调试分析 (14)五、用户手册 (14)六、测试数据 (15)七、附录 (18)—1—一、需求分析商品销售管理程序商品信息:商品编号、商品名称、商品类别(普通电视机、DVD、带DVD的电视机,带DVD的电视机的售价为普通电视机和DVD单价之和的80%)、商品进货价格、商品销售价格、商品数量、供应商名称等。
记录每一次销售商品的数量和价格,并提供对已售出商品的价格、数量进行统计、排序功能,但允许用户退商品。
(要求:1.源文件采用多文件的工程结构 2.数据存储采用文件形式3.标准的C输入输出4.功能完善,适当的注释,5.关于文件的内容需要自学)二、概要设计(一)按系统分析的功能要求将系统划分为以下几个主要功能模块:1、文件管理文件打开、关闭:对于刚输入或进行操作后的商品信息,在建立新的商品库存量后,能够把其保存在一个文件中,并对该文件可进行打开和关闭操作。
2、进出货管理(1)商品进货: 输入数据后商品信息能自动更新进行添加(2)商品销售: 输入数据后商品信息能自动更新进行减少3、商品数据管理(1)增加/删除商品: 添加或删除某条商品的信息(2)修改商品信息: 对某条商品的信息进行修改4、浏览商品信息管理(1)查询商品信息:可分别按商品编号、名称、类别或需要进货商品查询(2)排序商品信息: 可按商品编号、名称、类别分别排排序(3)浏览商品信息:可浏览输入、查询或排序后的数据。
(二)本程序结构(1)结构体设计struct goods{ long int num;char name[20];char sort[20];long int count;long int price;}goods[200];(2)各功能函数设计:void input() /*功能1:输入商品信息*/—2—void sequence() /*功能2:排序商品信息*/void purchase() /*功能3:进货商品信息*/void sell() /*功能4:销售商品信息*/void edit() /*功能5:添加或删除商品信息*/ void correct() /*功能6:修改商品信息*/void search() /*功能7:查询商品信息*/void scan() /*功能8:浏览商品信息*/void reserve() /*功能9:保存文件*/void quit() /*退出系统*/(3)主函数设计:void main (){void input();void sequence();void purchase();void sell();void edit();void correct();void search();void scan();void reserve();lp: for(i=0;i<1;i++)scanf("%d",&k);system("cls");switch(k) /*用switch语句实现功能选择*/。
#include<stdio.h>#include<string.h>#include<conio.h>#include<stdlib.h>#define N 100struct commodity{char option[20];char name[20];char price[10];char production_date[8];char stale_date[8];char finished_goods[20];char saleroom[20];};void print_1();void create();void edit();void print_2(); /*invoked of edit*/void edit_add(); /*invoked of edit*/void edit_modify(); /*invoked of edit*/void edit_delete(); /*invoked of edit*/void delete_option(); /*invoked of 2delete*/void delete_name(); /*invoked of 2delete*/void show();void search();void search_option(); /*invoked of search*/void search_name(); /*invoked of search*/main(){char choose='\0',yes_no='\0';do{print_1();choose=getch();switch(choose){case'1':create();break; /*create information of commodity*/case'2':edit();break; /*edit information of commodity*/case'3':show();break; /*show information of commodity*/case'4':search();break; /*search information of commodity*/case'0':exit(0);default:printf("\n %c is illegality option!\n",choose);}printf("\n Do you want to continue(y/n)?");do{yes_no=getche();}while(yes_no!='Y'&&yes_no!='y'&&yes_no!='N'&&yes_no!='n');}while(yes_no=='Y'||yes_no=='y');}void print_1() /*show limiting surface of menu*/{clrscr(); /*clearn screen of function*/printf("********************************************************************* ***********\n");printf("************** Manage'system of Commodity Information *************\n");printf("********************************************************************* ***********\n");printf(" |***********************************************|\n");printf(" | Please input option number |\n");printf("|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|\n");printf(" | 1-----Create commodity information |\n");printf(" | 2-----Edit commodity information |\n");printf(" | 3-----Show commodity information |\n");printf(" | 4-----Search commodity information |\n");printf(" | 0-----Exit system |\n");printf(" |***********************************************|\n"); }void create() /*create information of commodity for function*/{int i=0,j,num;struct commodity temp={0};FILE *fp=NULL;fp=fopen("D:\\commodity.txt","w");if(fp==NULL){printf("\n File of information of commodity opening failed.\n");return ;}clrscr(); /*clearn screen of function*/ printf("Please input want to input the number of goods!");scanf("%d",&num);for(j=1;num>=j;j++){printf("\nPlease input %d record:\n",j);printf(" number:");do{gets(temp.option);}while(strcmp(temp.option,"")==0);printf(" name:");gets();printf(" price:");gets(temp.price);printf(" production:");gets(temp.production_date);printf(" stale_date:");gets(temp.stale_date);printf(" finished_goods:");gets(temp.finished_goods);printf(" saleroom:");gets(temp.saleroom);fprintf(fp,"%s %s %s %s %s %s %s\n",temp.option,,temp.price,temp.production_date,temp.stale_date,temp.finished_goods,temp.stale_date);i++;}fclose(fp);}void edit() /*edit information of commodity for function*/ {char choose='\0',yes_no='\0',pass[20]={0},old[20]={0},w;int i=0,j,m=0;FILE *fp_code;fp_code=fopen("D:\\code.txt","r");if(fp_code==NULL){printf("\n File of code opening failed.\n");return ;}fscanf(fp_code,"%s",old);fclose(fp_code);for(j=0;j<=2;j++){printf("Intput password:");i=0;do{w=getch();if(w!='\r'){putch('*');pass[i]=w;i++;}elsebreak;}while(1);if(strcmp(pass,old)==0)break;else{printf("\nYour code is wrong!!!\n");m++;if(m>=3)exit(1);}}do{print_2();printf(" ");choose=getch();switch(choose){case'1':edit_add();break; /*add new information of commodity*/case'2':edit_modify();break; /*modify information of commodity*/case'3':edit_delete();break; /*delete information of commodity*/case'0':exit(0);default:printf("\n %c is illegality option!\n",choose);}printf("\n Do you want to continue(y/n)?");do{yes_no=getche();}while(yes_no!='Y'&&yes_no!='y'&&yes_no!='N'&&yes_no!='n');}while(yes_no=='Y'||yes_no=='y');}void print_2() /*show limiting surface of menu*/{clrscr(); /*clearn screen of function*/printf("********************************************************************* ***********\n");printf("************** Manage'system of Commodity Information *************\n");printf("********************************************************************* ***********\n");printf(" |***********************************************|\n");printf(" | Please input option number |\n");printf("|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|\n");printf(" | 1-----Add commodity information |\n");printf(" | 2-----Modify commodity information |\n");printf(" | 3-----Delete commodity information |\n");printf(" | 0-----Exit system |\n");printf(" |***********************************************|\n"); }void edit_add() /*add new information of commodity*/{char c='\0';int n=0;struct commodity temp={0},record[N]={0},*p=NULL;FILE *fp=NULL;fp=fopen("D:\\commodity.txt","r");if(fp==NULL){printf("\n File opening failed.\n");return;}p=record;while(feof(fp)==0){fscanf(fp,"%s%s%s%s%s%s%s",p->option,p->name,p->price,p->production_date,p->stale_d ate,p->finished_goods,p->saleroom);p++;n++;}fclose(fp);do{printf("\n Please input new option:");do{gets(temp.option);}while(strcmp(temp.option," ")==0);printf(" Please input new name:");gets();printf(" Please input new price:");gets(temp.price);printf(" Please input new production:");gets(temp.production_date);printf(" Please input new stale_date:");gets(temp.stale_date);printf(" Please input new finished_goods:");gets(temp.finished_goods);printf(" Please input new saleroom:");gets(temp.saleroom);for(p=record;p<record+n;p++)if(strcmp(temp.option,p->option)==0){printf("\n The option is repeat,if you want to input again(y/n)?");do{c=getche();}while(c!='Y'&&c!='y'&&c!='N'&&c!='n');putchar('\n');break;}if(p==record+n){*p=temp;break;}}while(c=='y'||c=='Y');fp=fopen("D:\\commodity.txt","w");if(fp==NULL){printf("\n File opening failed.\n");return;}for(p=record;p<record+n+1;p++)fprintf(fp,"\n%6s%10s%8s%8s%8s%8s%8s",p->option,p->name,p->price,p->production_dat e,p->stale_date,p->finished_goods,p->saleroom);fclose(fp);}void edit_modify() /*modify information of commodity*/{char c='\0';int n=0;struct commodity *find=NULL,temp={0},record[100]={0},*p=NULL;FILE *fp=NULL;fp=fopen("D:\\commodity.txt","r");if(fp==NULL){printf("\n File opening failed.\n");return;}p=record;while(!feof(fp)){fscanf(fp,"%s%s%s%s%s%s%s",p->option,p->name,p->price,p->production_date,p->stale_d ate,p->finished_goods,p->saleroom);p++;n++;}fclose(fp);if(n==0){printf("\n No record in this file.\n");return;}printf("\n Please input you want to commodity'option:");gets(temp.option);for(p=record;p<record+n;p++)if(strcmp(temp.option,p->option)==0){find=p;break;}if(p==record+n){printf("\n No this commodity.\n");return;}do{printf("\n Please input right option.:");do{gets(temp.option);}while(strcmp(temp.option," ")==0);printf(" Please input right name:");gets();printf(" Please input right price:");gets(temp.price);printf(" Please input right production:");gets(temp.production_date);printf(" Please input right stale_date:");gets(temp.stale_date);printf(" Please input right finished_goods:");gets(temp.finished_goods);printf(" Please input right saleroom:");gets(temp.saleroom);for(p=record;p<record+n;p++)if(strcmp(temp.option,p->option)==0&&(p!=find)){printf("\n The option is repeat,do you want to continue?(y/n)");do{c=getche();}while(c!='Y'&&c!='y'&&c!='N'&&c!='n');putchar('\n');break;}if(p==record+n){*find=temp;break;}}while((c=='y')||(c=='Y'));fp=fopen("D:\\commodity.txt","w");if(fp==NULL){printf("\n File opening is failed.\n");return;}for(p=record;p<record+n;p++)fprintf(fp,"\n%6s%10s%8s%8s%8s%8s%8s",p->option,p->name,p->price,p->production_dat e,p->stale_date,p->finished_goods,p->saleroom);fclose(fp);}void edit_delete() /*delete information of commodity*/{char c='\0';printf("\n According to the option(o) to delete, delete or by the name(n)?");c=getche();if(c=='o'||c=='O')delete_option();elseif(c=='n'||c=='N')delete_name();elseprintf("\n This char is illegal.\n");}void delete_option() /*delete information of commodity by option*/{char tempoption[10]=" ";int n=0;struct commodity record[N]={0},*p=NULL,*k=NULL;FILE *fp=NULL;fp=fopen("D:\\commodity.txt","r");if(fp==NULL){printf("\n File opening is failed.\n");return;}p=record;while(!feof(fp)){fscanf(fp,"%s%s%s%s%s%s%s",p->option,p->name,p->price,p->production_date,p->stale_d ate,p->finished_goods,p->saleroom);p++;n++;}fclose(fp);printf("\n Please input you want to delete the option:");gets(tempoption);for(k=record;k<record+n;k++)if(strcmp(tempoption,k->option)==0)break;if(k<record+n)for(p=k;p<k+n-1;p++)*p=*(p+1);elseprintf("\n No such commodify.\n");fp=fopen("D:\\commodity.txt","w");if(fp==NULL){printf("\n File opening failed.\n");return;}for(p=record;p<record+n-1;p++)fprintf(fp,"\n%6s%10s%8s%8s%8s%8s%8s",p->option,p->name,p->price,p->production_dat e,p->stale_date,p->finished_goods,p->saleroom);fclose(fp);}void delete_name() /*delete information of commodity by name*/ {char tempname[20]="";int n=0;struct commodity record[N]={0},*p=NULL,*k=NULL;FILE *fp=NULL;fp=fopen("D:\\commodity.txt","w");if(fp==NULL){printf("\n File opening failed.\n");return;}p=record;while(!feof(fp)){fscanf(fp,"%s%s%s%s%s%s%s",p->option,p->name,p->price,p->production_date,p->stale_d ate,p->finished_goods,p->saleroom);p++;n++;}fclose(fp);printf("\n Please input you want to delete the name:");gets(tempname);for(k=record;p<(record+n-1);p++)if(strcmp(tempname,k->name)==0)break;if(record+n)for(p=k;p<k+n-1;p++)*p=*(p+1);elseprintf("\n No such commodity.\n");fp=fopen("D:\\commodity.txt","w");if(fp==NULL){printf("\n File opening failed.\n");return;}for(p=record;p<record+n-1;p++)fprintf(fp,"\n%6s%10s%8s%8s%8s%8s%8s",p->option,p->name,p->price,p->production_dat e,p->stale_date,p->finished_goods,p->saleroom);fclose(fp);}void show() /*show information of commodity*/{int n=0;struct commodity temp={0};FILE *fp=NULL;fp=fopen("D:\\commodity.txt","r");if(fp==NULL){printf("\n File opening failed.\n");return;}clrscr(); /*clearn screen of function*/printf(" option name price production stale_date finishde_good saleroom\n");while(!feof(fp)){fscanf(fp,"%s%s%s%s%s%s%s",temp.option,,temp.price,temp.production_date,temp.stale_date,temp.finished_goods,temp.stale_date);printf("\n%5s%11s%8s%10s%10s%15s%14s",temp.option,,temp.price, temp.production_date,temp.stale_date,temp.finished_goods,temp.stale_date);n++;}if(n==0)printf("\n This file has not commodity information.\n");elseprintf("\n This file has commodity'quantity is %d.",n);fclose(fp);}void search() /*search information of commodity*/{char c='\0';printf("\n According to the option(o) to inquires, inquires or by the name(n)?");c=getche();if(c=='o'||c=='O')search_option(); /*search information of commodity by option*/elseif(c=='n'||c=='N')search_name(); /*search information of commodity by name*/ elseprintf("\n This char is illegal.\n");}void search_option() /*search information of commodity by option*/{int flag=0,n=0;char tempoption[10]="";struct commodity temp={0};FILE *fp=NULL;fp=fopen("D:\\commodity.txt","r");if(fp==NULL){printf("\n File opening failed.\n");return;}printf("\n Please input you want to search commodity information by option:");gets(tempoption);while(!feof(fp)){fscanf(fp,"%s%s%s%s%s%s%s",temp.option,,temp.price,temp.production_date,te mp.stale_date,temp.finished_goods,temp.saleroom);if(strcmp(tempoption,temp.option)==0){if(flag==0)printf(" option name price production stale_date finishde_good saleroom\n");printf("\n%5s%11s%8s%10s%10s%15s%14s",temp.option,,temp.price,temp.production_date,temp.stale_date,temp.finished_goods,temp.stale_date);flag=1;}n++;}if(n==0)printf("\n This file has not commodity'information.\n");elseif(flag==0)printf("\n This file has not this commodity.\n");fclose(fp);}void search_name() /*search information of commodity by name*/{int flag=0,n=0;char tempname[10]="";struct commodity temp={0};FILE *fp=NULL;fp=fopen("D:\\commodity.txt","r");if(fp==NULL){printf("\n File opening failed.\n");return;}printf("\n Please input you want to search commodity information by option:");gets(tempname);while(!feof(fp)){fscanf(fp,"%s%s%s%s%s%s%s",temp.option,,temp.price,temp.production_date,te mp.stale_date,temp.finished_goods,temp.saleroom);if(strcmp(tempname,)==0){if(flag==0)printf(" option name price production stale_date finishde_good saleroom\n");printf("\n%5s%11s%8s%10s%10s%15s%14s",temp.option,,temp.price,temp.production_date,temp.stale_date,temp.finished_goods,temp.stale_date);flag=1;}n++;}if(n==0)printf("\n This file has not commodity'information.\n");elseif(flag==0)printf("\n This file has not this commodity.\n");fclose(fp);}。
商品管理系统c语言简介商品管理系统是一个广泛应用于商业领域的软件系统,用于管理商品的库存、销售、采购以及相关的数据统计和报表分析等功能。
本文将从系统设计的角度出发,探讨如何使用C语言实现一个简单的商品管理系统。
系统需求分析在设计商品管理系统之前,首先需要明确系统的功能需求。
根据实际商业场景的特点,我们可以确定以下功能: 1. 商品信息管理:包括商品的基本信息(名称、编号、价格等)以及库存管理(进货、出货、盘点等)。
2. 销售管理:记录商品的销售情况,统计销售额、销售量等数据。
3. 采购管理:记录商品的采购情况,统计采购额、采购量等数据。
4. 数据统计和报表分析:根据销售和采购数据,生成各种报表进行数据分析。
数据结构设计在实现商品管理系统时,需要合理设计数据结构来存储商品的信息和相关操作。
以下是主要的数据结构设计: 1. 商品结构体:包含商品的编号、名称、价格、库存数量等信息。
2. 销售记录结构体:包含销售的商品编号、销售数量、销售日期等信息。
3. 采购记录结构体:包含采购的商品编号、采购数量、采购日期等信息。
4. 统计信息结构体:包含销售额、采购额、库存总量等信息。
系统流程设计商品信息管理流程1.显示主菜单:包含商品信息管理、销售管理、采购管理、数据统计和报表分析四个功能选项。
2.商品信息管理功能:包含商品的新增、删除、修改和查询功能。
1.新增商品:输入商品的编号、名称、价格、库存数量等信息,将商品添加到商品列表中。
2.删除商品:输入要删除的商品编号,从商品列表中删除该商品。
3.修改商品:输入要修改的商品编号,根据提示修改商品的相关信息。
4.查询商品:输入要查询的商品编号或名称,显示商品的详细信息。
3.销售管理功能:包含销售记录的新增和查询功能。
1.新增销售记录:输入销售的商品编号和销售数量等信息,将销售记录添加到销售记录列表中。
2.查询销售记录:输入要查询的销售日期,显示该日期的销售记录。
商店销售管理系统#include <stdio.h>#include <time.h>#define N 1000 //N代表货物的最大种类struct goods{char name[10];//商品名称int amount;//商品数量int num;//商品编号float price;//商品价格}sp[N],sc[N];//定义全局变量int flag=1;FILE *fp;int i=0;int k=0;int b=0;chakan()//显示目前的库存{int zong=0;fp=fopen("chaoshi.txt","r");for(i=1;i<=(k+b);i++)fread(&sp[i],sizeof(struct goods),1,fp);fclose(fp);for(i=1;i<=k;i++){zong=zong+sp[i].num;}if(zong!=0){printf(" 目前库存情况为:名称数量价格编号\n");for(i=1;i<=(k+b);i++){printf(" %s %d %f %d\n",sp[i].name,sp[i].amount,sp[i].price,sp[i].num);}}else printf("\n #####目前库存为#####\n");}jinhuo()//进货模块{do{k++;i++;printf(" 请输入商品的名称.数量.价格.标号(>0)例如:a 1 2.5 111\n\t\t\t");scanf("%s %d %f %d%c",sp[i].name,&sp[i].amount,&sp[i].price,&sp[i]. num);printf(" 是否继续,是(1),否(0)\n\t\t\t");scanf("%d",&flag);}while(flag!=0);fp=fopen("chaoshi.txt","w");for(i=1;i<=k;i++)fwrite(&sp[i],sizeof(struct goods),1,fp);fclose(fp);chakan();}xiaoshou()//销售模块{float m[100];int z=1;int j[100];int a[100];int g=0;int y=0;int h=0;float zong=0;fp=fopen("chaoshi.txt","r");for(i=1;i<=k;i++)fread(&sp[i],sizeof(struct goods),1,fp);fclose(fp);do{g++;y++;loop: printf(" 请输入商品编号和数量,例如:(100 20)\n\t\t\t");scanf("%d %d",&j[y],&a[y]);for(z=1;z<=k;z++){if(j[y]==sp[z].num){h++;sp[z].amount=sp[z].amount-a[y];m[y]=(float)a[y]*sp[z].price;sc[y]=sp[z];}}if(h==0){printf(" 输入有误,请重新输入\n\t\t\t");goto loop;}fp=fopen("chaoshi.txt","wt");for(i=1;i<=k;i++)fwrite(&sp[i],sizeof(struct goods),1,fp);fclose(fp);printf(" 是否继续,是(1),否(0)\n\t\t\t");scanf("%d",&flag);}while(flag!=0);printf("\n############################################\n");printf(" 编号名称单价数量总计\n");for(y=1;y<=g;y++){printf(" %4d%10s%8.2f%6d%13.2f\n",sc[y].num,sc[ y].name,sc[y].price,a[y],m[y]);zong=zong+m[y];}printf(" 您此次一共消费%f 元,欢迎您下次光临\n",zong);shijian();}zengjia()//增加商品数量模块{float m;int z=1;int j[100],a[100];int g=0;int y=0;int zong=0;int h=0;fp=fopen("chaoshi.txt","r");for(i=1;i<=k;i++)fread(&sp[i],sizeof(struct goods),1,fp);fclose(fp);do{g++;y++;loop: printf(" 请输入商品编号和数量,例如:(100 20)\n\t\t\t");scanf("%d %d",&j[y],&a[y]);for(z=1;z<=k;z++){if(j[y]==sp[z].num){h++;sp[z].amount=sp[z].amount+a[y];m=a[y]*sp[z].price;sc[y]=sp[z];}}if(h==0){printf(" 输入有误,请重新输入\n\t\t\t");goto loop;}fp=fopen("chaoshi.txt","wt");for(i=1;i<=k;i++)fwrite(&sp[i],sizeof(struct goods),1,fp);fclose(fp);printf(" 是否继续,是(1),否(0)\n\t\t\t");scanf("%d",&flag);}while(flag!=0);chakan();}shanchu()//删除商品模块{int z;int j[100],a[100];int c=0;int y=0;int h=0;do{c++;loop: printf(" 请输入您想删除的商品编号\n\t\t\t");scanf("%d",&j[y]);for(z=1;z<=k;z++){h++;if(j[y]==sp[z].num)sp[z]=sp[z+1];}if(h==0){printf(" 输入有误,请重新输入\n\t\t\t");goto loop;}fp=fopen("chaoshi.txt","wt");for(i=1;i<=(k-1);i++)fwrite(&sp[i],sizeof(struct goods),1,fp);fclose(fp);printf(" 是否继续,是(1),否(0)\n\t\t\t");scanf("%d",&flag);}while(flag!=0);chakan();}shijian(){struct tm when;time_t now;time(&now);when=*localtime(&now);printf(" %s\n",asctime(&when));}main()//主函数{int choice;do{printf("\n\n\n ********超市管理系统*******\n\n");printf(" 1.进货\n");printf(" 2.销售\n");printf(" 3.增加商品数量\n");printf(" 4.删除商品\n");printf(" 5.查看目前库存\n");printf(" 0.返回主菜单\n");printf(" 请选择您要进行的操作\n\t\t\t");scanf("%d",&choice);switch(choice){case 1:jinhuo();break;case 2:xiaoshou();break;case 3:zengjia();break;case 4:shanchu();break;case 5:chakan();break;case 0:break;default :printf(" 输入有误,请重新输入\n\t\t\t");}}while(choice!=0);}。
《C语言程序设计》课程设计报告专业:电子信息工程(本)班级: 0902姓名:学号:指导教师:二0一0 年十二月二十九日目录一.商品信息管理系统设计的目的 (03)二.商品信息管理系统设计题目描述和要求 (04)三.商品信息管理系统设计报告内容 (04)3.1需求分析 (04)3.2概要设计 (04)3.3详细设计 (05)3.4编写代码 (06)3.5程序分析 (11)四.总结 (11)五.参考书目 (12)六.附源程序 (13)二、设计目的1、熟练掌握C语言课程中所学的理论知识;通过课程设计让我们对掌握的C语言的理论知识更加熟练,加深对C语言的各种数据类型的理解,以及在编程中对各种数据类型,运算符和表达示的运用,更加熟练掌握运用不同的结构类型如顺序结构、选择结构、循环结构,同时掌握数组、结构体在编程中的运用的优点。
2、通过综合C语言的基本知识来解决实际问题;对理论知识有了一定的掌握后,要求我们能做到理论与实践相结合,通过综合C 语言的基本知识来解决实际问题,这次的课程设计就是我们理论联系实际的案例,要求我们编写一个商品信息管理系统,方便对商品的各类指标进行存储,查询,为商店的管理带来方便,是我们对解决实际问题的一次尝试。
3、加强分析和解决问题的能力。
通过课程设计,加强我们对实际问题的分析能力,让我们在学习过程中的一些想法得到检验,可以让我们的思维在辩证中提高,最重要的是可以分析我们过往的不足,对于以后遇到类似问题可以更加快速、完善的解决,同时让我们积累了一定的经验,为今后的发展奠定了基础。
二.程序设计题目描述和要求设计对n种商品进行管理的商品信息管理系统,商品信息管理系统是为了商品信息管理的方便而做的一套商品信息管理系统。
本管理系统只有获得权限的用户才可以管理商品信息,否则不可以进行操作,提高了管理系统的安全性。
获得权限的用户可以进行商品信息修改、商品信息删除、商品信息查询、计算总价格和平均价格的基本操作,还可以轻而易举得到统计信息,即商品编号,商品名称,出厂日期,商品价格。
商品管理系统c语言一、引言商品管理系统是一个非常重要的系统,它可以帮助企业更好地管理商品信息,提高工作效率。
本文将介绍一款基于C语言开发的商品管理系统,包括系统功能、设计思路、技术实现等方面。
二、系统功能1. 商品信息的录入和修改:管理员可以通过该功能录入新的商品信息,并对已有商品信息进行修改。
2. 商品信息的查询和删除:管理员可以通过该功能查询商品信息,并对不需要的商品进行删除。
3. 商品销售记录的统计:系统可以记录每个商品的销售情况,并提供统计报表,方便管理员了解销售情况。
4. 库存管理:系统可以根据销售情况自动更新库存数量,并提醒管理员及时补充库存。
三、设计思路1. 系统结构设计本系统采用MVC(Model-View-Controller)架构模式,将数据、视图和控制器分离。
数据层负责数据处理和存储;视图层负责显示用户界面;控制器层负责协调数据层和视图层之间的交互。
2. 数据库设计本系统采用关系型数据库MySQL进行数据存储。
数据库中包含两个表格:商品表格和销售记录表格。
其中,商品表格包含字段有ID(编号)、name(名称)、price(价格)、stock(库存)等;销售记录表格包含字段有ID(编号)、product_id(商品编号)、quantity (数量)、price(单价)等。
3. 界面设计本系统的用户界面采用命令行界面,通过菜单方式实现各项功能。
管理员可以通过键盘输入选择相应的菜单项,进行商品信息的录入、修改、查询和删除,以及销售记录的统计等操作。
四、技术实现1. 数据库连接系统使用C语言中的MySQL API进行数据库连接。
在程序中调用mysql_init()函数初始化连接句柄,然后调用mysql_real_connect()函数建立与数据库服务器的连接。
2. 数据库操作系统使用C语言中的MySQL API进行数据库操作。
在程序中使用mysql_query()函数执行SQL语句,例如插入新商品信息、更新商品信息、查询商品信息等。
c语言商品信息课程设计一、课程目标知识目标:1. 学生能理解C语言在商品信息处理中的应用,掌握基本的变量定义、数据类型及运算符使用。
2. 学生能够运用C语言编写程序,实现商品信息的输入、存储、计算和输出。
3. 学生掌握使用结构体来组织商品信息,并能运用数组管理多个商品的数据。
技能目标:1. 学生能够设计商品信息管理系统的基本框架,编写相应的C语言代码实现功能模块。
2. 学生能够通过调试程序,解决在商品信息处理中遇到的问题,优化程序性能。
3. 学生能够运用所学知识,完成一个小型的商品信息管理系统的开发,提高实际编程能力。
情感态度价值观目标:1. 培养学生对于编程的兴趣,激发他们利用计算机技术解决实际问题的热情。
2. 学生通过小组合作开发商品信息管理系统,增强团队协作能力和沟通技巧。
3. 学生能够在编程实践中体会到编程的逻辑性与严谨性,培养耐心和细心的学习态度。
课程性质分析:本课程设计旨在通过商品信息管理的实际案例,使学生在实践中掌握C语言编程的基本技能,同时培养解决实际问题的能力。
学生特点分析:考虑到学生年级特点,他们在前期的学习中已经掌握了C语言的基础知识,有基本的编程能力,但对复杂问题的解决尚需引导和练习。
教学要求:1. 教学内容应贴近实际应用,提高学生的学习兴趣和参与度。
2. 教学过程中要注重引导学生主动思考,培养解决问题的能力。
3. 教学评价要关注学生的程序设计思维和实际操作能力,以及团队协作能力的培养。
二、教学内容1. 商品信息管理系统概述:介绍商品信息管理系统的基本概念、功能及在实际生活中的应用,使学生了解课程设计背景和意义。
2. C语言基础知识回顾:复习基本的变量定义、数据类型、运算符、控制结构等,为后续编程打下基础。
- 教材章节:第1章-第3章3. 结构体与数组:讲解结构体的定义和使用,以及如何用数组存储和管理商品信息。
- 教材章节:第6章4. 函数的定义与调用:介绍如何将商品信息管理系统的功能模块化,编写相应的函数,提高代码的可读性和可维护性。
c语言商品信息课程设计一、教学目标本课程旨在通过C语言编程,使学生掌握商品信息管理的基本概念和技能,培养学生的编程思维和问题解决能力。
具体目标如下:知识目标:使学生了解C语言的基本语法和数据结构,掌握结构体和指针的运用,了解动态内存分配,能够使用C语言编写简单的商品信息管理系统。
技能目标:培养学生能够通过C语言实现商品信息的增删改查功能,掌握结构体数组的运用,培养学生编程解决问题的能力。
情感态度价值观目标:培养学生对计算机编程的兴趣,培养学生勇于探索、创新的精神,培养学生团队协作的能力。
二、教学内容本课程的教学内容主要包括C语言的基本语法、数据结构、结构体和指针的运用、动态内存分配以及商品信息管理系统的设计和实现。
具体安排如下:1.C语言的基本语法:介绍C语言的基本数据类型、运算符、表达式、语句等。
2.数据结构:介绍数组、链表、栈和队列等基本数据结构。
3.结构体和指针的运用:介绍结构体的定义和使用,指针的基本概念和运用。
4.动态内存分配:介绍动态内存分配的基本方法,如malloc和calloc。
5.商品信息管理系统的设计和实现:介绍如何使用C语言实现一个简单的商品信息管理系统,包括商品的增删改查等功能。
三、教学方法为了激发学生的学习兴趣和主动性,本课程将采用多种教学方法,如讲授法、讨论法、案例分析法、实验法等。
1.讲授法:通过讲解C语言的基本语法、数据结构、结构体和指针的运用等理论知识,使学生掌握基本概念。
2.讨论法:通过分组讨论,引导学生深入思考和理解编程问题,培养学生的团队协作能力。
3.案例分析法:通过分析实际案例,使学生了解商品信息管理系统的设计和实现过程。
4.实验法:通过编写代码和调试程序,使学生掌握C语言编程的技巧,培养学生的动手能力。
四、教学资源为了支持教学内容和教学方法的实施,丰富学生的学习体验,我们将选择和准备以下教学资源:1.教材:《C程序设计语言》(K&R)或《C Primer Plus》。
一题目及运行说明商品进销存管理程序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 nu mber; char n ame[20];int shumu;float jiage;struct goods *n ext;};int n,k;struct goods *head;等一些变量。
(2)数据输入的形式和输入值的范围字符不超过20位整型变量输入大于0浮点型变量也大于0商品编号为四位整数(3)数据输入的形式按程序运行的提示操作※(4)程序所能达到的功能及出错处理该程序具有以下功能:(1)录入商品信息;(2)给定商品编号,修改该商品信息;(3)给定商品编号,删除该商品信息;(4)录入商品的进货和销售信息;(5)给定商品编号或商品名,查看该商品及库存信息(6)统计功能:提供一些统计各类信息的功能。
二程序设计思路根据要求首先设计一个结构体类型,设计好界面,设计好主函数。
程序各功能通过调用子函数来实现用switch来实现菜单的选择一切数据信息通通存在文件中,并实现文件读写操作。
#include<stdio.h>#include<string.h>#include<conio.h>#include<stdlib.h>#define N 100struct commodity{char option[20];char name[20];char price[10];char production_date[8];char stale_date[8];char finished_goods[20];char saleroom[20];};void print_1();void create();void edit();void print_2(); /*invoked of edit*/void edit_add(); /*invoked of edit*/void edit_modify(); /*invoked of edit*/void edit_delete(); /*invoked of edit*/void delete_option(); /*invoked of 2delete*/void delete_name(); /*invoked of 2delete*/void show();void search();void search_option(); /*invoked of search*/void search_name(); /*invoked of search*/main(){char choose='\0',yes_no='\0';do{print_1();choose=getch();switch(choose){case'1':create();break; /*create information of commodity*/case'2':edit();break; /*edit information of commodity*/case'3':show();break; /*show information of commodity*/case'4':search();break; /*search information of commodity*/case'0':exit(0);default:printf("\n %c is illegality option!\n",choose);}printf("\n Do you want to continue(y/n)?");do{yes_no=getche();}while(yes_no!='Y'&&yes_no!='y'&&yes_no!='N'&&yes_no!='n');}while(yes_no=='Y'||yes_no=='y');}void print_1() /*show limiting surface of menu*/{clrscr(); /*clearn screen of function*/printf("********************************************************************* ***********\n");printf("************** Manage'system of Commodity Information *************\n");printf("********************************************************************* ***********\n");printf(" |***********************************************|\n");printf(" | Please input option number |\n");printf("|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|\n");printf(" | 1-----Create commodity information |\n");printf(" | 2-----Edit commodity information |\n");printf(" | 3-----Show commodity information |\n");printf(" | 4-----Search commodity information |\n");printf(" | 0-----Exit system |\n");printf(" |***********************************************|\n"); }void create() /*create information of commodity for function*/{int i=0,j,num;struct commodity temp={0};FILE *fp=NULL;fp=fopen("D:\\commodity.txt","w");if(fp==NULL){printf("\n File of information of commodity opening failed.\n");return ;}clrscr(); /*clearn screen of function*/ printf("Please input want to input the number of goods!");scanf("%d",&num);for(j=1;num>=j;j++){printf("\nPlease input %d record:\n",j);printf(" number:");do{gets(temp.option);}while(strcmp(temp.option,"")==0);printf(" name:");gets();printf(" price:");gets(temp.price);printf(" production:");gets(temp.production_date);printf(" stale_date:");gets(temp.stale_date);printf(" finished_goods:");gets(temp.finished_goods);printf(" saleroom:");gets(temp.saleroom);fprintf(fp,"%s %s %s %s %s %s %s\n",temp.option,,temp.price,temp.production_date,temp.stale_date,temp.finished_goods,temp.stale_date);i++;}fclose(fp);}void edit() /*edit information of commodity for function*/ {char choose='\0',yes_no='\0',pass[20]={0},old[20]={0},w;int i=0,j,m=0;FILE *fp_code;fp_code=fopen("D:\\code.txt","r");if(fp_code==NULL){printf("\n File of code opening failed.\n");return ;}fscanf(fp_code,"%s",old);fclose(fp_code);for(j=0;j<=2;j++){printf("Intput password:");i=0;do{w=getch();if(w!='\r'){putch('*');pass[i]=w;i++;}elsebreak;}while(1);if(strcmp(pass,old)==0)break;else{printf("\nYour code is wrong\n");m++;if(m>=3)exit(1);}}do{print_2();printf(" ");choose=getch();switch(choose){case'1':edit_add();break; /*add new information of commodity*/case'2':edit_modify();break; /*modify information of commodity*/case'3':edit_delete();break; /*delete information of commodity*/case'0':exit(0);default:printf("\n %c is illegality option!\n",choose);}printf("\n Do you want to continue(y/n)?");do{yes_no=getche();}while(yes_no!='Y'&&yes_no!='y'&&yes_no!='N'&&yes_no!='n');}while(yes_no=='Y'||yes_no=='y');}void print_2() /*show limiting surface of menu*/{clrscr(); /*clearn screen of function*/printf("********************************************************************* ***********\n");printf("************** Manage'system of Commodity Information *************\n");printf("********************************************************************* ***********\n");printf(" |***********************************************|\n");printf(" | Please input option number |\n");printf("|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|\n");printf(" | 1-----Add commodity information |\n");printf(" | 2-----Modify commodity information |\n");printf(" | 3-----Delete commodity information |\n");printf(" | 0-----Exit system |\n");printf(" |***********************************************|\n"); }void edit_add() /*add new information of commodity*/{char c='\0';int n=0;struct commodity temp={0},record[N]={0},*p=NULL;FILE *fp=NULL;fp=fopen("D:\\commodity.txt","r");if(fp==NULL){printf("\n File opening failed.\n");return;}p=record;while(feof(fp)==0){fscanf(fp,"%s%s%s%s%s%s%s",p->option,p->name,p->price,p->production_date,p->stale_d ate,p->finished_goods,p->saleroom);p++;n++;}fclose(fp);do{printf("\n Please input new option:");do{gets(temp.option);}while(strcmp(temp.option," ")==0);printf(" Please input new name:");gets();printf(" Please input new price:");gets(temp.price);printf(" Please input new production:");gets(temp.production_date);printf(" Please input new stale_date:");gets(temp.stale_date);printf(" Please input new finished_goods:");gets(temp.finished_goods);printf(" Please input new saleroom:");gets(temp.saleroom);for(p=record;p<record+n;p++)if(strcmp(temp.option,p->option)==0){printf("\n The option is repeat,if you want to input again(y/n)?");do{c=getche();}while(c!='Y'&&c!='y'&&c!='N'&&c!='n');putchar('\n');break;}if(p==record+n){*p=temp;break;}}while(c=='y'||c=='Y');fp=fopen("D:\\commodity.txt","w");if(fp==NULL){printf("\n File opening failed.\n");return;}for(p=record;p<record+n+1;p++)fprintf(fp,"\n%6s%10s%8s%8s%8s%8s%8s",p->option,p->name,p->price,p->production_dat e,p->stale_date,p->finished_goods,p->saleroom);fclose(fp);}void edit_modify() /*modify information of commodity*/{char c='\0';int n=0;struct commodity *find=NULL,temp={0},record[100]={0},*p=NULL;FILE *fp=NULL;fp=fopen("D:\\commodity.txt","r");if(fp==NULL){printf("\n File opening failed.\n");return;}p=record;while(!feof(fp)){fscanf(fp,"%s%s%s%s%s%s%s",p->option,p->name,p->price,p->production_date,p->stale_d ate,p->finished_goods,p->saleroom);p++;n++;}fclose(fp);if(n==0){printf("\n No record in this file.\n");return;}printf("\n Please input you want to commodity'option:");gets(temp.option);for(p=record;p<record+n;p++)if(strcmp(temp.option,p->option)==0){find=p;break;}if(p==record+n){printf("\n No this commodity.\n");return;}do{printf("\n Please input right option.:");do{gets(temp.option);}while(strcmp(temp.option," ")==0);printf(" Please input right name:");gets();printf(" Please input right price:");gets(temp.price);printf(" Please input right production:");gets(temp.production_date);printf(" Please input right stale_date:");gets(temp.stale_date);printf(" Please input right finished_goods:");gets(temp.finished_goods);printf(" Please input right saleroom:");gets(temp.saleroom);for(p=record;p<record+n;p++)if(strcmp(temp.option,p->option)==0&&(p!=find)){printf("\n The option is repeat,do you want to continue?(y/n)");do{c=getche();}while(c!='Y'&&c!='y'&&c!='N'&&c!='n');putchar('\n');break;}if(p==record+n){*find=temp;break;}}while((c=='y')||(c=='Y'));fp=fopen("D:\\commodity.txt","w");if(fp==NULL){printf("\n File opening is failed.\n");return;}for(p=record;p<record+n;p++)fprintf(fp,"\n%6s%10s%8s%8s%8s%8s%8s",p->option,p->name,p->price,p->production_dat e,p->stale_date,p->finished_goods,p->saleroom);fclose(fp);}void edit_delete() /*delete information of commodity*/{char c='\0';printf("\n According to the option(o) to delete, delete or by the name(n)?");c=getche();if(c=='o'||c=='O')delete_option();elseif(c=='n'||c=='N')delete_name();elseprintf("\n This char is illegal.\n");}void delete_option() /*delete information of commodity by option*/{char tempoption[10]=" ";int n=0;struct commodity record[N]={0},*p=NULL,*k=NULL;FILE *fp=NULL;fp=fopen("D:\\commodity.txt","r");if(fp==NULL){printf("\n File opening is failed.\n");return;}p=record;while(!feof(fp)){fscanf(fp,"%s%s%s%s%s%s%s",p->option,p->name,p->price,p->production_date,p->stale_d ate,p->finished_goods,p->saleroom);p++;n++;}fclose(fp);printf("\n Please input you want to delete the option:");gets(tempoption);for(k=record;k<record+n;k++)if(strcmp(tempoption,k->option)==0)break;if(k<record+n)for(p=k;p<k+n-1;p++)*p=*(p+1);elseprintf("\n No such commodify.\n");fp=fopen("D:\\commodity.txt","w");if(fp==NULL){printf("\n File opening failed.\n");return;}for(p=record;p<record+n-1;p++)fprintf(fp,"\n%6s%10s%8s%8s%8s%8s%8s",p->option,p->name,p->price,p->production_dat e,p->stale_date,p->finished_goods,p->saleroom);fclose(fp);}void delete_name() /*delete information of commodity by name*/ {char tempname[20]="";int n=0;struct commodity record[N]={0},*p=NULL,*k=NULL;FILE *fp=NULL;fp=fopen("D:\\commodity.txt","w");if(fp==NULL){printf("\n File opening failed.\n");return;}p=record;while(!feof(fp)){fscanf(fp,"%s%s%s%s%s%s%s",p->option,p->name,p->price,p->production_date,p->stale_d ate,p->finished_goods,p->saleroom);p++;n++;}fclose(fp);printf("\n Please input you want to delete the name:");gets(tempname);for(k=record;p<(record+n-1);p++)if(strcmp(tempname,k->name)==0)break;if(record+n)for(p=k;p<k+n-1;p++)*p=*(p+1);elseprintf("\n No such commodity.\n");fp=fopen("D:\\commodity.txt","w");if(fp==NULL){printf("\n File opening failed.\n");return;}for(p=record;p<record+n-1;p++)fprintf(fp,"\n%6s%10s%8s%8s%8s%8s%8s",p->option,p->name,p->price,p->production_dat e,p->stale_date,p->finished_goods,p->saleroom);fclose(fp);}void show() /*show information of commodity*/{int n=0;struct commodity temp={0};FILE *fp=NULL;fp=fopen("D:\\commodity.txt","r");if(fp==NULL){printf("\n File opening failed.\n");return;}clrscr(); /*clearn screen of function*/printf(" option name price production stale_date finishde_good saleroom\n");while(!feof(fp)){fscanf(fp,"%s%s%s%s%s%s%s",temp.option,,temp.price,temp.production_date,temp.stale_date,temp.finished_goods,temp.stale_date);printf("\n%5s%11s%8s%10s%10s%15s%14s",temp.option,,temp.price, temp.production_date,temp.stale_date,temp.finished_goods,temp.stale_date);n++;}if(n==0)printf("\n This file has not commodity information.\n");elseprintf("\n This file has commodity'quantity is %d.",n);fclose(fp);}void search() /*search information of commodity*/{char c='\0';printf("\n According to the option(o) to inquires, inquires or by the name(n)?");c=getche();if(c=='o'||c=='O')search_option(); /*search information of commodity by option*/elseif(c=='n'||c=='N')search_name(); /*search information of commodity by name*/ elseprintf("\n This char is illegal.\n");}void search_option() /*search information of commodity by option*/{int flag=0,n=0;char tempoption[10]="";struct commodity temp={0};FILE *fp=NULL;fp=fopen("D:\\commodity.txt","r");if(fp==NULL){printf("\n File opening failed.\n");return;}printf("\n Please input you want to search commodity information by option:");gets(tempoption);while(!feof(fp)){fscanf(fp,"%s%s%s%s%s%s%s",temp.option,,temp.price,temp.production_date,te mp.stale_date,temp.finished_goods,temp.saleroom);if(strcmp(tempoption,temp.option)==0){if(flag==0)printf(" option name price production stale_date finishde_good saleroom\n");printf("\n%5s%11s%8s%10s%10s%15s%14s",temp.option,,temp.price,temp.production_date,temp.stale_date,temp.finished_goods,temp.stale_date);flag=1;}n++;}if(n==0)printf("\n This file has not commodity'information.\n");elseif(flag==0)printf("\n This file has not this commodity.\n");fclose(fp);}void search_name() /*search information of commodity by name*/{int flag=0,n=0;char tempname[10]="";struct commodity temp={0};FILE *fp=NULL;fp=fopen("D:\\commodity.txt","r");if(fp==NULL){printf("\n File opening failed.\n");return;}printf("\n Please input you want to search commodity information by option:");gets(tempname);while(!feof(fp)){fscanf(fp,"%s%s%s%s%s%s%s",temp.option,,temp.price,temp.production_date,te mp.stale_date,temp.finished_goods,temp.saleroom);if(strcmp(tempname,)==0){if(flag==0)printf(" option name price production stale_date finishde_good saleroom\n");printf("\n%5s%11s%8s%10s%10s%15s%14s",temp.option,,temp.price,temp.production_date,temp.stale_date,temp.finished_goods,temp.stale_date);flag=1;}n++;}if(n==0)printf("\n This file has not commodity'information.\n");elseif(flag==0)printf("\n This file has not this commodity.\n");fclose(fp);}。
用C语言编写软件完成以下任务:
对超市的 1 / 4
:增加商品数据,包括:商品编号、名称、单价、和数量,要能实现在现有商品的基础
上增加新的商品数据,数据保存到文件myfile.txt中;对商品进行销售和查询,例如:现有
课本10本,销售2本后,查询应为8本。后2个功能要从已保存的文件中读取数据。
#include
#include
#include
#define N 3 //标定商品数量
struct commo
{
int num1;
int num2;
int num3;
int num4;
char name[20];
int price;
};
void getdata() //输入并保存数据
{
struct commo shp[N];
int i;
FILE *fp;
printf("增加商品数据\n");
if((fp=fopen("d:\\myfile.txt","w+"))==NULL)
{
printf("建立文件失败,请检查路径设置\n\n");
exit(0);
}
for(i=0;i
printf("\n请输入第%d种商品编号:",i+1);
scanf("%d",&shp[i].num1);
printf("请输入数量:");
scanf("%d",&shp[i].num2);
printf("请输入名称:");
scanf("%s",&shp[i].name);
printf("请输入单价:");
scanf("%d",&shp[i].price);
getchar();
}
for(i=0;i
fwrite(&shp[i],sizeof(struct commo),1,fp); //向文件中写数据
}
fclose(fp);
}
void chushou() //计算售出
{struct commo shp[N];
FILE *fp;
int i;
if((fp=fopen("d:\\myfile.txt","r+"))==NULL)
{
printf("打开文件失败,请检查路径设置\n\n");
exit(0);
}
for(i=0;i
fread(&shp[i],sizeof(struct commo),1,fp);
}
rewind(fp); //将文件内部的位置指针移到文件开始位置
for(i=0;i
printf("第%d种商品销售的数量:\n",i+1);
scanf("%d",&shp[i].num4);
}
for(i=0;i
shp[i].num3=shp[i].num2-shp[i].num4;
printf("第%d种剩余的商品是数量:%d\n",i+1,shp[i].num3);
fwrite(&shp[i],sizeof(struct commo),1,fp);
}
fclose(fp);
getchar();
}
void chaxun() //查询
{
int i;
int a;
FILE *fp;
struct commo shp[N];
if((fp=fopen("D:\\myfile.txt","r+"))==NULL)
{
printf("打开文件失败,请检查路径设置\n\n");
exit(0);
}
for(i=0;i
fread(&shp[i],sizeof(struct commo),1,fp);
}
printf("查询的商品编号");
scanf("%d",&a);
for(i=0;i
if(shp[i].num1==a)
printf(" %s 剩余的商品是数量:%d\n ",shp[i].name,shp[i].num3);
}
fclose(fp);
getchar();
}
void menu() //菜单
{
/*system("cls");*/ //清屏
printf("\n\n>>> 超市管理系统 <<<\n\n\n");
printf("***增加商品信息 请按1***\n\n"),
printf("***销 售 商 品 请按2***\n\n"),
printf("***查 询 请按3***\n\n"),
printf("***退 出 程 序 请按4***\n\n"),
printf("*******************************************************\n");
}
void main() //主函数
{
int select;
while(1)
{
menu();
printf("**********请选择操作: 1 ,2,3,4 ************\n");
scanf("%d",&select);
getchar();
if(select==1)
getdata();
if(select==2)
chushou();
if(select==3)
chaxun();
if(select==4)
exit(0);
}
}