#include "stdio.h" //需要的一些头文件
#include "stdlib.h"
#include "cstring"
#define COUNT 30 //声明商品的种类为30中,你也可以修改
//函数声明
void start(); //启动界面
void input(); //商品数据信息输入函数
void change(); //商品数据信息修改函数
void dele(); //给定指定商品名称,删除商品信息
void output(); //商品信息输出
void search(); //商品信息查找
struct MarketGoods{ //存数商品信息的结构体
char goods_id[30]; //商品编号
char goods_name[30]; //商品名称
double goods_price; //商品价格
double goods_discount;//商品折扣
int goods_amount;//商品总数目
int goods_remain;//商品剩余数目
}goods[COUNT];
int count=0; //全局变量,用于保存实际上有多少个商品
void main() //主函数
{
while(1)
start();
}
void start() //启动菜单
{
int chi;
printf(" 超市商品管理系统\n");
printf(" ********************************************\n");
printf(" 1.商品信息的录入:\n");
printf(" 2.商品信息的修改:\n");
printf(" 3.删除某个商品信息:\n");
printf(" 4.查找商品信息:\n");
printf(" 5.退出系统:\n");
printf(" ********************************************\n");
printf(" 输入你的选择: ");
scanf("%d",&chi); //根据你的选择执行相应的函数
if(chi==1) input();
else if(chi==2) change();
else if(chi==3) dele();
else if(chi==4) search();
else if(chi==5) { printf("你已经退出超市商品管理系统!\n"); exit(0);}
else { printf(" You Enter The Choice Is Not valid ! \n"); }
}
void input() //数据录入
{
char flag[20];
do{
printf("请输入你的商品信息:\n"); //录入商品的信息
printf("商品编号:");
scanf("%s",goods[count].goods_id);
printf("商品名字:");
scanf("%s",goods[count].goods_name);
printf("商品价格:");
scanf("%lf",&goods[count].goods_price);
printf("商品折扣:");
scanf("%lf",&goods[count].goods_discount);
printf("商品总数目:");
scanf("%d",&goods[count].goods_amount);
printf("商品剩余数目:");
scanf("%d",&goods[count].goods_remain);
count++; //存数的商品数加一
printf("是否继续输入数据 y是 n否 : "); //是否还想继续输入数据
scanf("%s",flag);
}while(strcmp(flag,"y")==0||strcmp(flag,"Y")==0);
output(); //调用显示商品数据
}
void change() //数据修改
{
char ch[20],a[20];
int i;
printf("\nyou sure want change goodsInfor y/n): "); //根据商品的id来修改数据
scanf("%s",ch);
if(strcmp(ch,"y")==0||strcmp(ch,"Y")==0)
{ printf("\nenter you want change goods_id:");
scanf("%s",a);
for(i=0;i
if(strcmp(goods[i].goods_id,a)==0)
{ printf("\nyou sure want change goods name(y/n): ");
scanf("%s",ch);
if(strcmp(ch,"y")==0||strcmp(ch,"Y")==0) { printf("\nname:"); scanf("%s",goods[i].goods_name);}
printf("\nyou sure want change goods price(y/n): ");
scanf("%s",ch);
if(strcmp(ch,"y")==0||strcmp(ch,"Y")==0) { printf("\nprice"); scanf("%lf",&goods[i].goods_price);}
printf("\nyou sure want goods discount(y/n): ");
scanf("%s",ch);
if(strcmp(ch,"y")==0||strcmp(ch,"Y")==0) { printf("\ndiscount"); scanf("%lf",&goods[i].goods_discount);}
printf("\nyou sure want goods amount(y/n): ");
scanf("%s",ch);
if(strcmp(ch,"y")==0||strcmp(ch,"Y")==0) { printf("\namount"); scanf("%d",&goods[i].goods_amount);}
printf("\nyou sure want goods remain(y/n): ");
scanf("%s",ch);
if(strcmp(ch,"y")==0||strcmp(ch,"Y")==0) { printf("\nremain"); scanf("%d",&goods[i].goods_remain);}
}
} }
output();
}
void dele() //数据删除
{
int i,j;
char c[20];
printf("\nenter you want delete name :\n"); //根据商品的名称来删除数据
printf("name:");
scanf("%s",c);
for(i=0;i
for(j=i;j
printf("\t\t\tyou had delete %s\n",c);
count--;
output();
}
void output() //数据输出
{
int i;
for(i=0;i
printf("%s %s %lf %lf %d %d \n",goods[i].goods_id,goods[i].goods_name,goods[i].goods_price,goods[i].goods_discount,goods[i].goods_amount,goods[i].goods_remain);
}
}
void search() //数据查找
{
int i;
char a[20],ch[10];
printf("\nenter you want look name:"); //根据商品的名称来查找数据
scanf("%s",a);
for(i=0;i
printf("%s %s %lf %lf %d %d \n",goods[i].goods_id,goods[i].goods_name,goods[i].goods_price,goods[i].goods_discount,goods[i].goods_amount,goods[i].goods_remain);
}
代码在vc++6.0测试通过 有问题可以hi我
哦