|
|
|
@ -0,0 +1,111 @@
|
|
|
|
|
#include<stdio.h>
|
|
|
|
|
#include<string.h>
|
|
|
|
|
#include<stdlib.h>
|
|
|
|
|
|
|
|
|
|
int cmp(char str0[],char str1[]) //比较两行字符串是否相等,相等则返回0,否则返回非0
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
for(i=0;str0[i]!=0 && str1[i]!=0 && str0[i]==str1[i];i++);
|
|
|
|
|
return str0[i]-str1[i];
|
|
|
|
|
}
|
|
|
|
|
int main(void)
|
|
|
|
|
{
|
|
|
|
|
char sm[100];
|
|
|
|
|
|
|
|
|
|
int c=1,i=0,n=0,flag=0,j=0;
|
|
|
|
|
struct kc //定义结构体数组,以每个名词的首字母取员名,如”书名“为”sm“
|
|
|
|
|
{
|
|
|
|
|
char sm[100];
|
|
|
|
|
char zz[100];
|
|
|
|
|
char cbs[100];
|
|
|
|
|
long cbrq;
|
|
|
|
|
double jg;
|
|
|
|
|
int wz;
|
|
|
|
|
int sl;
|
|
|
|
|
};
|
|
|
|
|
struct kc a[10]=
|
|
|
|
|
{ //定义书籍资料
|
|
|
|
|
{"怨女","张爱玲","北京十月文艺出版社",20090520,29.80,1,100},
|
|
|
|
|
{"围城","钱钟书","人民文学出版社",19910214,19.00,2,10},
|
|
|
|
|
{"红楼梦","曹雪芹","人民文学出版社",19961225,59.70,3,100},
|
|
|
|
|
{"看见","柴静","广西师范大学出版社",20131001,39.80,4,100},
|
|
|
|
|
{"一只特立独行的猪","王小波","北方文艺出版社",20060927,18.80,5,50},
|
|
|
|
|
{"芳华","严歌苓","人民文学出版社",20171116,39.00,6,60},
|
|
|
|
|
{"穆斯林的葬礼","霍达","北京十月文艺出版社",19880707,32.00,7,80},
|
|
|
|
|
{"我的前半生","亦舒","新世界出版社",20070504,22.00,8,100},
|
|
|
|
|
{"挪威的森林","村上春树","上海译文出版社",20010807,18.80,9,6},
|
|
|
|
|
{"我们仨","杨绛","新知三联书店",20031101,18.80,10,20}
|
|
|
|
|
};
|
|
|
|
|
flag1:
|
|
|
|
|
printf("***********书店库存管理系统***********:\n");
|
|
|
|
|
printf("**** 1.书本录入 ****:\n");
|
|
|
|
|
printf("**** 2.书本查询 ****:\n");
|
|
|
|
|
printf("**************************************:\n");
|
|
|
|
|
|
|
|
|
|
int choose;
|
|
|
|
|
printf("请选择:\t");
|
|
|
|
|
scanf("%d",&choose); //选择序号
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(choose==1)
|
|
|
|
|
{
|
|
|
|
|
printf("录入成功!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(choose==2){
|
|
|
|
|
printf("请输入书名:\n");
|
|
|
|
|
fflush(stdin);
|
|
|
|
|
gets(sm);
|
|
|
|
|
j=0; //未找到书籍而跳到这里时使j清零,防止当再次没找到书籍时因j已大于10而无法进入最后的if语句,即无法得到未查找到的提示
|
|
|
|
|
for(i=0;i<10;i++)
|
|
|
|
|
{
|
|
|
|
|
j++; //当j加到10时则说明没有找到书籍
|
|
|
|
|
if(cmp(a[i].sm,sm)==0)
|
|
|
|
|
{
|
|
|
|
|
printf("书名:");
|
|
|
|
|
puts(a[i].sm);
|
|
|
|
|
printf("作者:");
|
|
|
|
|
puts(a[i].zz);
|
|
|
|
|
printf("出版社:");
|
|
|
|
|
puts(a[i].cbs);
|
|
|
|
|
printf("出版日期:%d\n",a[i].cbrq);
|
|
|
|
|
printf("价格:%lf\n",a[i].jg);
|
|
|
|
|
printf("位置:%d\n",a[i].wz);
|
|
|
|
|
printf("库存:%d\n",a[i].sl);
|
|
|
|
|
printf("请输入所需数量:\n");
|
|
|
|
|
fflush(stdin);
|
|
|
|
|
scanf("%d",&n);
|
|
|
|
|
if(n<=a[i].sl)
|
|
|
|
|
printf("总价为 %lf\n",(n*a[i].jg));
|
|
|
|
|
else
|
|
|
|
|
printf("所需数量不在库存范围内\n");
|
|
|
|
|
printf("是否还想买其他书籍?(是 1: 否 0:双击回车键)\n");
|
|
|
|
|
fflush(stdin);
|
|
|
|
|
scanf("%d",&c);
|
|
|
|
|
if(c==1)
|
|
|
|
|
goto flag1;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
j=0; //当要退出时使j清零,防止当所找书籍位置为10时跳出for语句后因j也为10而误进入下面的if语句
|
|
|
|
|
printf("谢谢,再见!\n");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(j=10)
|
|
|
|
|
{
|
|
|
|
|
j=0;
|
|
|
|
|
printf("未查找到该书籍,是否还想买其他书籍?(是Y或y否N或n)\n");
|
|
|
|
|
fflush(stdin); //清空输入缓存,防止干扰下次输入
|
|
|
|
|
scanf("%c",&c);
|
|
|
|
|
if(c==1)
|
|
|
|
|
goto flag1;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
printf("谢谢,再见!\n");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|