标题:[求助]帮个忙,试一下程序!
只看楼主
gang
Rank: 1
等 级:新手上路
帖 子:31
专家分:0
注 册:2006-2-28
 问题点数:0 回复次数:3 
[求助]帮个忙,试一下程序!

大家帮个忙,最近抄了个程序,是用C语言编的,然后我用VC++编译,编译的时候出现了很多错误,然后在论坛上问了问,改了改,总算改得差不多了,现在编译的时候已经是:0 erroe,0 warning
可是运行的时候选第一项输入信息的时候在输入入到名字的时候去总是会出现错误信息说该指令引用的内存不能为written,然后就不行了,要强制退出了!请问这到底是什么原因呢?
程序改得很乱,大家凑合着看吧,有什么意见就请麻烦尽量提出来,毕竟我是第一次!先谢过了!
#include<stdio.h>
#include<string>
#include<stdlib.h>
using namespace std;
#define N 3
#define PAGE 2
#define PRINT1 printf("----------------------\n")
#define PRINT2 printf("商品号--商品名称--商品种类--销售价格--生产日期(年-月-日)--保质期\n")


int sum; /*用来记录商品数目*/

/*日期结构体类型*/
typedef struct datetime
{ int year;
int month;
int date;
}in_time,pro_time;

/*商品结构体类型*/
struct goods_type
{ 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 datetime in_time;
struct datetime pro_time;
char factory[10];
int save_day;
int profit;
}goods[20]; /*存放MAX种商品记录的结构体数组*/


/*保存信息*/
save_message(int sum)
{ FILE *fp;
int i;
if((fp=fopen("supermarket.txt","wb"))==NULL)
{ printf("读文件错误!\n");
}
for(i=0;i<sum;i++)
if(fwrite(&goods[i],sizeof(struct goods_type),1,fp)!=1)
printf("写文件错误\n");
fclose(fp);
return 0;}


/*输入模块*/
void input_message(struct goods_type goods[20],int sum)
{ int i=0,s=20;

printf("\n\n 录入商品信息 (最多%d种)\n",s);
printf(" -------------------------------\n");
do
{printf("\n 第%d种商品",i+1);
printf("\n 商品号:");
scanf("%d",&goods[i].num);
if(goods[i].num==0) break;
printf("\n 商品名称:");
scanf("%s",goods[i].name[10]);
printf("\n 商品类别:");
scanf("%s",goods[i].kind[10]);
printf("\n 商品总量:");
scanf("%d",&goods[i].amount);
printf("\n 商品上限:");
scanf("%d",&goods[i].goods_up);
printf("\n 商品下限:");
scanf("%d",&goods[i].goods_down);
printf("\n 进货价格:");
scanf("%d",&goods[i].in_price);
printf("\n 销售价格:");
scanf("%d",&goods[i].out_price);
printf("\n 进货数量:");
scanf("%d",&goods[i].in_num);
printf("\n 进货日期(yyyy-mm-dd):");
scanf("%d%d%d",&goods[i].in_time.year,&goods[i].in_time.month,&goods[i].in_time.date);
printf("\n 生产日期(yyyy-mm-dd):");
scanf("%d%d%d",&goods[i].pro_time.year,&goods[i].pro_time.month,&goods[i].pro_time.date);
printf("\n 生产厂家:");
scanf("%s",goods[i].factory);
printf("\n 保质期:");
scanf("%d",&goods[i].save_day);
i++;
}while(i<20);
printf("\n --%d种商品信息输入完毕!--\n",i);
sum=i;
printf("\n 按任意键返回主菜单!");
getchar();
}


/*读取信息*/
int read_message(struct goods_type goods[20])
{ FILE *fp;
int i=0;
if((fp=fopen("supermarket.txt","rb"))==NULL)
{ printf("\n\n****暂时还没有任何库存信息,按任意键进入主菜单选择基本信息的录入!****\n");

}
while(feof(fp)!=1)
{ fread(&goods[i],sizeof(struct goods_type),1,fp);
if(goods[i].num==0)break;
else i++;
}
fclose(fp);
return i;
}


