C语言商品信息管理系统

#include
#include
struct shmas
{
int no;
char name[40];
float jinjia;
float shoujia;
int jinhuo;
int xiaoshou;
int shengyu;
struct shmas *next;
};
struct shmas *creat(int a);
void print(struct shmas *he,int b,int w);
struct shmas *insert(struct shmas *hi,struct shmas *hq);
struct shmas *del(struct shmas *hv,int v);
int main()
{
int n,x,o,z,l,u;
struct shmas *h1,*h2,*h3;
printf("***************************欢迎使用商品管理系统!!***************************\n");
printf("首先请先创造一个商品文档\n");
printf("请输入商品种类的数目:");
scanf("%d",&n);
h1=creat(n); //在这里开始建立一个大的循环,还需一个清屏函数
do
{
system("cls");
h3=h1;
while(h3->next!=0)
{
h3=h3->next;
}
print(h1,h3->no,0);
printf("请选择你要进行的功能(按下与之对应的数字键):\n");
printf("1、添加新的商品\n");
printf("2、删除已有的商品\n");
printf("3、统计销售状况\n");
printf("4、显示商品的信息\n");
printf("5、退出系统\n");
scanf("%d",&x);
switch(x)
{
case 1:
printf("请输入要添加商品种类的数目:");
scanf("%d",&o);
h2=creat(o);
h1=insert(h2,h1);
break;
case 2:
printf("请输入要删除商品种类的编号:");
scanf("%d",&z);
h1=del(h1,z);
break;
case 3:
print(h1,h3->no,1);
printf("按任意键数字键继续系统运行:\n");
scanf("%d",&l);
switch(l)
{
case 1:
default:
break;
}
printf("继续运行程序。");
break;
case 4:
print(h1,h3->no,2);
printf("按任意键数字键继续系统运行:\n");
scanf("%d",&u);
switch(u)
{
case 1:
default:
break;
}
printf("继续运行程序。");
break;
case 5:
exit(0);
}
}
while(1);
return 0;
}
struct shmas *creat(int a)
{
struct shmas *p1,*p2,*head;
int i;
static int xno=1;
float x,*y;
y=&x;
x=*y;
head=(struct shmas *)malloc(sizeof(struct shmas));
p2=(struct shmas *)malloc(sizeof(struct shmas));
printf("请输入商品的信息(名称、进价、售价、进货量、销售量):\n");
for(i=1;i<=a;i++)
{
p1=(struct shmas *)malloc(sizeof(struct shmas));
if(i==1)
{
head->next=p1;
}
flushall();
scanf("%s%f%f%d%d",p1->name,&p1->jinjia,&p1->shoujia,&p1->jinhuo,&p1->xiaoshou);
p1->no=xno++;
p1->shengyu=p1->jinhuo-p1->xiaoshou;
p1->next=0;
p2->next=p1;
p2=p1;
}
return head;

}
void print(struct shmas *he,int b,int w)
{
printf("下列是商品的编号和名称:\n");
struct shmas *p3;
p3=he;
while(p3->next!=0)
{
p3=p3->next;
if(w==0)
{
printf("%d号商品*********************%s\n",p3->no,p3->name);
}
if(w==1)
{
printf("%d号商品%s的销售量是***********%d\n",p3->no,p3->name,p3->xiaoshou);


}
if(w==2)
{
printf("编号:%d 名称:%s 进价:%f 售价:%f 进货量:%d 销售量:%d 剩余量:%d",p3->no,p3->name,p3->jinjia,p3->shoujia,p3->jinhuo,p3->xiaoshou,p3->shengyu);
}
}
}
struct shmas *insert(struct shmas *hi,struct shmas *hq)
{
struct shmas *hm;
hm=hq;
while(hq->next!=0)
{
hq=hq->next;
}
hq->next=hi->next;
return hm;
}
struct shmas *del(struct shmas *hv,int v)
{
struct shmas *hg,*ht;
hg=hv;
do
{
ht=hv;
hv=hv->next;
}
while(hv->no!=v);
ht->next=hv->next;
return hg;
}

相关文档
最新文档