c语言程序设计_超_市_管_理_系_统

更新时间:2023-05-12 23:18:01 阅读量: 实用文档 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

c语言

实验题目:超市管理系统

一、 实验目的

1. 熟悉c语言的编译连接和运行过程。

2. 掌握c语言的数据类型,熟悉整型、实型、字符型变量的定义方式及如何给它们赋值。

3. 掌握if语句及switch语句的运用方法及嵌套应用方法。

4. 掌握实现循环结构的三种语句while、 do-while.、for 的使用。 5. 掌握函数的定义方法和调用方法。 6. 能够采用模块化思想调试程序。 二.实验内容

1. 编写程序并进行调试运行。

2. 输入商品资料,并保存于文件。每件商品包含信息如:商品号、商品名、商品类别、商品总量、商品上限和下限、商品价格、进货日期、生产日期、保质期等。

3. 对已存入的商品信息进行更新操作,包括添加一件商品信息、删除某件商品信息和修改商品信息。

4. 通过按商品名、商品种类、商品进货量的方式查询商品信息。

5.输入某商品号后对其利润进行统计、对进货价格相同的商品进行统计。 6 对商品的库存量和利润进行排序。 7.最后输出商品信息,供需要时打印。

二、 需求分析

1. 该程序可用于对商品的基本信息的存储、更新、查询、输出、统计、排序等操作,以实现管理者对商品的管理和消费者对商品的了解。

2. 其中更新功能包括:添加信息、删除信息、修改信息、可根据需要添加一个或多件商品信息,也可对个别商品信息进行适当的删除或修改。以便随时更新商品信息。

3. 程序中设计的查询功能可根据需要从若干数据中查询某件商品信息,并且可根据三种不同的方法查询:按商品名查询、按商品种类查询和按商品进货量查询。以满足不同的需要。

四、概要设计

1、方案设计

对系统进行分析,给出结构图

分析:系统要求实现许多的功能,因此遵循结构化程序设计思想来进行本系统的设计—自顶向下、逐步细化,将系统设计任务分解出许多子功能模块进行设计

结构图如下:

c语言

超市管理管理系统

管理者系统

退出系统

消费者管理系统

录 入 信 息

输 出 信 息

更 新 模 块

统 计 模 块

排 序 模 块

查 询 模 块

退 出 系 统

退 出 系 统

排 序 模 块

查 询 模 块

退 出 系 统

添 加 商 品 信 息

删 除 商 品 信 息

修 改 商 品 信 息

退 出 系 统

第 一 类 商 品

第 二 类 商 品

第 三 类 商 品

退 出 系 统

库 存 量 排 行

利 润 排 行

按 商 品 名 查 询

按 商 品 种 类 查

退 出 系 统

按 进 货 量 查 询

退 出 系 统

利 润 排 行

库 存 量 排 行

退 出 系 统

按 商 品 名 查 询

按 商 品 种 类 查

按 进 货 量 查 询

c语言

2

对各个模块进行功能的描述 (1).输入模块:

录入需要管理的商品信息并将信息保存于文件中,以方便日后进

行打印、读取、更新等操作。

(2).添加模块:

可添加一件或多件商品信息,并将所添加商品信息保存,方便查

找。

(3).删除模块:

可对过期的商品做删除处理。

(4).修改模块:

可根据需要对多件商品信息进行修改,也可随时对个别项进行修

改。

(5).查询模块:

可对已建立的商品信息进行查询,并且可根据需要选择按商品名

查询或按商品种类查询或按商品进货量查询。

(6).保存模块:

用于对信息进行保存。

(7).输出模块:

将所有商品信息或想要查询的商品信息显示于屏幕,用于打印商品信息

或查找某些商品信息。

(8) 排序模块:

根据商品的利润和进货量进行排序。 (9) 统计模块:

统计商品的利润和对进货价格相同的商品进行统计。 (10).退出系统:

选择该项,自动退出该系统。

五、详细设计及运行结果