/*输出模块*/
void output_message(struct goods_type goods[20])
{ int i=0,j=0,count=0,page=1;

printf("\n\n --商品信息表-- 第%d页\n\n",page);
PRINT2;
PRINT1;
do
{ if(goods[i].num!=0)
{ j++;
if(j%PAGE!=0)
{ printf("%4d%8s%8s%8d%15d-%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.date,goods[i].save_day);
PRINT1;
}
else
{ printf("%4d%8s%8s%8d%15d-%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.date,goods[i].save_day);
PRINT1;
if(goods[i+1].num!=0)
{ printf("按任意键继续!");
getchar();

printf("\n\n --商品信息表-- 第%d页\n\n",++page);
PRINT2;
PRINT1;
}
}
}
i++;
}while(goods[i].num!=0);
printf("按任意键返回主菜单!");
getchar();
}


/*添加商品信息*/
void insert_message(struct goods_type goods[20],int sum)
{ int i=sum,flag=0;
char choice;

printf("\n\n 添加一种新商品\n");
printf(" --------------------------------\n");
do
{goods[i].num=++sum;
printf("\n 新商品号:%d",goods[i].num);
printf("\n 商品名称:");
scanf("%s",goods[i].name);
printf("\n 商品类别:");
scanf("%s",goods[i].kind);
printf("\n 商品总量:");
scanf("%d",&goods[i].amount);
printf("\n 商品上限:");
scanf("%d",&goods[i].goods_up);
printf("\n 商品下限:");
scanf("%d",&goods[i].goods_down);
printf("\n 进货价格:");
scanf("%d",&goods[i].in_price);
printf("\n 销售价格:");
scanf("%d",&goods[i].out_price);
printf("\n 进货数量:");
scanf("%d",&goods[i].in_num);
printf("\n 进货日期(yyyymmdd):");
scanf("%d-%d-%d",&goods[i].in_time.year,
&goods[i].in_time.month,
&goods[i].in_time.date);
printf("\n 生产日期(yyyymmdd):");
scanf("%d-%d-%d",&goods[i].pro_time.year,
&goods[i].pro_time.month,
&goods[i].pro_time.date);
printf("\n 生产厂家:");
scanf("%s",goods[i].factory);
printf("\n 保质期:");
scanf("%d",&goods[i].save_day);
printf("\n 要继续吗?(Y/N)");
choice=getchar();
if (choice=='y'||choice=='Y')
{ printf("\n 继续!\n");
i++;
flag=1;
}
else flag=0;
}while(flag==1);
printf("\n 按任意键返回主菜单!");
getchar();
}


/*删除商品信息*/
void del_message()
{;}


/*修改模块*/
void revise_message(struct goods_type goods[20])
{ int i=0,choice,revise_num,flag;
do
{
printf("\n 输入要修改的商品号:");
scanf("%d",&revise_num);
for(i=0;i<sum;i++)
if(goods[i].num==revise_num)
{ printf("\n --商品信息--\n");
PRINT1;
PRINT2;
printf("%4d%8s%8s%8d%15d-%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.date,goods[i].save_day);
printf("\n 你要修改哪一项?\n");
printf("\n 1.名称\n");
printf("\n 2.种类\n");
printf("\n 3.销售价格\n");
printf("\n 4.生产日期\n");
printf("\n 5.保质期\n");
scanf("%d",&choice);
switch(choice)
{case 1:printf("\n 输入修改后的名称:");
scanf("%s",&goods[i].name);break;
case 2:printf("\n 输入修改后的种类:");
scanf("%s",&goods[i].kind);break;
case 3:printf("\n 输入修改后的销售价格:");
scanf("%d",&goods[i].out_price);break;
case 4:printf("\n 输入修改后的生产日期:");
scanf("%d-%d-%d",&goods[i].pro_time.year,&goods[i].pro_time.month,&goods[i].pro_time.date);
break;
case 5:printf("\n 输入修改后的保质期:");
scanf("%d",&goods[i].save_day);break;
}
PRINT1;
PRINT2;
printf("%4d%8s%8s%8d%15d-%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.date,goods[i].save_day);
break;
}
if(i==sum)
{ printf("\n 该商品不存在!");
getchar();
}
printf("\n\n 继续修改吗?(Y/N)");
choice=getchar();
if(choice=='Y'||choice=='y')
{ flag=1;
printf("\n 继续!\n");
}
else flag=0;
}while(flag==1);
printf("\n 按任意键返回主菜单!");
getchar();
}


/*更新模块*/
void renew_message(struct goods_type goods[20])
{ int choice;
do
{
printf("\n\n ************更新商品信息*************\n\n");
printf(" 1.添加商品信息\n\n");
printf(" 2.删除商品信息\n\n");
printf(" 3.修改商品信息\n\n");
printf(" 0.返回主菜单\n\n");
printf(" 请选择(0-3):");
scanf("%d",&choice);
switch(choice)
{case 1: insert_message(goods,sum);break;
case 2: del_message();break;
case 3: revise_message(goods);break;
case 0: break;
}
}while(choice!=0);
}


/*按名称查询*/
void inquire_name(struct goods_type goods[20],int sum)
{ int i,j=0;
char inquire_name[10];

printf("\n 输入要查询的商品名称:");
scanf("%s",inquire_name);
for(i=0;i<sum;i++)
if(strcmp(goods[i].name,inquire_name)==0&&goods[i].num!=0)
{ printf("\n ---商品信息---\n");
PRINT1;
PRINT2;
printf("%4d%8s%8s%8d%15d-%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.date,goods[i].save_day);
}
else j++;
if(j==sum)printf("\n 该商品不存在!");
getchar();
}


/*按类别查询*/
void inquire_kind()
{ ;}


/*按进货量和进货时间查询*/
void inquire_count_time()
{ ;}

/*查询模块*/
void inquire_message()
{ int choice;
do
{
printf("\n\n *********查询商品信息**********\n\n");
printf(" 1.按商品名称查询\n\n");
printf(" 2.按商品类别查询\n\n");
printf(" 3.按商品名称和进货价格查询\n\n");
printf(" 0.返回主菜单\n\n");
printf(" 请选择(0~3):");
scanf("%d",&choice);
switch(choice)
{case 1:inquire_name(goods,sum);break;
case 2:inquire_kind();break;
case 3:inquire_count_time();break;
case 0:break;
}
}while(choice!=0);
}

/*统计利润*/
void count_profit(struct goods_type goods[20])
{ int i,j=0,count_num=0,profit=0;


printf("\n 输入要统计的商品号:");
scanf("%d",&count_num);
for(i=0;i<sum;i++)
if(goods[i].num==count_num)
{profit=goods[i].out_price-goods[i].in_price;
printf("\n 商品利润");
printf("\n ------------------\n");
printf("\n 商品号 利润");
printf("\n%25d13d\n",goods[i].num,profit);
}
else j++;
if(j==sum) printf("\n 该商品不存在!");
getchar();
}

/*统计进货量*/
void count_in_amount()
{ ;}


/*统计库存量*/
void count_full()
{ ;}


/*统计模块*/
void count_message()
{ int choice;
do
{
printf("\n\n\n *********统计商品信息*********\n\n");
printf(" 1.统计某商品的利润\n\n");
printf(" 2.统计某商品的进货量\n\n");
printf(" 3.统计同种名称不同货号商品库存量\n\n");
printf(" 4.返回主菜单\n\n");
printf(" 请选择(0~3):");
scanf("%d",&choice);
switch(choice)
{ case 1: count_profit(goods);break;
case 2:count_in_amount();break;
case 3:count_full();break;
case 0:break;
}
}while(choice!=0);
}

/*库存排行*/
void sort_amount(struct goods_type goods[20])
{ struct goods_type *p,*q[20];
int i,j,k;

printf("\n 库存排行\n");
printf("-----------------------------------------\n");
printf("\n 排名 商品号 商品名称 商品类别 库存量\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%18d%6d%8s%11s%10d\n",i+1,q[i]->num,q[i]->name,q[i]->kind,q[i]->amount);
getchar();
}


/*利润排行*/
void sort_profit()
{ ;}


/*销售量排行*/
void sort_out_amount()
{ ;}


/*排序模块*/
void sort_message()
{ int choice;
do
{
printf("\n\n\n *********商品排行信息***********\n\n");
printf(" 1.库存量排行\n\n");
printf(" 2.利润排行\n");
printf(" 3.销售量排行\n\n");
printf(" 0.返回主菜单\n\n");
printf(" 请选择(0~3):");
scanf("%d",&choice);
switch(choice)
{ case 1:sort_amount(goods);break;
case 2:sort_profit();break;
case 3:sort_out_amount();break;
case 0:break;
}
}while(choice!=0);
}


/*主程序*/

void main()
{ int choice;
do
{
printf("\n\n\n *********超市管理系统********\n\n");
printf(" 1.录入商品信息\n\n");
printf(" 2.打印商品信息\n\n");
printf(" 3.更新商品信息\n\n");
printf(" 4.查询商品信息\n\n");
printf(" 5.统计商品信息\n\n");
printf(" 6.商品排行信息\n\n");
printf(" 0.退出系统\n\n");
printf(" 请选择(0~6):");
scanf("%d",&choice);
switch(choice)
{case 1:input_message(goods,sum);break;
case 2:output_message(goods);break;
case 3:renew_message(goods);break;
case 4:inquire_message();break;
case 5:count_message();break;
case 6:sort_message();break;
case 0:break;
}
}while(choice!=0);
save_message(sum);
printf("\n-以上商品信息已保存!-(文件名:supermaket.txt)\n");
}

搜索更多相关主题的帖子: include warning written C语言 names 
2006-03-04 00:19
zinking
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:35
帖 子:916
专家分:0
注 册:2004-12-5
得分:0 

#include<cstdio>
#include<string>
#include<cstdlib>
using namespace std;
#define N 3
#define PAGE 2
#define PRINT1 printf("----------------------\n")
#define PRINT2 printf("商品号--商品名称--商品种类--销售价格--生产日期(年-月-日)--保质期\n")


int sum; /*用来记录商品数目*/

/*日期结构体类型*/
typedef struct datetime
{ int year;
int month;
int date;
}in_time,pro_time;

/*商品结构体类型*/
struct goods_type
{ 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 datetime in_time;
struct datetime pro_time;
char factory[10];
int save_day;
int profit;
}goods[20]; /*存放MAX种商品记录的结构体数组*/


/*保存信息*/
int save_message(int sum)
{ FILE *fp;
int i;
if((fp=fopen("supermarket.txt","wb"))==NULL)
{ printf("读文件错误!\n");
}
for(i=0;i<sum;i++)
if(fwrite(&goods[i],sizeof(struct goods_type),1,fp)!=1)
printf("写文件错误\n");
fclose(fp);
return 0;}


/*输入模块*/
void input_message(struct goods_type goods[20],int sum)
{ int i=0,s=20;

printf("\n\n 录入商品信息 (最多%d种)\n",s);
printf(" -------------------------------\n");
do
{printf("\n 第%d种商品",i+1);
printf("\n 商品号:");
scanf("%d",&goods[i].num);
if(goods[i].num==0) break;
printf("\n 商品名称:");
scanf("%s",goods[i].name[10]);
printf("\n 商品类别:");
scanf("%s",goods[i].kind[10]);
printf("\n 商品总量:");
scanf("%d",&goods[i].amount);
printf("\n 商品上限:");
scanf("%d",&goods[i].goods_up);
printf("\n 商品下限:");
scanf("%d",&goods[i].goods_down);
printf("\n 进货价格:");
scanf("%d",&goods[i].in_price);
printf("\n 销售价格:");
scanf("%d",&goods[i].out_price);
printf("\n 进货数量:");
scanf("%d",&goods[i].in_num);
printf("\n 进货日期(yyyy-mm-dd):");
scanf("%d%d%d",&goods[i].in_time.year,&goods[i].in_time.month,&goods[i].in_time.date);
printf("\n 生产日期(yyyy-mm-dd):");
scanf("%d%d%d",&goods[i].pro_time.year,&goods[i].pro_time.month,&goods[i].pro_time.date);
printf("\n 生产厂家:");
scanf("%s",goods[i].factory);
printf("\n 保质期:");
scanf("%d",&goods[i].save_day);
i++;
}while(i<20);
printf("\n --%d种商品信息输入完毕!--\n",i);
sum=i;
printf("\n 按任意键返回主菜单!");
getchar();
}


/*读取信息*/
int read_message(struct goods_type goods[20])
{ FILE *fp;
int i=0;
if((fp=fopen("supermarket.txt","rb"))==NULL)
{ printf("\n\n****暂时还没有任何库存信息,按任意键进入主菜单选择基本信息的录入!****\n");

}
while(feof(fp)!=1)
{ fread(&goods[i],sizeof(struct goods_type),1,fp);
if(goods[i].num==0)break;
else i++;
}
fclose(fp);
return i;
}


/*输出模块*/
void output_message(struct goods_type goods[20])
{ int i=0,j=0,count=0,page=1;

printf("\n\n --商品信息表-- 第%d页\n\n",page);
PRINT2;
PRINT1;
do
{ if(goods[i].num!=0)
{ j++;
if(j%PAGE!=0)
{ printf("%4d%8s%8s%8d%15d-%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.date,goods[i].save_day);
PRINT1;
}
else
{ printf("%4d%8s%8s%8d%15d-%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.date,goods[i].save_day);
PRINT1;
if(goods[i+1].num!=0)
{ printf("按任意键继续!");
getchar();

printf("\n\n --商品信息表-- 第%d页\n\n",++page);
PRINT2;
PRINT1;
}
}
}
i++;
}while(goods[i].num!=0);
printf("按任意键返回主菜单!");
getchar();
}


/*添加商品信息*/
void insert_message(struct goods_type goods[20],int sum)
{ int i=sum,flag=0;
char choice;

printf("\n\n 添加一种新商品\n");
printf(" --------------------------------\n");
do
{goods[i].num=++sum;
printf("\n 新商品号:%d",goods[i].num);
printf("\n 商品名称:");
scanf("%s",goods[i].name);
printf("\n 商品类别:");
scanf("%s",goods[i].kind);
printf("\n 商品总量:");
scanf("%d",&goods[i].amount);
printf("\n 商品上限:");
scanf("%d",&goods[i].goods_up);
printf("\n 商品下限:");
scanf("%d",&goods[i].goods_down);
printf("\n 进货价格:");
scanf("%d",&goods[i].in_price);
printf("\n 销售价格:");
scanf("%d",&goods[i].out_price);
printf("\n 进货数量:");
scanf("%d",&goods[i].in_num);
printf("\n 进货日期(yyyymmdd):");
scanf("%d-%d-%d",&goods[i].in_time.year,
&goods[i].in_time.month,
&goods[i].in_time.date);
printf("\n 生产日期(yyyymmdd):");
scanf("%d-%d-%d",&goods[i].pro_time.year,
&goods[i].pro_time.month,
&goods[i].pro_time.date);
printf("\n 生产厂家:");
scanf("%s",goods[i].factory);
printf("\n 保质期:");
scanf("%d",&goods[i].save_day);
printf("\n 要继续吗?(Y/N)");
choice=getchar();
if (choice=='y'||choice=='Y')
{ printf("\n 继续!\n");
i++;
flag=1;
}
else flag=0;
}while(flag==1);
printf("\n 按任意键返回主菜单!");
getchar();
}


/*删除商品信息*/
void del_message()
{;}


/*修改模块*/
void revise_message(struct goods_type goods[20])
{ int i=0,choice,revise_num,flag;
do
{
printf("\n 输入要修改的商品号:");
scanf("%d",&revise_num);
for(i=0;i<sum;i++)
if(goods[i].num==revise_num)
{ printf("\n --商品信息--\n");
PRINT1;
PRINT2;
printf("%4d%8s%8s%8d%15d-%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.date,goods[i].save_day);
printf("\n 你要修改哪一项?\n");
printf("\n 1.名称\n");
printf("\n 2.种类\n");
printf("\n 3.销售价格\n");
printf("\n 4.生产日期\n");
printf("\n 5.保质期\n");
scanf("%d",&choice);
switch(choice)
{case 1:printf("\n 输入修改后的名称:");
scanf("%s",&goods[i].name);break;
case 2:printf("\n 输入修改后的种类:");
scanf("%s",&goods[i].kind);break;
case 3:printf("\n 输入修改后的销售价格:");
scanf("%d",&goods[i].out_price);break;
case 4:printf("\n 输入修改后的生产日期:");
scanf("%d-%d-%d",&goods[i].pro_time.year,&goods[i].pro_time.month,&goods[i].pro_time.date);
break;
case 5:printf("\n 输入修改后的保质期:");
scanf("%d",&goods[i].save_day);break;
}
PRINT1;
PRINT2;
printf("%4d%8s%8s%8d%15d-%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.date,goods[i].save_day);
break;
}
if(i==sum)
{ printf("\n 该商品不存在!");
getchar();
}
printf("\n\n 继续修改吗?(Y/N)");
choice=getchar();
if(choice=='Y'||choice=='y')
{ flag=1;
printf("\n 继续!\n");
}
else flag=0;
}while(flag==1);
printf("\n 按任意键返回主菜单!");
getchar();
}


/*更新模块*/
void renew_message(struct goods_type goods[20])
{ int choice;
do
{
printf("\n\n ************更新商品信息*************\n\n");
printf(" 1.添加商品信息\n\n");
printf(" 2.删除商品信息\n\n");
printf(" 3.修改商品信息\n\n");
printf(" 0.返回主菜单\n\n");
printf(" 请选择(0-3):");
scanf("%d",&choice);
switch(choice)
{case 1: insert_message(goods,sum);break;
case 2: del_message();break;
case 3: revise_message(goods);break;
case 0: break;
}
}while(choice!=0);
}


/*按名称查询*/
void inquire_name(struct goods_type goods[20],int sum)
{ int i,j=0;
char inquire_name[10];

printf("\n 输入要查询的商品名称:");
scanf("%s",inquire_name);
for(i=0;i<sum;i++)
if(strcmp(goods[i].name,inquire_name)==0&&goods[i].num!=0)
{ printf("\n ---商品信息---\n");
PRINT1;
PRINT2;
printf("%4d%8s%8s%8d%15d-%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.date,goods[i].save_day);
}
else j++;
if(j==sum)printf("\n 该商品不存在!");
getchar();
}


/*按类别查询*/
void inquire_kind()
{ ;}


/*按进货量和进货时间查询*/
void inquire_count_time()
{ ;}

/*查询模块*/
void inquire_message()
{ int choice;
do
{
printf("\n\n *********查询商品信息**********\n\n");
printf(" 1.按商品名称查询\n\n");
printf(" 2.按商品类别查询\n\n");
printf(" 3.按商品名称和进货价格查询\n\n");
printf(" 0.返回主菜单\n\n");
printf(" 请选择(0~3):");
scanf("%d",&choice);
switch(choice)
{case 1:inquire_name(goods,sum);break;
case 2:inquire_kind();break;
case 3:inquire_count_time();break;
case 0:break;
}
}while(choice!=0);
}

/*统计利润*/
void count_profit(struct goods_type goods[20])
{ int i,j=0,count_num=0,profit=0;


printf("\n 输入要统计的商品号:");
scanf("%d",&count_num);
for(i=0;i<sum;i++)
if(goods[i].num==count_num)
{profit=goods[i].out_price-goods[i].in_price;
printf("\n 商品利润");
printf("\n ------------------\n");
printf("\n 商品号 利润");
printf("\n%25d13d\n",goods[i].num,profit);
}
else j++;
if(j==sum) printf("\n 该商品不存在!");
getchar();
}

/*统计进货量*/
void count_in_amount()
{ ;}


/*统计库存量*/
void count_full()
{ ;}


/*统计模块*/
void count_message()
{ int choice;
do
{
printf("\n\n\n *********统计商品信息*********\n\n");
printf(" 1.统计某商品的利润\n\n");
printf(" 2.统计某商品的进货量\n\n");
printf(" 3.统计同种名称不同货号商品库存量\n\n");
printf(" 4.返回主菜单\n\n");
printf(" 请选择(0~3):");
scanf("%d",&choice);
switch(choice)
{ case 1: count_profit(goods);break;
case 2:count_in_amount();break;
case 3:count_full();break;
case 0:break;
}
}while(choice!=0);
}

/*库存排行*/
void sort_amount(struct goods_type goods[20])
{ struct goods_type *p,*q[20];
int i,j,k;

printf("\n 库存排行\n");
printf("-----------------------------------------\n");
printf("\n 排名 商品号 商品名称 商品类别 库存量\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%18d%6d%8s%11s%10d\n",i+1,q[i]->num,q[i]->name,q[i]->kind,q[i]->amount);
getchar();
}


/*利润排行*/
void sort_profit()
{ ;}


/*销售量排行*/
void sort_out_amount()
{ ;}


/*排序模块*/
void sort_message()
{ int choice;
do
{
printf("\n\n\n *********商品排行信息***********\n\n");
printf(" 1.库存量排行\n\n");
printf(" 2.利润排行\n");
printf(" 3.销售量排行\n\n");
printf(" 0.返回主菜单\n\n");
printf(" 请选择(0~3):");
scanf("%d",&choice);
switch(choice)
{ case 1:sort_amount(goods);break;
case 2:sort_profit();break;
case 3:sort_out_amount();break;
case 0:break;
}
}while(choice!=0);
}


/*主程序*/

int main()
{ int choice;
do
{
printf("\n\n\n *********超市管理系统********\n\n");
printf(" 1.录入商品信息\n\n");
printf(" 2.打印商品信息\n\n");
printf(" 3.更新商品信息\n\n");
printf(" 4.查询商品信息\n\n");
printf(" 5.统计商品信息\n\n");
printf(" 6.商品排行信息\n\n");
printf(" 0.退出系统\n\n");
printf(" 请选择(0~6):");
scanf("%d",&choice);
switch(choice)
{case 1:input_message(goods,sum);break;
case 2:output_message(goods);break;
case 3:renew_message(goods);break;
case 4:inquire_message();break;
case 5:count_message();break;
case 6:sort_message();break;
case 0:break;
}
}while(choice!=0);
save_message(sum);
printf("\n-以上商品信息已保存!-(文件名:supermaket.txt)\n");
system("pause");
return 0;
}

修改了头文件还有一个函数的返回类型
能编译通过了
能运行
但是运行的时候不稳定
用c写这种程序不明智不容易维护
应该用c++写这样不管那个方面都好做些对巴!


http://kongfuziandlife. http://codeanddesign.
2006-03-04 11:38
gang
Rank: 1
等 级:新手上路
帖 子:31
专家分:0
注 册:2006-2-28
得分:0 

用C++写的话差不多也是着样子吧,还是用那个用更好的写法?望指点!谢谢!


一个来自华南师大通信工程的菜鸟,只学过一点学校教的C++和自学了一点C,大家不要笑他!哈哈……
2006-03-04 12:19
gang
Rank: 1
等 级:新手上路
帖 子:31
专家分:0
注 册:2006-2-28
得分:0 

对不起,还有一个白痴问题,请问在C++里面怎么用getchar(),怎么程序里的的getchar()没有反应呢?试了很久还是想不出什么办法!


一个来自华南师大通信工程的菜鸟,只学过一点学校教的C++和自学了一点C,大家不要笑他!哈哈……
2006-03-05 00:42



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-48340-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.702409 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved