#include<stdio.h>
#include<string.h>
#include<conio.h>
#define N 6 //给后面c数组用
struct library{
int NUM;
char book[100];
float money;
char name[50];
char sign[100];
};
void lookup(struct library *L)
{
int n,i;
do{
printf("输入想查找书的编号(按0退出查看功能):");
scanf("%d",&n); //搜索书编号
for(i=0;i<10;i++)
{
if(n == (L+i)->NUM) //如果输入的书编号等于NUM的值,就打印当前NUM值下的信息
{
printf(" 编号:%d \t书名:%s \t价钱:%.2f \t借阅人:%s \t状态:%s\n", (L+i)->NUM,(L+i)->book,(L+i)->money,(L+i)->name,(L+i)->sign);
}
}
}while(n!=0); //0退出查书
printf("借书(1)or离开(0)\n");
scanf("%d",&n);
if(n==0)
printf("算了,走了\n");
else if(n==1)
{
int j,inp; char c[N];
printf("--load--\n");
printf("\n");
printf("请输入你想借阅的书编号:\n");
scanf("%d",&inp); //输入要借的书编号
getchar();
for(j=0;j<10;j++)
{
if(inp == (L+j)->NUM) //如果输入的书编号当前等于NUM的值
{
if(strlen((L+j)->sign)==8) //如果是8,也就是Loanable的长度,代表没有被借出
{
printf("输入姓名标记借出\n");
gets(c);
printf("\n");
printf("|->回车键确认借出<-|\n");
getch();
strcpy((L+j)->name,c); //将姓名替换到当前name的值
strcpy((L+j)->sign,"done"); //用done把Loanable替换了
printf("Success!\n");
printf(" 编号:%d \t书名:%s \t价钱:%.2f \t借阅人:%s \t状态:%s\n",(L+j)->NUM,(L+j)->book,(L+j)->money,(L+j)->name,(L+j)->sign);
}
else
printf("此书也被借出\n");
}
}
}
}
int main()
{
struct library LIB[]={ //编号、书名、价格、借阅人姓名(none是没有人)、是否借出标记(done是已借出,Loanale是可借出的)
{1,"《Pride and Prejudice》",42.20,"yangwz","done"},
{2,"《Ulysses》",36.10,"none","Loanable"},
{3,"《Moby-Dick》",25.00,"yangyl","done"},
{4,"《To Kill A Mockingbird》",31.21,"none","Loanable"},
{5,"《The Big Sleep》",19.99,"none","Loanable"},
{6,"《Lord of the flies》",29.99,"none","Loanable"},
{7,"《Jane Eyre》",60.20,"none","Loanable"},
{8,"《FLIPPED》",20.6,"yangzw","done"},
{9,"《Tuesdays with Morrie》",21.4,"none","Loanable"},
{10,"《Sweetbitter》",44.44,"yangwwz","done"},
};
lookup(LIB);
return 0;
}
图书馆借书系统
最新推荐文章于 2021-10-16 14:48:38 发布