流程图, 函数之间相互调用的图示 ,程序设计及编码, 运行结果。

c语言

开 始 输入 i 值

判断 i 值

管理者系统

消费者系统

退出系统

退 出 系 统

输 出 模 块

输 入 模 块

更 新 模 块

排 序 模 块

统 计 模 块

查 询 模 块

查 询 模 块

排 序 模 块

退 出 系 统

输入更 新值

输入排 序值

输入统 计值

输入查询

值输入查 询 输入排 序值

退 出 系 统

添 加 信 息

删 除 信 息

修 改 信 息

退 出 系 统

利 润 排 序

库 存 排 序

退 出 系 统

一 类 商 品

二 类 商 品

三 类 商 品

退 出 系 统

按 名 查 询

按 种 类 查

按 进 货 量

4

退 出 系 统

按 名 查 询

按 种 类 查

按 进 货 量

退 出 系 统

利 润 排 序

库 存 排 序

c语言

六. 调试情况及运行结果

1、对自己设计进行评价,指出合理和不足之处,提出改进的方案。

此次实践课编写的是一个应用程序,相对于以前我们见到的程序,它要大得多,于是就按课本上的例子编了超市管理系统,先把界面弄好然后再添加各模块,而且各模块也出现了不少问题,在同学们和老师的帮助下,我很有耐心的一次又一次的进行修改,最后运行的结果基本上达到了预期的目的。可结果还不是太理想。

由于时间很短,在选题报告中设想到的好多功能都没有实现。已有的那些功能虽已能基本上满足管理者和消费者的需要,但如果还有更多的功能程序就会更加完美。如:进入系统时没有设制密码,保护性不够强;在输入商品号时没有出错提示,如果商品号输入负值

2、在设计过程中的感受。

本次C 语言的实习课让我对C 语言的学习又有了更深入的了解,也让我更深刻地领悟到了“实践出真理”这个道理,在上机实践过程中学到的知识远远超过了在课堂上十几周学到的,学校组织的这次实习让我们这些实践知识匮乏的大学生增添了许多社会经验,为我们将来走上工作岗位其了不小的铺垫作用。

本次实习中遇到了很多以前没有遇到过的问题,也曾想过要放弃,但看到那些同学都在那认真的写程序,给了我继续的信心。在同学的帮助下,我顺利的结束了本次实习,让我知道原来凭借自己努力取得的成功会让自己这么欣慰,也让我知道了友谊和团结的重要性。

七.参考文献

《C语言程序设计》 王曙燕 曹锰 科学出版社 八。附录:

#include <stdio.h>

#include <string.h> #define MAX 3 #define N 3 #define PAGE 2 #define PRINTF1 printf("---------------------------------------------------------------------\n") #define PRINTF2 printf("num----name----kind----out_price----pro_time(year-month-day)----save_time\n"); #define PRINTF3 printf("%d%8s %7s %8d %5d-%2d-%2d %10d\n",goods[i].num,goods[i].name,goods[i].kind,goods[i].out_price,goods[i].pro_time.year,goods[i].pro_time.month,goods[i].pro_time.day,goods[i].save_day); int sum;

/*data struct kind*/

c语言

struct data {

int year; int month; int day; };

/*goods struct kind*/ struct goods {

int num;

char name[10]; char kind[10]; int amount; int goods_up; int goods_down; int in_price; int out_price; int in_num;

struct data in_time; struct data pro_time; char factory[10]; int save_day; float profit;

}goods[MAX]; /*save message*/

save_message(int sum) {

FILE *fp; int i;

if((fp=fopen("goods.txt","wb"))==NULL) {

printf("read the file error!\n"); return; }

for(i=0;i<sum;i++)

if(fwrite(&goods[i],sizeof(struct goods),1,fp)!=1) printf("write the file error!\n"); fclose(fp); }

c语言

