#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define N 100
int a=0;
struct books
{
int shuhao;
//书号
char shuming[20];
//书名
char zuozhe[20];
//作者
char cbs[20];
//出版社
int
jiage;
//价格
};
struct books book[N];
void luru()
{
int i;
system("cls");
for(i=0;i>=0;i++)
{
char ch;
printf("~~~~~~~~~~~~~~~开始输入信息~~~~~~~~~~~~~\n");
printf("请输入书的编号:");
scanf("%d",&book[i].shuhao);
printf("\n");
printf("请输入书名:");
scanf("%s",&book[i].shuming);
printf("\n");
printf("请输作者名:");
scanf("%s",&book[i].zuozhe);
printf("\n");
printf("请输入出版社:");
scanf("%s",&book[i].cbs);
printf("\n");
printf("请输入图书价格:");
scanf("%d",&book[i].jiage);
printf("\n");
getchar( );
system("cls");
printf("是否继续输入,请选择\n(1:继续 2:退出):");
scanf("%d",&ch);
if(ch==1)
{
a++;
}
else
{
break;
}
}
}
void liulan()
{
int i;
system("cls");
printf("书号\t书名\t作者\t出版社\t价格\n");
for(i=0;i<=a;i++)
{
printf("%d\t%s\t%s\t%s\t%d\n",book[i].shuhao,book[i].shuming,book[i].zuozhe,book[i].cbs,book[i].jiage);
}
}
void cx1()//书名查询
{
int i;
char name[20];
system("cls");
printf("|按书名查询|\n");
scanf("%s",&name);
for(i=0;i<=a;i++)
{
if(strcmp(name,book[i].shuming)==0)
{
printf("书号\t书名\t作者\t出版社\t价格\n");
printf("%d\t%s\t%s\t%s\t%d\n",book[i].shuhao,book[i].shuming,book[i].zuozhe,book[i].cbs,book[i].jiage);
}
if(strcmp(name,book[i].shuming)!=0)
{
printf("没有你要的查询结果\n");
}
}
}
void cx2()//作者名查询
{
int i;
char g[20];
system("cls");
printf("|按作者名查询|\n");
scanf("%s",&g);
for(i=0;i<=a;i++)
{
if(strcmp(g,book[i].zuozhe)==0)
{
printf("书号\t书名\t作者\t出版社\t价格\n");
printf("%d\t%s\t%s\t%s\t%d\n",book[i].shuhao,book[i].shuming,book[i].zuozhe,book[i].cbs,book[i].jiage);
}
if(strcmp(g,book[i].zuozhe)!=0)
{
printf("没有你要的查询结果\n");
}
}
}
void chaxun()//查询
{
int x;
system("cls");
printf("\n==================================图书信息查询==================================\n");
printf("**************************************请选择查询方式****************************\n");
printf("|1.按书名查询|\n");
printf("|2.按作者名查询|\n");
sta:printf("请输入你选择:");
scanf("%d",&x);
switch(x)
{
case 1:cx1();break;//调用cx1函数完成按书名查询
case 2:cx2();break;//调用cx2函数完成按作者查询
default :
{
printf("输入有误,请重新输入!\n");
//syetem("cls");
goto sta;
break;
}
}
}
void del()//删除
{
char shu[20];
int i,h,z;
system("cls");
fanhui:printf("请你输入想要删除图书的名称:\n");
fflush(stdin);
scanf("%s",&shu);//接收书名
for(i=0;i<=a;i++)
{
if(strcmp(shu,book[i].shuming)==0)
{
printf("书号\t书名\t作者\t出版社\t价格\n");
printf("%d\t%s\t%s\t%s\t%d\n",book[i].shuhao,book[i].shuming,book[i].zuozhe,book[i].cbs,book[i].jiage);
printf("你确定要删除以上信息吗?\n");
printf("|1.是,确认删除\n");
printf("|2.否,返回上一层\n");
printf("|3.否,返回主页\n");
fflush(stdin);
scanf("%d",&h);
if(h==1)
{
for(z=i;z<a;z++)
{
book[i]=book[i+1];
}
}
if(h==2)
{
system("cls");
goto fanhui;
}
if(h==3)
{
break;
}
printf("信息删除成功\n");
a--;
break;
}
if(shu,book[i].shuming!=0)
{
printf("没有该书籍信息\n");
break;
}
}
}
void xg()//修改
{
int i;
char name[20];
system("cls");
printf("|请输入你要修改的书名|\n");
scanf("%s",&name);
for(i=0;i<=a;i++)
{
if(strcmp(name,book[i].shuming)==0)
{
printf("该图书信息为:\n");
printf("\n");
printf("\n");
printf("书号\t书名\t作者\t出版社\t价格\n");
printf("%d\t%s\t%s\t%s\t%d\n",book[i].shuhao,book[i].shuming,book[i].zuozhe,book[i].cbs,book[i].jiage);
printf("请重新输入该书籍信息:\n");
printf("~~~~~~~~~~~~~~~开始输入信息~~~~~~~~~~~~~\n");
printf("请输入书的编号:");
scanf("%d",&book[i].shuhao);
printf("\n");
printf("请输入书名:");
scanf("%s",&book[i].shuming);
printf("\n");
printf("请输作者名:");
scanf("%s",&book[i].zuozhe);
printf("\n");
printf("请输入出版社:");
scanf("%s",&book[i].cbs);
printf("\n");
printf("请输入图书价格:");
scanf("%d",&book[i].jiage);
printf("\n");
/*
getchar( );
system("cls");
*/
}
}
if(strcmp(name,book[i].shuming)!=0)
printf("没有该书籍信息!\n");
}
void main()
{
int n=0,sta=1,shuru;
while(sta)
{
system("cls");
{
printf("\t\t*****************图书信息管理系统*****************\n");
printf("\t\t*\t\t|1.图书录入
*\n");
printf("\t\t*\t\t|2.图书浏览
*\n");
printf("\t\t*\t\t|3.图书查询
*\n");
printf("\t\t*\t\t|4.图书的删除
*\n");
printf("\t\t*\t\t|5.图书修改
*\n");
printf("\t\t*\t\t|6.退出系统
*\n");
printf("\t\t*****************图书信息管理系统*****************\n\n\n");
printf("\t\t请输入以上序号进行选择:\n");
scanf("%d",&shuru);
}
switch(shuru)
{
case 1:luru(book,n);
{
system("pause");
break;
}
case 2:liulan(book,n);
{
system("pause");
break;
}
case 3:chaxun(book,n);
{
system("pause");
break;
}
case 4:del(book,n);
{
system("pause");
break;
}
case 5:xg(book,n);
{
system("pause");
break;
}
case 6:exit(0);
{
system("pause");
}
default :
{
printf("输入有误,请重新输入!\n");
fflush(stdin);
scanf("%d",&shuru);
}
}
}
}
当时课程设计自己写着玩的你自己改改吧