#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct
{
char num[20];
char name[50];
char author[50];
double fee;
}BOOK;
void input_book(BOOK b[]);
void search_book(BOOK b[]);
void fee_book(BOOK b[]);
void menu(void);
int main()
{
BOOK book[10];
int type;
while(1)
{
menu();
printf("请选择需要的操作:\n");
scanf("%d",&type);
switch(type)
{
case 1:
system("cls");
input_book(book);
getch();
break;
case 2:
system("cls");
search_book(book);
getch();
break;
case 3:
system("cls");
fee_book(book);
getch();
break;
case 4:
exit(0);
break;
default:
printf("操作错误\n");
break;
}
}
return 0;
}
void menu(void)
{
system("cls");
printf("\t\t\t**************************\n");
printf("\t\t\t** 1.录入书籍信息 ****\n");
printf("\t\t\t** 2.查找书籍 ****\n");
printf("\t\t\t** 3.通过价格查找书籍 **\n");
printf("\t\t\t** 4.退出 **\n");
printf("\t\t\t**************************\n");
}
//输入书籍信息
void input_book(BOOK b[])
{
int i;
printf("请按照如下格式输入书籍信息:\n");
printf("书号\t书名\t作者\t价格\n");
for(i=0;i<10;i++)
{
scanf("%s\t%s\t%s\t%lf",b[i].num,b[i].name,b[i].author,&b[i].fee);
}
}
//查找书籍
void search_book(BOOK b[])
{
char name[50];
int flag = 0;
int i;
printf("请输入书名:");
scanf("%s",name);
for(i=0;i<10;i++)
{
if(strcmp(b[i].name,name)==0)
{
flag = 1;
printf("书号\t书名\t作者\t价格\n");
printf("%s\t%s\t%s\t%.2lf",b[i].num,b[i].name,b[i].author,b[i].fee);
}
}
if(flag==0)
{
printf("没有这本书\n");
}
}
void fee_book(BOOK b[])
{
int i;
double temp;
int flag = 0;
printf("请输入书籍价格:");
scanf("%lf",&temp);
for(i=0;i<10;i++)
{
if(b[i].fee>temp)
{
flag = 1;
printf("书号\t书名\t作者\t价格\n");
printf("%s\t%s\t%s\t%.2lf\n",b[i].num,b[i].name,b[i].author,b[i].fee);
}
}
if(flag==0)
{
printf("没有高于次价格的书籍\n");
}
}
温馨提示:答案为网友推荐,仅供参考