#includeusing namespace std;
const int N = 25;//定义20本图书
struct Book {
char name[25];
char author[15];
char price[7];
char publisher[20];
char isbn[20];
};
int ii = 19;
Book book[N] = { { "红与黑","司汤达","26.00","长江文艺出版社","978-7-5354-5003-6" },
{ "张伯苓画传","梁吉生","35.00","四川教育出版社","978-7-5408-5623-6" },
{ "四世生花","沈煜伦","49.80","湖南文艺出版社","978-7-5404-7718-9" },
{ "北大人的礼仪课","段建林","39.80","外文出版社","978-7-119-08439-8" },
{ "悲惨世界","雨果","44.00","北方文艺出版社","978-7-5317-3049-1" },
{ "好吗好的","大冰","39.00","湖南文艺出版社","978-7-5404-7689-2" },
{ "千秋","落落","28.80","长江文艺出版社","978-7-5354-5060-9" },
{ "陪安东尼度过漫长岁月","安东尼","28.80","长江文艺出版社","978-7-5354-6205-3" },
{ "刘邦正传","周启元","52.80","中国文史出版社","978-7-5034-5145-4" },
{ "小王子","圣埃克苏佩里","24.00","湖南少儿出版社","978-7-5562-0考试界-1" },
{ "围城","钱钟书","19.00","人民文学出版社","978-7-02-009000-6" },
{ "解忧杂货铺","东野圭吾","39.50","南海出版社","978-7-5442-7087-3" },
{ "追风筝的人","胡赛尼","29.00","上海人民出版社","978-7-208-06164-4" },
{ "摆渡人","麦克福尔","36.00","百花洲文艺出版社","978-7-550-01324-7" },
{ "神话","朱大可","35.00","东方出版社","978-7-5060-5278-8" },
{ "人民的名义","周梅森","46.90","北京十月文艺出版社","978-7-5302-1619-4" },
{ "夜谭十记","马识途","29.80","京华出版社","978-7-5502-2550-3" },
{ "悟空传","今何在","32.00","北京联合出版社","978-7-5502-7767-0" },
{ "英雄传","宫部美雪","29.90","青岛出版社","978-7-5436-6784-6" },
{ "白夜行","东野圭吾","39.50","南海出版社","978-7-5442-5860-9" } };
void inquiremenu() {
system("cls");
int y = 0;
printf("************");
printf("1.书号查询");
printf("2.书名查询");
printf("3.作者查询");
printf("4.出版社查询");
printf("请选择(1~4): 回车确定");
scanf("%d", &y);
int i;
switch (y) {
case 1: {
char x[20];
system("cls");
printf("请输入查找书号");
scanf("%s", &x);
bool fg = 0;
for (i = 0; i if (strcmp(book[i].isbn,x) == 0) {
printf("已找到");
fg = 1;
printf("书名:%s,作者:%s,价格:%s,出版社:%s,书号:%s", book[i].name, book[i].author, book[i].price, book[i].publisher, book[i].isbn);
}
}//按书号查询
if (!fg)printf("未找到/n");
break;
}
case 2: {
char j[25];
system("cls");
printf("请输入查找书名");
scanf("%s", &j);
bool fg = 0;
for (i = 0; i if (strcmp(j, book[i].name) == 0) {
printf("已找到");
fg = 1;
printf("书名:%s,作者:%s,价格:%s,出版社:%s,书号:%s", book[i].name, book[i].author, book[i].price, book[i].publisher, book[i].isbn);
}
}//按书名查询
if (!fg)printf("未找到/n");
break;
}
case 3: {
char k[15];
system("cls");
printf("请输入查找作者");
scanf("%s", &k);
bool fg = 0;
for (i = 0; i if (strcmp(k, book[i].author) == 0) {
printf("已找到");
fg = 1;
printf("书名:%s,作者:%s,价格:%s,出版社:%s,书号:%s", book[i].name, book[i].author, book[i].price, book[i].publisher, book[i].isbn);
}
}//按作者查询
if (!fg)printf("未找到/n");
break;
}
case 4: {
char z[20];
system("cls");
scanf("%s", &z);
bool fg = 0;
printf("请输入查找出版社");
for (i = 0; i if (strcmp(z, book[i].publisher) == 0) {
printf("已找到");
fg = 1;
printf("书名:%s,作者:%s,价格:%s,出版社:%s,书号:%s", book[i].name, book[i].author, book[i].price, book[i].publisher, book[i].isbn);
}
}//按出版社查询
if (!fg)printf("未找到/n");
break;
}
}
}//查询函数
void addbook() {
system("cls");
printf("请输入书名");
scanf("%s", &book[ii + 1].name);
printf("请输入作者");
scanf("%s", &book[ii + 1].author);
printf("请输入价格");
scanf("%s", &book[ii + 1].price);
printf("请输入出版社");
scanf("%s", &book[ii + 1].publisher);
printf("请输入书号");
scanf("%s", &book[ii + 1].isbn);
++ii;
}//添加图书
void information() {
int i;
for (i = 0; i printf("");
printf("书名:%s,作者:%s,价格:%s,出版社:%s,书号:%s", book[i].name, book[i].author, book[i].price, book[i].publisher, book[i].isbn);
}
}//显示所有图书信息
int main() {
int accept, input_error_flag;
system("cls");
printf("******图书查询系统******");
printf("************************");
printf("******1.图书查询*******");
printf("******2.添加图书***");
printf("******3.图书信息*****");
printf("******4.退 出******");
printf("************************");
printf("****请输入选择(1~4):*****");
input_error_flag = 0;
do {
if (input_error_flag == 1)
printf("输入错误!!! 重新输入:");
printf("输入:1~4):");
fflush(stdin);//输入缓冲区清空
scanf("%d", &accept);
input_error_flag = 1;
} while (accept 4);
switch (accept)
{
case 0:
case 1:inquiremenu(); break;
case 2:addbook(); break;
case 3:information(); break;
case 4:printf("退出"); break;
default:system("cls");
}
return 0;
}