驱动人生怎么样-游戏性能测试软件
![c语言图书管理系统](/uploads/image/0113.jpg)
2023年4月5日发(作者:电脑怎么录屏)
图书管理系统设计
图书管理信息包括:图书名称、图书编号、单价、作者、存在状态、借书人姓名、性别、学
号等
功能描述:
1.新进熟土基本信息的输入
2.图书基本信息的查询
3.对撤消图书信息的删除
4.为借书人办理注册
5.办理借书手续
6.办理换书手续
要求:以文件方式存储数据,系统以菜单方式工作。
这是本人大一第二学期初C语言课程设计的作品,嘿嘿,本来以为已经找不到原稿了,今天
无意中竟然在QQ网络硬盘中找到了当初的teta版,发布于此,以作纪念。
C源代码如下:
#include〈stdio.h〉
#include
#include
structbook{
charbook_name[30];
intbianhao;
doubleprice;
charauthor[20];
charstate[20];
charname[20];
charsex[10];
intxuehao;
structbook*book_next;
};
structclub{
charname[20];
charsex[10];
intxuehao;
charborrow[30];
structclub*club_next;
};
voidPrint_Book(structbook*head_book);/*浏览所有图书信息*/
voidPrint_Club(structclub*head_club);/*浏览所有会员信息*/
structbook*Create_New_Book();/*创建新的图书库,图书编号输入为0时结束*/
structbook*Search_Book_bianhao(intbianhao,structbook*head_book);
structbook*Search_Book_name(char*b_name,structbook*head_book);
structbook*Search_Book_price(doubleprice_h,doubleprice_l,structbook*head_book);
structbook*Insert_Book(structbook*head_book,structbook*stud_book);/*增加图书,逐
个添加*/
structbook*Delete_Book(structbook*head_book,intbianhao);/*删除图书*/
structclub*Create_New_Club();
structclub*Search_Club_xuehao(intxuehao,structclub*head_club);
structclub*Search_Club_name(char*c_name,structclub*head_club);
structclub*Insert_Club(structclub*head_club,structclub*stud_club);
structclub*Delete_Club(structclub*head_club,intxuehao);
structbook*Lent_Book(intbianhao,intxuehao,structbook*head_book,structclub*
head_club);
structbook*back(intbianhao,intxuehao,structbook*head_book,structclub*head_club);
intmain()
{
structbook*head_book,*p_book;
charbook_name[30],name[20],author[20],sex[10];
intbianhao;
doubleprice,price_h,price_l;
intsize_book=sizeof(structbook);
intm=1,n=1,f;
char*b_name,*c_name;
structclub*head_club,*p_club;
intxuehao;
intsize_club=sizeof(structclub);
intchoice;
printf(”n欢迎您第一次进入图书管理系统!nn");
printf(”-—--—>[向导]—-——->[新建图书库]nn”);
printf("注意:当输入图书编号为0时,进入下一步.nn");
head_book=Create_New_Book();
system("cls");
printf("n欢迎您第一次进入图书管理系统!nn");
printf("—————〉[向导]—--—-〉[新建会员库]nn");
printf("注意:当输入会员学号为0时,进入主菜单。nn”);
head_club=Create_New_Club();
system(”cls");
do{
printf("nttt〓〓〓〓〓图书管理系统〓〓〓〓〓nn");
printf("n”);
printf("ttt[1]:借书办理t”);printf("[6]:还书办理n”);
printf("n");
printf("ttt[2]:查询图书t");printf("[7]:查询会员n”);
printf("ttt[3]:添加图书t”);printf("[8]:添加会员n”);
printf("ttt[4]:删除图书t”);printf(”[9]:删除会员n”);
printf(”ttt[5]:遍历图书t”);printf(”[10]:遍历会员nn");
printf("ttt〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓nn”);
printf("ttt0:退出nn");
printf("请选择<0~10>:”);
scanf("%d",&choice);
switch(choice){
case1:
printf(”nttt〓〓〓〓〓图书管理系统〓〓〓〓〓nn");
printf(”输入所借图书编号:n”);
scanf(”%d”,&bianhao);
printf(”输入借书人的学号:n”);
scanf(”%d",&xuehao);
head_book=Lent_Book(bianhao,xuehao,head_book,head_club);
system("cls");
printf(”n借阅成功!nn");
printf("相关信息如下:nn”);
head_book=Search_Book_bianhao(bianhao,head_book);
break;
case2:
system(”cls");
printf(”nttt〓〓〓〓〓图书管理系统〓〓〓〓〓nn”);
printf(”1.按编号查询nn");
printf(”2。按名称查询nn”);
printf("3。按价格区间查询nn”);
printf(”0.返回主菜单nn”);
printf("请选择:”);
scanf("%d”,&f);
if(f==1){
printf("请输入查询图书编号:”);
scanf(”%d”,&bianhao);
printf(”相关信息如下:nn”);
head_book=Search_Book_bianhao(bianhao,head_book);
break;
}
elseif(f==2){
b_name=book_name;
getchar();
printf("请输入查询图书名称:");
gets(b_name);
printf("相关信息如下:nn");
head_book=Search_Book_name(b_name,head_book);
break;
}
elseif(f==3){
printf(”请输入最高价格:”);
scanf("%lf",&price_h);
printf("请输入最低价格:");
scanf(”%lf",&price_l);
printf("相关信息如下:nn”);
head_book=Search_Book_price(price_h,price_l,head_book);
break;
}
elseif(f==0){
break;
}
break;
case6:
printf(”nttt〓〓〓〓〓图书管理系统〓〓〓〓〓nn”);
printf(”输入所还图书编号:n”);
scanf(”%d”,&bianhao);
printf("输入还书人的学号:n”);
scanf(”%d”,&xuehao);
head_book=back(bianhao,xuehao,head_book,head_club);
system("cls”);
printf(”n归还成功!nn");
printf("相关信息如下:nn");
head_book=Search_Book_bianhao(bianhao,head_book);
break;
case3:
system(”cls”);
printf(”nttt〓〓〓〓〓图书管理系统〓〓〓〓〓nn”);
printf(”请输入图书名称:");
scanf(”%s",book_name);
printf("请输入图书编号:");
scanf(”%d",&bianhao);
printf(”请输入单价:");
scanf(”%lf",&price);
printf(”请输入作者名字:");
scanf(”%s",author);
printf(”n”);
structbook*ptr_b;
for(ptr_b=head_book;ptr_b;ptr_b=ptr_b—>book_next)
{
if(ptr_b->bianhao==bianhao)
{
printf("此编号图书已存在n");m=0;
break;
}
}
if(m){
p_book=(structbook*)malloc(size_book);
strcpy(p_book->book_name,book_name);
p_book—>bianhao=bianhao;
p_book-〉price=price;
p_book-〉xuehao=0;
strcpy(p_book—>author,author);
strcpy(p_book—〉state,”存在”);
strcpy(p_book-〉sex,"待定");
strcpy(p_book—>name,”待定”);
head_book=Insert_Book(head_book,p_book);
printf("n添加图书成功!nn");
}
break;
case4:
system(”cls”);
printf("nttt〓〓〓〓〓图书管理系统〓〓〓〓〓nn");
printf(”输入删除图书编号:n");
scanf("%d”,&bianhao);
head_book=Delete_Book(head_book,bianhao);
printf("n删除图书成功!nn”);
break;
case5:
system(”cls");
printf("nttt〓〓〓〓〓图书管理系统〓〓〓〓〓nn”);
Print_Book(head_book);
break;
case7:
system("cls");
printf(”nttt〓〓〓〓〓图书管理系统〓〓〓〓〓nn");
printf("1.按学号查询nn");
printf("2。按姓名查询nn");
printf("0.返回主菜单nn");
printf(”请选择:");
scanf(”%d",&f);
if(f==1){
printf(”请输入查询会员学号:”);
scanf("%d",&xuehao);
printf(”相关信息如下:nn”);
head_club=Search_Club_xuehao(xuehao,head_club);
break;
}
elseif(f==2){
c_name=name;
getchar();
printf("请输入查询会员姓名:");
gets(c_name);
printf(”相关信息如下:nn”);
head_club=Search_Club_name(c_name,head_club);
break;
}
elseif(f==0){
break;
}
break;
printf(”请输入查询会员学号:n");
scanf("%d",&xuehao);
printf(”相关信息如下:nn");
break;
case8:
system(”cls”);
printf("nttt〓〓〓〓〓图书管理系统〓〓〓〓〓nn”);
printf(”请输入会员名字:");
scanf(”%s”,name);
printf("请输入会员性别:");
scanf(”%s”,sex);
printf("请输入会员学号:");
scanf("%d",&xuehao);
printf("n”);
structclub*ptr_c;
for(ptr_c=head_club;ptr_c;ptr_c=ptr_c—〉club_next)
{
if(ptr_c—>xuehao==xuehao)
{printf(”此学号会员已存在n”);n=0;break;}
}
if(n){
p_club=(structclub*)malloc(sizeof(structclub));
strcpy(p_club-〉name,name);
strcpy(p_club—〉sex,sex);
p_club->xuehao=xuehao;
strcpy(p_club->borrow,”暂无”);
head_club=Insert_Club(head_club,p_club);
printf("n添加会员成功!nn”);
}
break;
case9:
system("cls”);
printf("nttt〓〓〓〓〓图书管理系统〓〓〓〓〓nn");
printf(”输入要删除会员学号:n”);
scanf("%d”,&xuehao);
head_club=Delete_Club(head_club,xuehao);
printf("n删除会员成功!nn”);break;
case10:
system(”cls");
printf("nttt〓〓〓〓〓图书管理系统〓〓〓〓〓nn”);
Print_Club(head_club);break;
case0:
system("cls");
printf("nttt〓〓〓〓〓图书管理系统〓〓〓〓〓nn”);
printf("n谢谢您的使用!nn”);break;
}
}while(choice!=0);
return0;
}
structbook*Create_New_Book()
{
structbook*head_book,*p_book;
intbianhao;
doubleprice;
charbook_name[30],author[20];
intsize_book=sizeof(structbook);
head_book=NULL;
printf("请输入图书名称:");
scanf(”%s”,book_name);
printf(”请输入图书编号:");
scanf("%d",&bianhao);
printf("请输入单价:”);
scanf(”%lf”,&price);
printf("请输入作者名字:");
scanf("%s”,author);
printf(”n”);
while(bianhao!=0){
p_book=(structbook*)malloc(size_book);
strcpy(p_book->book_name,book_name);
p_book—>bianhao=bianhao;
p_book—>price=price;
p_book—〉xuehao=0;
strcpy(p_book-〉author,author);
strcpy(p_book->state,"存在”);
strcpy(p_book—>sex,"待定”);
strcpy(p_book—>name,”待定");
head_book=Insert_Book(head_book,p_book);
printf("请输入图书名称:”);
scanf("%s",book_name);
printf("请输入图书编号:");
scanf("%d",&bianhao);
printf(”请输入单价:");
scanf(”%lf”,&price);
printf(”请输入作者名字:");
scanf("%s”,author);printf(”n");
}
returnhead_book;
}
structbook*Search_Book_bianhao(intbianhao,structbook*head_book)
{
structbook*ptr_book;intflag=0;
for(ptr_book=head_book;ptr_book;ptr_book=ptr_book—>book_next)
{
if(ptr_book—>bianhao==bianhao){
printf("图书编号:%dn",ptr_book—>bianhao);
printf("图书名称:%sn”,ptr_book—〉book_name);
printf("图书单价:%.2lfn",ptr_book-〉price);
printf("图书作者:%sn”,ptr_book—〉author);
printf("存在状态:%sn",ptr_book—〉state);
printf("借书人姓名:%sn",ptr_book—〉name);
printf("借书人性别:%sn",ptr_book->sex);
printf("学号:%dn”,ptr_book—>xuehao);
printf(”n”);flag++;
}
}
if(flag==0){printf("暂无此图书信息!nn”);}
returnhead_book;
}
structbook*Search_Book_name(char*b_name,structbook*head_book)
{
structbook*ptr_book;
intflag=0;
for(ptr_book=head_book;ptr_book;ptr_book=ptr_book—〉book_next)
{
if(strcmp(ptr_book—>book_name,b_name)==0){
printf("图书编号:%dn",ptr_book->bianhao);
printf("图书名称:%sn”,ptr_book—>book_name);
printf(”图书单价:%.2lfn",ptr_book->price);
printf(”图书作者:%sn",ptr_book—〉author);
printf("存在状态:%sn",ptr_book—〉state);
printf("借书人姓名:%sn",ptr_book->name);
printf(”借书人性别:%sn",ptr_book—〉sex);
printf(”学号:%dn”,ptr_book—>xuehao);
printf(”n”);
flag++;
}
}
if(flag==0){printf(”暂无此图书信息!nn");}
returnhead_book;
}
structbook*Search_Book_price(doubleprice_h,doubleprice_l,structbook*head_book)
{structbook*ptr_book;
intflag=0;
for(ptr_book=head_book;ptr_book;ptr_book=ptr_book->book_next)
{
if((ptr_book—〉price>=price_l)&&(ptr_book-〉price〈=price_h)){
printf("图书编号:%dn",ptr_book->bianhao);
printf("图书名称:%sn",ptr_book-〉book_name);
printf("图书单价:%.2lfn”,ptr_book->price);
printf(”图书作者:%sn",ptr_book->author);
printf("存在状态:%sn”,ptr_book->state);
printf("借书人姓名:%sn”,ptr_book—〉name);
printf(”借书人性别:%sn”,ptr_book—>sex);
printf("学号:%dn",ptr_book—>xuehao);
printf(”n”);
flag++;
}
}
if(flag==0){printf("暂无此图书信息!nn”);}
returnhead_book;
}
structbook*Delete_Book(structbook*head_book,intbianhao)
{
structbook*ptr1_book,*ptr2_book;
while(head_book!=NULL&&head_book->bianhao==bianhao){
ptr2_book=head_book;
head_book=head_book->book_next;
free(ptr2_book);
}
if(head_book==NULL)returnNULL;
ptr1_book=head_book;
ptr2_book=head_book—〉book_next;
while(ptr2_book!=NULL){
if(ptr2_book-〉bianhao==bianhao){
ptr1_book->book_next=ptr2_book—>book_next;
free(ptr2_book);
}
else
ptr1_book=ptr2_book;
ptr2_book=ptr1_book—>book_next;
}
returnhead_book;
}
structclub*Create_New_Club()
{structclub*head_club,*p_club;
intxuehao;
charname[20],sex[10];
intsize_club=sizeof(structclub);
head_club=NULL;
printf("请输入会员名字:”);scanf("%s”,name);
printf("请输入会员性别:”);scanf("%s”,sex);
printf("请输入会员学号:");scanf("%d”,&xuehao);
printf("n”);
while(xuehao!=0){
p_club=(structclub*)malloc(size_club);
strcpy(p_club-〉name,name);
strcpy(p_club—>sex,sex);p_club->xuehao=xuehao;
strcpy(p_club—>borrow,"暂无");
head_club=Insert_Club(head_club,p_club);
printf("请输入会员名字:");
scanf("%s",name);
printf("请输入会员性别:");scanf("%s”,sex);
printf(”请输入会员学号:”);scanf(”%d”,&xuehao);
printf("n");
}
returnhead_club;
}
structclub*Search_Club_xuehao(intxuehao,structclub*head_club)
{structclub*ptr_club;
intflag=0;
for(ptr_club=head_club;ptr_club;ptr_club=ptr_club—〉club_next)
{
if(ptr_club->xuehao==xuehao){
printf(”会员姓名:%sn”,ptr_club—>name);
printf("会员性别:%sn”,ptr_club—〉sex);
printf(”会员学号:%dn",ptr_club—〉xuehao);
printf(”所借图书:%sn",ptr_club—>borrow);
printf(”n”);flag++;
}}
if(flag==0){printf(”此用户不存在!nn");}
returnhead_club;
}
structclub*Search_Club_name(char*c_name,structclub*head_club)
{
structclub*ptr_club;intflag=0;
for(ptr_club=head_club;ptr_club;ptr_club=ptr_club->club_next)
{
if(strcmp(ptr_club-〉name,c_name)==0){
printf("会员姓名:%sn”,ptr_club->name);
printf("会员性别:%sn",ptr_club—〉sex);
printf(”会员学号:%dn",ptr_club-〉xuehao);
printf("所借图书:%sn”,ptr_club->borrow);
printf("n");flag++;}
}
if(flag==0){printf("此用户不存在!nn”);}
returnhead_club;
}
structbook*Lent_Book(intbianhao,intxuehao,structbook*head_book,structclub*
head_club)
{structbook*ptr_book;
structclub*ptr_club;
intflag=0;
for(ptr_book=head_book;ptr_book;ptr_book=ptr_book—>book_next)
for(ptr_club=head_club;ptr_club;ptr_club=ptr_club-〉club_next)
{
if((ptr_book->bianhao==bianhao)&&(ptr_club—>xuehao==xuehao))
{strcpy(ptr_book—>name,ptr_club—>name);/*字符串的复制,把右边的内容复制到左
边*/
strcpy(ptr_book—〉sex,ptr_club-〉sex);
ptr_book-〉xuehao=ptr_club->xuehao;
strcpy(ptr_book—>state,”暂无");
strcpy(ptr_club->borrow,ptr_book->book_name);flag++;}
if(flag==0){printf(”暂无此图书或您还未注册为会员!nn");}
}
returnhead_book;
}
structbook*back(intbianhao,intxuehao,structbook*head_book,structclub*head_club)
{structbook*ptr_book;structclub*ptr_club;
intflag=0;
for(ptr_book=head_book;ptr_book;ptr_book=ptr_book—〉book_next)
for(ptr_club=head_club;ptr_club;ptr_club=ptr_club->club_next)
{
if((ptr_book—>bianhao==bianhao)&&(ptr_club-〉xuehao==xuehao))
{strcpy(ptr_book—〉name,”暂无");strcpy(ptr_book-〉sex,”待定”);
ptr_book-〉xuehao=0;
strcpy(ptr_book—>state,”暂无");
strcpy(ptr_club->borrow,"暂无”);
flag++;}
if(flag==0){printf("输入有误,请重试nn”);}
}
returnhead_book;
}
structbook*Insert_Book(structbook*head_book,structbook*stud_book)
{structbook*ptr_b,*ptr1_b,*ptr2_b;
ptr2_b=head_book;ptr_b=stud_book;
if(head_book==NULL){
head_book=ptr_b;
head_book—>book_next=NULL;
}
else{
while((ptr_b—>bianhao〉ptr2_b->bianhao)&&(ptr2_b—>book_next!=NULL)){
ptr1_b=ptr2_b;ptr2_b=ptr2_b—>book_next;
}
if(ptr_b—>bianhao〈=ptr2_b—>bianhao){
if(head_book==ptr2_b)head_book=ptr_b;
elseptr1_b-〉book_next=ptr_b;
ptr_b->book_next=ptr2_b;
}
else{
ptr2_b—〉book_next=ptr_b;
ptr_b->book_next=NULL;
}
}
returnhead_book;
}
structclub*Insert_Club(structclub*head_club,structclub*stud_club)
{structclub*ptr_c,*ptr1_c,*ptr2_c;
ptr2_c=head_club;ptr_c=stud_club;
if(head_club==NULL){
head_club=ptr_c;
head_club-〉club_next=NULL;
}
else{
while((ptr_c—〉xuehao〉ptr2_c—〉xuehao)&&(ptr2_c->club_next!=NULL)){
ptr1_c=ptr2_c;ptr2_c=ptr2_c—>club_next;
}
if(ptr_c—〉xuehao<=ptr2_c—>xuehao){
if(head_club==ptr2_c)head_club=ptr_c;
elseptr1_c—>club_next=ptr_c;
ptr_c—>club_next=ptr2_c;
}
else{
ptr2_c—>club_next=ptr_c;
ptr_c-〉club_next=NULL;
}
}
returnhead_club;
}
voidPrint_Club(structclub*head_club)
{structclub*ptr_c;
if(head_club==NULL){
printf("n无记录nn");
return;
}
printf("n会员姓名t会员性别t会员学号nn");
for(ptr_c=head_club;ptr_c;ptr_c=ptr_c->club_next)
printf(”%stt%stt%dn”,ptr_c-〉name,ptr_c->sex,ptr_c-〉xuehao);
}
structclub*Delete_Club(structclub*head_club,intxuehao)
{structclub*ptr1_club,*ptr2_club;
while(head_club!=NULL&&head_club—〉xuehao==xuehao){
ptr2_club=head_club;head_club=head_club->club_next;
free(ptr2_club);
}
if(head_club==NULL)returnNULL;
ptr1_club=head_club;ptr2_club=head_club->club_next;
while(ptr2_club!=NULL){
if(ptr2_club->xuehao==xuehao){
ptr1_club—〉club_next=ptr2_club->club_next;
free(ptr2_club);
}
else
ptr1_club=ptr2_club;
ptr2_club=ptr1_club—>club_next;
}
returnhead_club;
}
voidPrint_Book(structbook*head_book)
{structbook*ptr_b;
if(head_book==NULL){
printf("n无记录nn");
return;
}
printf(”n图书编号t图书名称t图书单价t图书作者nn”);
for(ptr_b=head_book;ptr_b;ptr_b=ptr_b->book_next)
printf(”%dtt%stt%.2lftt%snn”,ptr_b-〉bianhao,ptr_b—〉book_name,ptr_b—〉
price,ptr_b->author);
}
更多推荐
c语言图书管理系统
发布评论