/*input message*/ input_message() {

int i=0,s=MAX; system("cls");

printf("\n\n input goods message the most%d\n\n",s);

do {

printf("\n di%dgoods",i+1); printf("\n num:");

scanf("%d",&goods[i].num);

if(goods[i].num==0) break;

printf("\n name:");

scanf("%s",goods[i].name); printf("\n kind:");

scanf("%s",goods[i].kind); printf("\n amount:");

scanf("%d",&goods[i].amount); printf("\n goods_up:");

scanf("%d",&goods[i].goods_up); printf("\n goods_down:");

scanf("%d",&goods[i].goods_down); printf("\n in_price:");

scanf("%d",&goods[i].in_price); printf("\n out_price:"); fflush(stdin);

scanf("%d",&goods[i].out_price); printf("\n in_num:");

scanf("%d",&goods[i].in_num); printf("\n in_time:");

scanf("%d-%d-%d",&goods[i].in_time.year,&goods[i].in_time.month, &goods[i].in_time.day); printf("\n pro_time:");

scanf("%d-%d-%d",&goods[i].pro_time.year,&goods[i].pro_time.month, &goods[i].pro_time.day); printf("\n factory:");

scanf("%s",goods[i].factory); printf("\n save_time:");

scanf("%d",&goods[i].save_day); i++;

}while(i<MAX);

c语言

printf("\n***** %d goods message input over!--\n",i); sum=i;

printf("\n press any key to return!"); bioskey(0) ; }

/*read message*/ int read_message() {

FILE *fp; int i=0;

if((fp=fopen("goods.txt","rb"))==NULL) {

printf("\n\n ******there is no any message,press return !******\n"); return; }

while(feof(fp)!=1) {

fread(&goods[i],sizeof(struct goods),1,fp); if(goods[i].num==0) break; else i++; }

fclose(fp); return(i); }

/*output message*/ output_message() {

int i=0,j=0,count,page=1; system("cls");

printf("\n\n --goods message,di %d page\n\n",page); PRINTF2; PRINTF1; do {

if(goods[i].num!=0) {

j++;

if(j%PAGE!=0) {

PRINTF3; PRINTF1;

any key to

c语言

} else {

PRINTF3; PRINTF1;

if(goods[i+1].num!=0) {

printf("press any key to return!"); getch();

system("cls");

printf("\n\n --goods message,di%d page\n\n",++page); PRINTF2; PRINTF1;

} } } i++;

} while(i<sum);

printf("press any key return!"); bioskey(0); }

/*insert goods message*/ insert_message() {

int i=sum,j,flag=0; char choice; system("cls");

printf("\n\n insert a new goods\n"); printf(" ----------------------\n"); do {

goods[i].num=++sum;

printf("\n new num:"); scanf("%d",&goods[i].num);

printf("\n new name:"); scanf("%s",goods[i].name);

printf("\n new kind:"); scanf("%s",goods[i].kind);

printf("\n new amount:"); scanf("%d",&goods[i].amount);

c语言

printf("\n new goods_up: "); scanf("%d",&goods[i].goods_up);

printf("\n new goods_down:"); scanf("%d",&goods[i].goods_down);

printf("\n new in_price: "); scanf("%d",&goods[i].in_price);

printf("\n new out_price:"); scanf("%d",&goods[i].out_price);

printf("\n new in_num:"); scanf("%d",&goods[i].in_num);

printf("\n new in_time:"); scanf("%d-%d-%d",&goods[i].in_time.year, &goods[i].in_time.month, &goods[i].in_time.day);

printf("\n new pro_time:"); scanf("%d-%d-%d",&goods[i].pro_time.year, &goods[i].pro_time.month, &goods[i].pro_time.day);

printf("\n new factory: "); scanf("%s",goods[i].factory);

printf("\n new save_time: "); scanf("%d",&goods[i].save_day);

printf("\n go on or not?(Y/N)"); choice=getch();

if(choice=='Y'||choice=='y') {

printf("\n go on!\n"); i++; flag=1; }

else flag=0; }while(flag==1);

printf("\n press any key return!"); bioskey(0); }

