#include
#include
#include
#include
#include
#define M 3
#define N 100
typedef struct book
{
char xuhao[10];
int score;
char bookname[20];
char writer[20];
char press[20];
int sum;
}BK;
BK bk[N];
int books=0;
void clean();
void ui();
void backs();
void change();
void view();
void seach();
void sum();
void luru()
{
int bs;
int i, k = 1;
system("CLS");
printf("请输入需要输入几个图书信息:");
scanf_s("%d", &bs);
for (i = books;i < books + bs;i++, k++)
{
printf("请输入第%d个书本的序号:", k);
scanf_s("%s", &bk[i].xuhao,10);
printf("请输入第%d个书本的书名:",k);
scanf_s("%s", bk[i].bookname,20);
printf("请输入第%d个书本的价格:", k);
scanf_s("%d", &bk[i].score);
printf("请输入第%d个书本的出版社", k);
scanf_s("%s", bk[i].press,20);
printf("请输入第%d个书本的作者", k);
scanf_s("%s", bk[i].writer,20);
}
books = books + bs;
backs();
}
void main()
{
ui();
}
void ui()
{
int i = 0;
int a;
system("CLS");
printf(" 图书管理系统\n");
printf(" 作者:rime\n");
printf("-------------------MENU-----------------\n");
printf(" 1.录入图书信息\n");
printf(" 2.删除库中信息\n");
printf(" 3.修改图书信息\n");
printf(" 4.浏览图书信息\n");
printf(" 5.查找\n");
printf(" 5.1.按书名查找\n");
printf(" 5.2按作者查找\n");
printf(" 5.3按出版社查找\n");
printf(" 6.根据价格从高到低排序\n");
printf(" 7.退出系统\n");
printf(" 请输入序号:______\b\b\b");
while (i == 0)
{
scanf_s("%d", &a);
switch (a)
{
case 1:
i++;luru();break;
case 2:
i++;clean();break;
case 3:
i++;change();break;
case 4:
i++;view();break;
case 5:
i++;seach();break;
case 6:
i++;sum();break;
case 7:
exit(0);break;
default:
printf("请重新输入\n");
}
}
}
void backs()
{
char a[20];
printf("\n");
printf("还需要操作么?如果需要操作请输入:yes,否则请输入:no\n");
scanf_s("%s", &a,20);
if (strcmp(a, "yes") == 0)
{
ui();
}
else if (strcmp(a, "no") == 0)
exit(0);
else
{
printf("请输入正确的字符,谢谢!\n");
backs();
}
}
void clean()
{
char cleanof[10];
system("CLS");
printf("删除全部书本信息请输入\"all\",删除指定单个信息请输入\"one\"\n");
scanf_s("%s", cleanof,10);
if (strcmp(cleanof, "all") == 0)
{
books = 0;
printf("删除成功\n\n");
}
else if (strcmp(cleanof, "one") == 0)
{
struct book* p = NULL;
char choice[10] ;
int i, j, k = 0;
printf("请输入删除的书的序号:");
scanf_s("%s", &choice,10);
for (i = 0;i < books;i++)
{
if (strcmp(choice, bk[i].xuhao) == 0)
{
k = 1;j = i;break;
}
}
if (k==1)
{
if (books == 1)
{
p = &bk[1];
free(p);
books = 0;
}
else
{
for (i = j;i < books;i++)
{
bk[i] = bk[i + 1];
}
books = books - 1;
}
printf("删除成功\n\n");
}
else
{
printf("输入数据错误!\n");
clean();
}
}
else
{
printf("输入数据错误!\n");
clean();
}
backs();
}
void change()
{
system("CLS");
char a[10];
int i, j;
printf("请选择需要修改信息的序号:\n");
scanf_s("%s", &a, 10);
for (i = 0;i < books;i++)
{
if (strcmp(a, bk[i].xuhao) == 0)
{
j = i;
}
}
printf("请选择要进行的步骤:\n");
printf("1.序号修改\n");
printf("2.作者修改\n");
printf("3.出版商修改\n");
printf("4.价格修改\n");
scanf_s("%d", &i);
switch (i)
{
case 1:scanf_s("%s", bk[j].xuhao, 10);break;
case 2:scanf_s("%s", bk[j].writer, 20);break;
case 3:scanf_s("%s", bk[j].press, 20);break;
case 4:scanf_s("%d", &bk[j].score);break;
}
backs();
}
void view()
{
int i, j;
system("CLS");
if (books == 0)
{
printf("系统里面没有任何学生的信息!(输入任意数字继续)\n");
scanf_s("%d", &i);
}
else
{
for (i = 0;i < books;i++)
{
printf("第%d个书的序号为:%s\n", i + 1, bk[i].xuhao);
printf("第%d个书的书名为:%s\n", i + 1, bk[i].bookname);
printf("第%d个书的作者为:%s\n", i + 1, bk[i].writer);
printf("第%d个书的出版社为:%s\n", i + 1, bk[i].press);
printf("\n");
}
}
backs();
}
void seach()
{
char choice[10], xx[20];
int i, j, k = 0;
system("CLS");
if (books == 0)
{
printf("系统里面没有任何学生的信息!\n");
scanf_s("%d", &i);
backs();
}
printf("三种查找方式:书名,作者,出版社请输入查找方式:");
scanf_s("%s", choice,20);
if (strcmp(choice, "书名") == 0)
{
printf("请输入需要查找书籍的书名:");
scanf_s("%s", xx,20);
for (i = 0;i < books;i++)
{
if (strcmp(xx, bk[i].bookname) == 0)
{
j = i;k = 1;break;
}
}
if (k == 0)
{
printf("输入信息有误:\n");
}
else
{
printf("您所查找的书的信息为:\n");
printf("----序号----书名----作者----出版社----价格\t\n");
printf("------%s------%s-------%s---------%s-------------%d\t\n", bk[j].xuhao, bk[j].bookname,bk[j].writer,bk[j].press,bk[j].score);
}
}
else if (strcmp(choice, "姓名") == 0)
{
printf("请输入需要查找的书籍的作者:\n");
scanf_s("%s", xx,20);
for (i = 0;i < books;i++)
{
if (strcmp(xx, bk[i].bookname) == 0)
{
j = i;k = 1;break;
}
}
if (k == 0)
{
printf("输入信息有误:\n");
}
else
{
printf("您所查找的书的信息为:\n");
printf("----序号----书名----作者----出版社----价格\t\n");
printf("------%s------%s-------%s---------%s-------------%d\t\n", bk[j].xuhao, bk[j].bookname, bk[j].writer, bk[j].press, bk[j].score);
}
}
else if (strcmp(choice, "成绩") == 0)
{
printf("请输入需要查找书的出版社:\n");
scanf_s("%s", xx,20);
for (i = 0;i < books;i++)
{
if (strcmp(xx, bk[i].press) == 0)
{
j = i;k = 1;break;
}
}
if (k == 0)
printf("输入信息有误:\n");
else
{
printf("您所查找的书的信息为:\n");
printf("----序号----书名----作者----出版社----价格\t\n");
printf("------%s------%s-------%s---------%s-------------%d\t\n", bk[j].xuhao, bk[j].bookname, bk[j].writer, bk[j].press, bk[j].score);
}
}
backs();
}
void sum()
{
struct book* p1[N], ** p2, * temp;
int i, j;
system("CLS");
p2 = p1;
for (i = 0;i < books;i++)
{
p1[i] = bk + i;
}
for (i = 0;i < books;i++)
{
for (j = i + 1;j < books;j++)
{
if ((*(p2 + i))->score < (*(p2 + j))->score)
{
temp = *(p2 + i);
*(p2 + i) = *(p2 + j);
*(p2 + j) = temp;
}
}
}
printf("按照价格排序之后的信息为:\n");
printf("----书名-----作者------价格----\n");
for (i = 0;i < books;i++)
{
printf("----%s-----%s---------%d\n", (*(p2 + i))->bookname, (*(p2 + i))->writer, (*(p2 + i))->score);
}
backs();
}