简单的商品库存管理程序 C语言

玛丽莲梦兔
914次浏览
2020年08月01日 05:53
最佳经验
本文由作者推荐

潭影空人心-穷追不舍的意思

#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
2. xiao shou
3. chao zhao
4. lei ju sang pin xin xi
5. qin chu suo you sang pin
6. exit

");
printf("input choose:
");
scanf("%d",&choose);
if(choose==1) head=creat(head);
else if(choose==2)
{
printf("input number and count:
");
scanf("%ld%d",&number,&count);
head=sell(number,count,head);
}
else if(choose==3)
{
printf("input number and count:
");
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:
");
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:
");
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
?");
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!
");
return NULL;
}
else printf("the operation of destory have been canceled
");
return h
ead;
}
struct goods* sell(long number,int count,struct goods* head)
{
struct goods *p1,*p2;
if(head==NULL)
{
printf("error! the system is null!
");
system("pause");
return NULL;
}
for(p1=head;p1!=NULL;p1=p1->next)
if(p1->number==number) break;
if(p1)
{
if(p1->count{
printf("The count is too less!
");
return head;
}
else p1->count-=count;
}
else printf("error! cannot find %ld's name
",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:
");
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
",head->number,head->name,head->count);
head=head->next;
}while(head);
else printf("the system is null!
");
}
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;
}

小时代kitty-冉冉读音


看用英语怎么说-大理岩


春秋之义-貂丁


湄公河在哪-緌怎么读


一个苹果的热量是多少-修明


什么是奇数和偶数-川芎怎么读


海底两万里每章概括-曲肱饮水


损塞-坚实的反义词