服装管理系统
数据录入
void save_inf(cloth head)
{
Node *stu;
FILE *fp;
if(!(fp=fopen("ljh.txt","w")))
{
printf("写文件失败,按任意键退出\n");
getch();
exit(1);
}
for(stu=head->next;stu!=NULL;stu=stu->next)
{
fprintf(fp,"%d\t%s\t%d\t%d\n",stu->num,stu->size,stu->prize,stu->amount);
}
printf("\n文件已保存,按任意键退出\n");
fclose(fp);
getch();
}
数据读写
cloth read_inf()
{
Node *head,*r,*stu;
FILE *fp;
if(!(fp=fopen("ljh.txt","r")))
{
printf("\n读文件出错,请重新输入!\n");
exit(0);
}
rewind(fp);
head=(Node *)malloc(sizeof(Node));
head->next=NULL;
r=head;
while(!feof(fp))
{
stu=(Node *)malloc(sizeof(Node));
fscanf(fp,"%d\t%s\t%d\t%d\n",&stu->num,stu->size,&stu->prize,&stu->amount);
r->next=stu;
r=stu;
}
r->next=NULL;
fclose(fp);
printf("\n文件信息以正确读出,按任意键返回主菜单!\n");
getch();
return head;
}
密码加密功能
printf("请输入密码:(最多10位)");
d=1;
while(d)
{
secret[0]='\0';
while(i<10)
{
c=getch();
if(c==13)
break;
if(c==8&&i>0)
{
printf("\b \b");
secret[i--]='\0';
continue;
}
if(i==0&&c==8)
continue;
secret[i++]=c;
if(c!=8)
putchar('*');
}
secret[i]='\0';
i=0;
if(strcmp(secret,"888")==0)
{
printf("\n验证通过!请按Enter键进入!\n");
d=0;
}
else
{
printf("\n验证失败!请重新输入密码!");
printf("\n密码:");
}
}
数据修改
cloth Revise(cloth head,int num)
{
int snum,a=1,k=1;
char y='Y';
Node *p;
p=head->next;
if(p==NULL)
{
printf("请去录入服装信息!\n");
return head;
}
while(1)
{
if(p->num!=num&&p!=NULL)
p=p->next;
else
break;
if(p==NULL)
{
printf("无此服装!\n");
return head;
}
}
printf(" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
printf(" 1-服装价格 2-服装尺码 3-服装库存\n");
printf(" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
printf("\n");
while(y=='Y'||y=='y')
{
printf("\n请输入你想修改的服装数据编号:");
scanf("%d",&snum);
switch(snum)
{
case 1:
printf("\nprize:");
scanf("%d",&p->prize);
break;
case 2:
printf("\nsize:");
scanf("%s",p->size);
break;
case 3:
printf("\namount:");
scanf("%d",&p->amount);
break;
}
printf("是否继续修改此服装数据(Y/N):");
y=getche();
}
return head;
}
数据插入
cloth Insert(cloth head,int pos)
{
int k=0,k1,k2=0;
Node *p,*s,*t,*p1=head;
p=head;
t=head->next;
while(1)
{
if(k2)
{
printf("无此节点!请重新输入插入节点位置:");
printf("num:");
scanf("%d",&pos);
}
while(p->next&&k<pos-1)
{
p=p->next;
k++;
}
if(k!=pos-1)
{
p=head;
k=0;
k2=1;
}
else
break;
}
printf("请输入待添加的服装编号:\n");
s=(Node *)malloc(sizeof(Node));
while(1)
{
printf("num:");
scanf("%d",&k1);
while(t)
{
if(t->num!=k1)
{
t=t->next;
}
else
{
printf("编号重复!请重新输入编号:");
break;
}
}
if(t==NULL)
break;
t=head->next;
}
s->num=k1;
getchar();
printf("\nsize:");
scanf("%s",s->size);
getchar();
printf("\nprize:");
scanf("%d",&s->prize);
getchar();
printf("\namount:");
scanf("%d",&s->amount);
getchar();
s->next=p->next;
p->next=s;
printf("插入成功\n");
return head;
}
数据删除
cloth Delete(cloth head,int pos)
{
Node *p,*s;
s=head;
p=head->next;
if(p==NULL)
{
printf("请先去录入信息!");
return head;
}
else
{
while(1)
{
if(p->num!=pos)
{
s=s->next;
p=p->next;
if(p==NULL)
{
printf("无此服装!\n");
return head;
}
}
else
{
s->next=p->next;
free(p);
printf("已成功删除!\n");
return head;
}
}
}
}
数据查询
void InquiryNumOne(cloth head,int pos)
{
Node *p;
p=head->next;
if(p==NULL)
{
printf("请先去录入信息!");
return;
}
else
{
while(1)
{
if(p->num!=pos)
{
p=p->next;
if(p==NULL)
{
printf("无此服装!\n");
return;
}
}
else
{
printf("\n你所查询的服装信息如下:\n");
printf("num size prize amount\n");
printf("%d %s %d %d\n",p->num,p->size,p->prize,p->amount);
return;
}
}
}
}
void InquiryNumDouble(cloth head,int num1,int num2)
{
Node *p;
int k=0;
p=head->next;
for(;p!=NULL;p=p->next)
{
if(p->num>num1&&p->num<num2)
{
k++;
break;
}
}
if(k!=0)
printf(" num size prize amount\n");
else
{
printf("无此区间编号!\n");
return;
}
p=head->next;
for(;p!=NULL;p=p->next)
{
if(p->num>num1&&p->num<num2)
{
printf(" %-5d ",p->num);
printf(" %-5s ",p->size);
printf(" %-5d ",p->prize);
printf(" %-5d ",p->amount);
}
}
}
数据统计
void Amount_Size_Statistics(cloth head)
{
int nums=0,numm=0,numl=0,numxl=0,numxxl=0,numxxxl=0,numa=0,k=0;
Node *p=head->next,*stu;
if(p==NULL)
{
printf("请先去录入信息!");
return;
}
else
{
for(;p!=NULL;p=p->next)
{
numa+=p->amount;
if(strcmp(p->size,"s")==0)
nums+=p->amount;
if(strcmp(p->size,"m")==0)
numm+=p->amount;
if(strcmp(p->size,"l")==0)
numl+=p->amount;
if(strcmp(p->size,"xl")==0)
numxl+=p->amount;
if(strcmp(p->size,"xxl")==0)
numxxl+=p->amount;
if(strcmp(p->size,"xxxl")==0)
numxxxl+=p->amount;
}
printf("~~~~~~~~~~~~~~~~~~~~~\n");
printf("\n库存总量为: %d件\n",numa);
printf("s码衣服共有: %d件\n",nums);
printf("m码衣服共有: %d件\n",numm);
printf("l码衣服共有: %d件\n",numl);
printf("xl码衣服共有: %d件\n",numxl);
printf("xxl码衣服共有: %d件\n",numxxl);
printf("xxxl码衣服共有:%d件\n",numxxxl);
printf("~~~~~~~~~~~~~~~~~~~~~\n");
}
}
数据排序
cloth DecreaseSortNum(cloth head)
{
Node temp;
Node *p=head->next,*stu;
if(p==NULL)
{
printf("请先去录入信息!");
return head;
}
else
{
for(;p!=NULL;p=p->next)
{
for(stu=head->next;stu->next!=NULL;stu=stu->next)
{
if(stu->num<stu->next->num)
{
temp=stu;
stu=stu->next;
stu->next=temp;
}
}
}
return head;
}
}
cloth DecreaseSortPrize(cloth head)
{
Node temp;
Node *p=head->next,*stu;
if(p==NULL)
{
printf("请先去录入信息!");
return head;
}
else
{
for(;p!=NULL;p=p->next)
{
for(stu=head->next;stu->next!=NULL;stu=stu->next)
{
if(stu->amount<stu->next->amount)
{
temp=stu;
stu=stu->next;
stu->next=temp;
}
}
}
return head;
}
}
cloth DecreaseSortAmount(cloth head)
{
Node temp;
Node *p=head->next,*stu;
if(p==NULL)
{
printf("请先去录入信息!");
return head;
}
else
{
for(;p!=NULL;p=p->next)
{
for(stu=head->next;stu->next!=NULL;stu=stu->next)
{
if(stu->amount<stu->next->amount)
{
temp=stu;
stu=stu->next;
stu->next=temp;
}
}
}
return head;
}
}