简单的商品库存管理程序 C语言
#include
#include
#define LEN sizeof(struct goods)
struct goods
{
long number;
char name[20];
int count;
struct goods* next;
};
struct goods* creat(struct goods* head); struct goods* destory(struct goods* head); struct goods* sell(long number,int count,struct goods* head);
struct goods* stock(long number,int count,struct goods* head);
void list(struct goods* head);
struct goods* del(struct goods* p1,struct goods* head); void main()
{
struct goods* head=NULL;
long number;
int count,choose;
do
{
printf("1. shu ru sang pin xin xi\n2. xiao shou\n3. chao zhao\n4. lei ju
sang pin xin xi\n5. qin chu suo you sang pin\n6. exit\n\n");
printf("input choose:\n");
scanf("%d",&choose);
if(choose==1) head=creat(head);
else if(choose==2)
{
printf("input number and count:\n");
scanf("%ld%d",&number,&count);
head=sell(number,count,head);
}
else if(choose==3)
{
printf("input number and count:\n");
scanf("%ld%d",&number,&count);
head=stock(number,count,head);
}
else if(choose==4) list(head);
else if(choose==5) head=destory(head);
}while(choose!=6);
}
struct goods* creat(struct goods* head1) {
struct goods* head=NULL,*p1,*p2;
int n=0;
if(head1) destory(head1);
p2=p1=(struct goods*)malloc(LEN);
printf("input number and name:\n");
scanf("%ld%s",&p2->number,p2->name);
p2->count=0;
while(p2->number)
{
if(n==0) head=p1;
else p1->next=p2;
p1=p2;
p2=(struct goods*)malloc(LEN);
printf("input number and name:\n");
scanf("%ld%s",&p2->number,p2->name);
p2->count=0;
n++;
}
p1->next=NULL;
return head;
}
struct goods*destory(struct goods* head) {
char word;
struct goods *p1,*p2;
p1=p2=head;
do
{
getchar();
printf("Do you really want to destory the goods system y/n\n?");
scanf("%c",&word);
}while(word!='y'&&word!='n');
if(word=='y')
{
if(p1)
do
{
p2=p1;
p1=p1->next;
free((void*)p2);
}while(p1);
printf("the goods system have been destoried!\n");
return NULL;
}
else printf("the operation of destory have been canceled\n");
return head;
}
struct goods* sell(long number,int count,struct goods* head)
{
struct goods *p1,*p2;
if(head==NULL)
{
printf("error! the system is null!\n");
system("pause");
return NULL;
}
for(p1=head;p1!=NULL;p1=p1->next)
if(p1->number==number) break;
if(p1)
{
if(p1->countcount-=count;
}
else printf("error! cannot find %ld's name\n",number);
for(p1=head;p1!=NULL;p1=p1->next)
if(p1->count==0) head=del(p1,head);
return head;
}
struct goods* stock(long number,int count,struct goods* head)
{
struct goods *p1,*p2;
for(p1=head;p1;p1=p1->next)
if(p1->number==number)
{
p1->count+=count;
break;
}
if(p1==NULL)
{
p2=(struct goods*)malloc(LEN);
printf("input name:\n");
getchar();
gets(p2->name);
p2->number=number;
p2->count=count;
p2->next=head;
head=p2;
}
return head;
}
void list(struct goods* head)
{
if(head)
do
{
printf("%ld %s %d\n",head->number,head->name,head->count);
head=head->next;
}while(head);
else printf("the system is null!\n");
}
struct goods* del(struct goods* p1,struct goods* head)
{
struct goods *p2;
if(p1==head) head=head->next;
else if(p1==NULL) return head;
else
{
for(p2=head;;p2=p2->next)
if(p2->next==p1)
{
p2->next=p1->next;
break;
}
}
free((void*)p1);
return head;
}
本文档为【简单的商品库存管理程序 C语言】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑,
图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。