/*renew goods message*/ renew_message() {

int choice; do

{ system("cls");

printf("\n\n\n *******renew goods message*******\n\n"); printf(" 1: insert goods message\n\n"); printf(" 2: del goods message\n\n");

c语言

printf(" 3: revise goods message\n\n"); printf(" 0: return\n\n ");

printf(" please choose(0-3):"); scanf("%d",&choice); switch(choice) {

case 1: insert_message(); break;

case 2: del_message(); break;

case 3: revise_message(); break;

case 0: break;

}

}while(choice!=0); }

/*del goods message*/ del_message() {

int i=0,del_num,flag,k; char choice,choice1; do {

system("cls");

printf("\n --please input the del goods num:--\n"); scanf("%d",&del_num);

printf("\n --really del the goods?(Y/N)"); choice1=getch();

if(choice1=='Y'||choice1=='y') printf("\n --continue!--\n"); for(i=0;i<sum;i++)

if(goods[i].num==del_num) {

printf("\n --goods message--\n"); PRINTF1; PRINTF2; PRINTF3;

for(k=i;k<sum-1;k++)

goods[k]=goods[k+1];sum--;

printf("\n --after delete--\n"); PRINTF1; PRINTF2;

c语言

PRINTF3; break;

}

if(i==sum) {

printf("\n --the goods is not exist!--\n"); getch(); }

printf("\n\n --go on or not?Y/N--\n"); choice=getch();

if(choice=='Y'||choice=='y') {

flag=1;

printf("\n --go on--\n");

}

else flag=0; }while(flag==1);

printf("\n --press any key return--\n"); bioskey(0); }

/*revise goods message*/ revise_message() {

int i=0,choice,revise_num,flag; char choice1; do {

system("cls");

printf("\n please input the revise goods num:"); scanf("%d",&revise_num); for(i=0;i<sum;)

{if(goods[i].num==revise_num) {

printf("\n ----goods message---- \n"); PRINTF1; PRINTF2; PRINTF3;

printf("\n which item you want to revise?\n printf("\n 1: name\n"); printf("\n 2: kind\n");

printf("\n 3: out_price\n");

");

c语言

printf("\n 4: pro_time\n"); printf("\n 5: save_day\n");

printf("\n please choose(1-5)"); scanf("%d",&choice); switch(choice) {

case 1: printf("\n after revise num: "); scanf("%s",goods[i].name); break;

case 2: printf("\n after revise kind: "); scanf("%s",goods[i].kind); break;

case 3: printf("\n after revise out_price:"); scanf("%d",&goods[i].out_price); break;

case 4: printf("\n after revise pro_time:");

scanf("%d-%d-%d",&goods[i].pro_time.year, &goods[i].pro_time.month, &goods[i].pro_time.day); break;

case 5: printf("\n after revise save_time:"); scanf("%d",&goods[i].save_day); break;

}

PRINTF1; PRINTF2; PRINTF3; break;

}

else i++;} if(i==sum) {

printf("\n this goods is not exist!"); getch();

}

printf("\n\n continue revise?(Y/N)"); choice1=getch();

if(choice1=='Y'||choice1=='y') {

flag=1;

printf("\n continue!\n");

c语言

}

else flag=0; }while(flag==1);

printf("\n press any key return\n"); bioskey(0); }

/*inquire goods message*/ inquire_message() {

int choice; do {

system("cls");

printf("\n\n **********inquire goods message***********\n\n"); printf(" 1: inquire goods according to name \n\n"); printf(" 2: inquire goods according to kind\n\n") ; printf(" 3: inquire goods according to in_num\n\n"); printf(" 0: return\n\n");

printf(" please choose (0-3): "); scanf("%d",&choice); switch(choice) {

case 1: inquire_name(); break;

case 2: inquire_kind(); break;

case 3: inquire_count(); break;

case 0: break;

}

}while(choice!=0); }

/*inquire according to name*/ inquire_name() {

int i,choice,j=0,inquire_in_price; char inquire_name[10]; system("cls");

printf("\n input the inquire goods name:");

c语言

scanf("%s",inquire_name); for(i=0;i<sum;i++) {

if(strcmp(goods[i].name,inquire_name)==0&&goods[i].num!=0) {

printf("\n --goods message-- \n"); PRINTF1; PRINTF2; PRINTF3;

}

else j++; if(j==sum)

printf("\n the good is not exist!"); bioskey(0);

} }

/* inquire accordingto kind */ inquire_kind() {int i,j=0;

char inquire_kind[10]; clrscr();

printf("\n please input the inquire goods kind:"); scanf("%s",inquire_kind); for(i=0;i<sum;i++)

if(strcmp(goods[i].kind,inquire_kind)==0&&goods[i].num!=0) {printf("\n ----goods message---- \n"); PRINTF1; PRINTF2; PRINTF3;} else j++;

if(j==sum) printf("\n this goods is not exist!"); bioskey(0); }

/*inquire according to in_num*/ inquire_count()

{int i,inquire_count,j=0; clrscr();

printf("\n please input the inquire in_num:"); scanf("%d",&inquire_count); for(i=0;i<sum;i++)

c语言

if(strcmp(goods[i].in_num,inquire_count)==0&&goods[i].num!=0) {printf("\n ----goods message----"); PRINTF1; PRINTF2; PRINTF3;} else j++;

if(j==sum) printf("\n this goods is not exist!"); bioskey(0); }

/*count goods message*/ count_message() {

int choice; do {

system("cls");

printf("\n\n **********count goods message**********\n\n"); printf(" 1: count the first kind of goods\n\n"); printf(" 2: count the secend kind of goods\n\n"); printf(" 3; count the third kind of goods\n\n"); printf(" 0: return\n\n"); printf(" please choose (0-3):"); scanf("%d",&choice); switch(choice) {

case 1: count_first_goods(); break;

case 2: count_secend_goods(); break;

case 3: count_third_goods(); break; case 0: break;

}

} while(choice!=0); }

/*count goods ji bie*/ count_first_goods() {int i,profit[MAX],j; clrscr();

for(i=0;i<sum;i++)

profit[i]=(goods[i].in_num-goods[i].amount)*(goods[i].out_price-goods[i].in_price);

c语言

printf("\n the first kind of goods : \n"); for(i=0;i<sum;i++) if(profit[i]>=500) {

PRINTF1; PRINTF2; PRINTF3;} else j++;

if(j==sum) printf("\n the goods is not exist!\n"); printf("\n press any key to return! \n"); bioskey(0); }

count_secend_goods() {int i,profit[MAX],j; system("cls");

for(i=0;i<sum;i++)

profit[i]=(goods[i].in_num-goods[i].amount)*(goods[i].out_price-goods[i].in_price); printf("\n the secend kind of goods : \n"); for(i=0;i<sum;i++)

if(profit[i]>=200&&profit[i]<500) {

PRINTF1; PRINTF2; PRINTF3;} else j++;

if(j==sum) printf("\n the goods is not exist!\n"); printf("\n press any key to return! \n"); bioskey(0); }

count_third_goods() {int i,profit[MAX],j; system("cls"); for(i=0;i<sum;i++)

profit[i]=(goods[i].in_num-goods[i].amount)*(goods[i].out_price-goods[i].in_price); printf("\n the third kind of goods : \n"); for(i=0;i<sum;i++) if(profit[i]<200) {

PRINTF1; PRINTF2; PRINTF3;} else j++;

if(j==sum) printf("\n the goods is not exist!\n"); printf("\n press any key to return! \n");

c语言

}

/*sort amount*/ sort_amount() {

struct goods *p,*q[MAX]; int i,j,k;

system("cls");

printf("\n sort amount\n");

printf("\n ----------------------------------------\n");

printf("\n rank num name kind amount\n"); p=goods;

for(i=0;i<sum;i++) q[i]=p++;

for(i=0;i<sum;i++) {

k=i;

for(j=i+1;j<sum;j++)

if(q[k]->amount<q[j]->amount) k=j; if(k!=i) {

p=q[i]; q[i]=q[k]; q[k]=p;

}

for(i=0;i<sum;i++)

printf("\n %6d %6d %8s %8s %5d\n",i+1,q[i]->num,q[i]->name,q[i]->kind,q[i]->amount);

bioskey(0); } }

/*sort profit*/ sort_profit()

{struct goods *p,*q[MAX]; int i,j,k; clrscr();

printf("\n sort profit \n");

printf(" ----------------------------------------------------\n");

printf("\n rank num name kind amount\n");

c语言

for(i=0;i<sum;i++) q[i]=p++; for(i=0;i<sum;i++) {k=i;

for(j=i+1;j<sum;j++)

if((q[k]->out_price-q[k]->in_price)<(q[j]->out_price-q[i]->in_price)) k=j; if(k!=i)

{p=q[i];q[i]=q[k];q[k]=p;} for(i=0;i<sum;i++) printf("\n %6d %6d %8s %8s ",i+1,q[i]->num,q[i]->name,q[i]->kind,q[i]->out_price-q[i]->in_price); bioskey(0); } }

/*sort goods message*/ sort_message() {

int choice; do {

system("cls");

printf("\n\n *********sort goods message*********\n\n"); printf(" 1: sort amount \n\n"); printf(" 2: sort profit\n\n"); printf(" 0: return\n\n");

printf(" please choose(0-2):"); scanf("%d",&choice); switch(choice) {

case 1: sort_amount(); break;

case 2: sort_profit(); break;

case 0: break;

}

}while(choice!=0); }

main() {

%5d\n

c语言

int choice ; char ch1;

sum=read_message(); bioskey(0); do{

clrscr();

printf("\n\n***************huan ying jin ru chao shi guan li xi tong********************\n\n");

printf(" qing xuan ze cao zuo lei xing!\n\n"); printf("

**********************************************************************\n\n");

printf(" 1:huan ying jin ru chao shi guan li zhe xi tong\n"); printf("

*********************************************************************\n\n");

printf(" 2:huan ying jin ru custom xi tong\n\n"); printf("

*********************************************************************\n\n");

printf(" 0:return\n\n"); printf("

*********************************************************************\n\n");

printf(" please choose (0-2) "); ch1=getch(); switch(ch1) { case '1':{do {

system("cls");

printf("\n\n\n ************** the system for guan li zhe***************\n");

printf("\n\n\n *****welcome to the system*****\n\n"); printf(" 1.input goods message\n\n"); printf(" 2.output goods message\n\n "); printf(" 3.renew goods message\n\n"); printf(" 4.inquire goods message\n\n" ); printf(" 5.court goods message\n\n"); printf(" 6.sort goods message\n\n"); printf(" 0.return\n\n");

printf(" please choose(0-6):"); scanf("%d",&choice); switch(choice) {

c语言

case 1: input_message(); break;

case 2: output_message(); break;

case 3: renew_message(); break;

case 4: inquire_message(); break;

case 5: count_message(); break;

case 6: sort_message(); break; case 0: break;

}

}while(choice!=0); }break;

case '2':{do{clrscr();

printf(" \n\n\n ****************the system for custom******************\n\n ");

printf(" *******welcome to the system*******\n\n "); printf(" 1:inquire goods message\n\n"); printf(" 2:sort goods message\n\n"); printf(" 0:return\n\n");

printf(" please choose (0-2):"); scanf("%d",&choice); switch(choice) {

case 1: inquire_message(); break;

case 2: sort_message(); break; case 0: break;}

}while(choice!=0); }break;

case '0':break; }

}while(ch1!='0');

save_message(sum);

printf("\n the message is saved!-(filename:goods.txt) \n"); }

the

本文来源:https://www.bwwdw.com/article/d3re.html

Top