① c语言图书管理系统!!
这个其实也不难,我可以帮你完成这样的程序!
② c语言图书管理系统
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
typedef int BOOL;
typedef struct bookinfo
{
char number[15];/*产品编号*/
char name[30];/*产品名称*/
float price;/*单价*/
char auther[20];/*作者*/
BOOL isExit;/*存在状态*/
char lendername[20];/*借书人姓名*/
char lendersex[2];/*借书人性别*/
char lendernum[15];/*借书人学号*/
}BOOKINFO;
void menu()
{
printf("\n\n\n\n\n\n\n");
printf("\t\t\t图书管理系统\n");
printf("\t\t\t1:新进图书基本信息的输入\n");
printf("\t\t\t2:显示全部记录\n");
printf("\t\t\t3:根据图书名称查询图书基本信息\n");
printf("\t\t\t4:根据图书名称对撤销的图书信息进行删除\n");
printf("\t\t\t5:按照图书名称从小大到排序\n");
printf("\t\t\t6:统计某价格以上的图书数量\n");
printf("\t\t\t7:列出所有未借出去的图书信息\n");
printf("\t\t\t8:退出\n");
}
void choice_1_input_new()/*输入新进的图书信息*/
{
char choice;
FILE *p;
BOOKINFO newbook;
system("cls");
while(1)
{
printf("输入图书编号:");
gets(newbook.number);
printf("输入图书名称:");
gets(newbook.name);
printf("输入图书单价:");
scanf("%f",&newbook.price);
while(getchar()!='\n');
printf("输入图书的作者:");
gets(newbook.auther);
printf("输入借书人姓名:");
gets(newbook.lendername);
printf("输入借书人性别:");
gets(newbook.lendersex);
printf("输入借书人学号:");
gets(newbook.lendernum);
printf("是否保存该条书目?(Y/N)\n");
choice=getch();
while(choice!='Y'&&choice!='y'&&choice!='N'&&choice!='n')
choice=getch();
if(choice=='Y'||choice=='y')
{
newbook.isExit=1;/*将图书状态设置成1,表示没有借出*/
p=fopen("c:\\bookinfo.data","ab");
fwrite(&newbook,sizeof(BOOKINFO),1,p);
fclose(p);
printf("\n该条书目已添加到c:\\bookinfo.data文件中!\n");
}
else
{
printf("\n本条书目未保存!\n");
}
printf("\n是否继续添加书目?(Y/N)\n");
choice=getch();
while(choice!='Y'&&choice!='y'&&choice!='N'&&choice!='n')
choice=getch();
if(choice=='Y'||choice=='y')
continue;
else
break;
}
}
void choice_2_display_all()/*显示全部图书信息*/
{
FILE *p;
int n;
BOOKINFO bookinfo[100];
int booknumber=0;
system("cls");
p=fopen("c:\\bookinfo.data","rb");
while(!feof(p))
{
fread(&bookinfo[booknumber],sizeof(BOOKINFO),1,p);
booknumber++;
}
/*booknumber--;使用feof()函数会多读一行,因此需要booknumber自减一次,使书目的数量正确*/
fclose(p);
booknumber--;
if(booknumber==0)
{
printf("没有任何图书信息!\n\n");
}
else
{
n=0;
printf(" 图书信息如下\n");
printf(" 图书信息 | 借书人信息 \n");
printf("编号 名称 单价 作者 图书状态 | 姓名 性别 学号\n");
while(n<booknumber)
{
printf("%-6s%-12s%-8.1f%-8s%-9d| %-12s%-8s%-8s\n",
bookinfo[n].number,bookinfo[n].name,bookinfo[n].price,
bookinfo[n].auther,bookinfo[n].isExit,bookinfo[n].lendername,
bookinfo[n].lendersex,bookinfo[n].lendernum);
n++;
}
}
printf("\n\n按任意键回到主菜单!\n");
getch();
}
void choice_3_search_according_name()/*根据图书名称显示图书的信息*/
{
char search[20]="";/*search用来存放要查询的书名*/
int n;
FILE *p;
char choice;
BOOKINFO bookinfo[100];
int booknumber=0;
system("cls");
p=fopen("c:\\bookinfo.data","rb");
while(!feof(p))
{
fread(&bookinfo[booknumber],sizeof(BOOKINFO),1,p);
booknumber++;
}
booknumber--;/*使用feof()函数会多读一行,因此需要booknumber自减一次,使书目的数量正确*/
fclose(p);
while(1)
{
printf("输入要查询的书本名称:");
gets(search);
if(booknumber==0)
{
printf("书库中没有任何信息!\n\n");
printf("按任意键回到主菜单!\n\n");
getch();
break;
}/*if结束*/
else
{
for(n=0;n<booknumber;n++)
if(strcmp(bookinfo[n].name,search)==0)
{
printf("该书的详细信息如下:\n");
printf(" 图书信息 | 借书人信息 \n");
printf("编号 名称 单价 作者 图书状态 | 姓名 性别 学号\n");
printf("%-6s%-12s%-8.1f%-8s%-9d| %-12s%-8s%-8s\n",
bookinfo[n].number,bookinfo[n].name,bookinfo[n].price,
bookinfo[n].auther,bookinfo[n].isExit,bookinfo[n].lendername,
bookinfo[n].lendersex,bookinfo[n].lendernum);
break;
}
if(n>=booknumber)
printf("没有查找该书的任何信息!\n");
printf("\n\n是否继续查询?(Y/N)\n");
choice=getch();
while(choice!='Y'&&choice!='y'&&choice!='N'&&choice!='n')
choice=getch();
if(choice=='Y'||choice=='y')
continue;
else
break;
}/*else结束*/
}/*while(1)结束*/
}
void choice_4_delete_according_name()/*根据图书名称对图书信息进行删除*/
{
char search[20]="";/*search用来存放要删除的书名*/
int n,i;
FILE *p;
char choice;
BOOKINFO bookinfo[100];
int booknumber;
system("cls");
while(1)
{
printf("输入要删除的书本名称:");
gets(search);
p=fopen("c:\\bookinfo.data","rb");
booknumber=0;
while(!feof(p))
{
fread(&bookinfo[booknumber],sizeof(BOOKINFO),1,p);
booknumber++;
}
booknumber--;/*使用feof()函数会多读一行,因此需要booknumber自减一次,使书目的数量正确*/
fclose(p);
if(booknumber==0)
{
printf("书库中没有任何信息!\n\n");
printf("按任意键回到主菜单!\n\n");
getch();
break;
}/*if结束*/
else
{
for(n=0;n<booknumber;n++)
if(strcmp(bookinfo[n].name,search)==0)
{
break;
}
if(n>=booknumber)
printf("没有查找该书的任何信息!\n");
else
{
printf("是否确认需要删除该条书目?(Y/N)");
choice=getch();
while(choice!='Y'&&choice!='y'&&choice!='N'&&choice!='n')
choice=getch();
if(choice=='Y'||choice=='y')
{
for(i=n;i<booknumber-1;i++)
bookinfo[i]=bookinfo[i+1];
booknumber--;
p=fopen("c:\\bookinfo.data","wb");
for(n=0;n<booknumber;n++)
fwrite(&bookinfo[n],sizeof(BOOKINFO),1,p);
fclose(p);
printf("删除成功!\n");
}
else
printf("\n\n该条书目没有被删除!");
}
printf("\n\n是否继续进行删除操作?(Y/N)\n");
choice=getch();
while(choice!='Y'&&choice!='y'&&choice!='N'&&choice!='n')
choice=getch();
if(choice=='Y'||choice=='y')
continue;
else
break;
}/*else结束*/
}/*while(1)结束*/
}
void choice_5_sort_according_name()/*根据图书名称排序*/
{
FILE *p;
int m,n;
BOOKINFO temp;
BOOKINFO bookinfo[100];
int booknumber;
p=fopen("c:\\bookinfo.data","rb");
booknumber=0;
system("cls");
while(!feof(p))
{
fread(&bookinfo[booknumber],sizeof(BOOKINFO),1,p);
booknumber++;
}
booknumber--;/*使用feof()函数会多读一行,因此需要booknumber自减一次,使书目的数量正确*/
fclose(p);
if(booknumber==0)
{
printf("没有任何图书信息!\n\n");
}
else
{
for(m=0;m<booknumber-1;m++)
for(n=m+1;n<booknumber;n++)
if(strcmp(bookinfo[m].name,bookinfo[n].name)>0)
{
temp=bookinfo[m];
bookinfo[m]=bookinfo[n];
bookinfo[n]=temp;
}
p=fopen("c:\\bookinfo.data","wb");
for(m=0;m<booknumber;m++)
fwrite(&bookinfo[m],sizeof(BOOKINFO),1,p);
fclose(p);
printf("\n\n完成排序!\n\n");
}
printf("按任意键回到主菜单!\n");
getch();
}
void choice_6_display_high_price()/*根据价格列出图书信息*/
{
float price;
FILE *p;
int n;
int count=0;
BOOKINFO bookinfo[100];
int booknumber;
system("cls");
printf("请输入价格:");
scanf("%f",&price);
p=fopen("c:\\bookinfo.data","rb");
booknumber=0;
while(!feof(p))
{
fread(&bookinfo[booknumber],sizeof(BOOKINFO),1,p);
booknumber++;
}
booknumber--;/*使用feof()函数会多读一行,因此需要booknumber自减一次,使书目的数量正确*/
fclose(p);
if(booknumber==0)
{
printf("没有任何图书信息!\n\n");
}
else
{
for(n=0;n<booknumber;n++)
{
if(bookinfo[n].price>=price)
count++;
}
if(count==0)
printf("书库中没有比%.1f$价格高的图书!",price);
else
{
printf(" 价格高于%.1f$的图书信息如下\n",price);
printf(" 图书信息 | 借书人信息 \n");
printf("编号 名称 单价 作者 图书状态 | 姓名 性别 学号\n");
for(n=0;n<booknumber;n++)
{
if(bookinfo[n].price>=price)
printf("%-6s%-12s%-8.1f%-8s%-9d| %-12s%-8s%-8s\n",
bookinfo[n].number,bookinfo[n].name,bookinfo[n].price,
bookinfo[n].auther,bookinfo[n].isExit,bookinfo[n].lendername,
bookinfo[n].lendersex,bookinfo[n].lendernum);
}
}
}
printf("\n\n按任意键回到主菜单!\n");
getch();
}
void choice_7_display_according_exitflag()/*根据存在状态列出图书信息*/
{
FILE *p;
int n;
int count=0;
BOOKINFO bookinfo[100];
int booknumber;
system("cls");
booknumber=0;
p=fopen("c:\\bookinfo.data","rb");
while(!feof(p))
{
fread(&bookinfo[booknumber],sizeof(BOOKINFO),1,p);
booknumber++;
}
booknumber--;
fclose(p);
if(booknumber==0)
{
printf("书库中没有任何书目存在!\n");
}
else
{
for(n=0;n<booknumber;n++)
if(bookinfo[n].isExit==1)
count++;
if(count==0)
printf("书库中的书籍全部借出!\n");
else
{
printf("书库中未被借出的图书信息如下:\n\n");
printf(" 图书信息 | 借书人信息 \n");
printf("编号 名称 单价 作者 图书状态 | 姓名 性别 学号\n");
for(n=0;n<booknumber;n++)
if(bookinfo[n].isExit==1)
{
printf("%-6s%-12s%-8.1f%-8s%-9d| %-12s%-8s%-8s\n",
bookinfo[n].number,bookinfo[n].name,bookinfo[n].price,
bookinfo[n].auther,bookinfo[n].isExit,bookinfo[n].lendername,
bookinfo[n].lendersex,bookinfo[n].lendernum);
}
}
}
printf("\n按任意键返回主菜单!\n");
getch();
}
void main()
{
char choice;
clock_t tm;
FILE *p;
if((p=fopen("c:\\bookinfo.data","rb"))==NULL)
{
p=fopen("c:\\bookinfo.data","wb");
fclose(p);
}
while(1)
{
system("cls");
menu();
choice=getch();
switch(choice)
{
case '1':choice_1_input_new();break;/*输入新进的图书信息*/
case '2':choice_2_display_all();break;/*显示全部图书信息*/
case '3':choice_3_search_according_name();break;/*根据图书名称显示图书的信息*/
case '4':choice_4_delete_according_name();break;/*根据图书名称对图书信息进行删除*/
case '5':choice_5_sort_according_name();break;/*根据图书名称排序*/
case '6':choice_6_display_high_price();break;/*根据价格列出图书信息*/
case '7':choice_7_display_according_exitflag();break;/*根据存在状态列出图书信息*/
case '8':printf("\n\n\t\t\t谢谢使用,再见!\n\t\t\t按任意键退出!\n");getch();return;
default:
printf("\n\n\t\t\t请输入菜单中的数字!(1~8)");
tm=clock();
while(clock()<tm+1800);
break;
}
}
}
写的很赶,不知道行不行
程序很长,但是没什么复杂的东西。
要是写的不好,楼主就将就吧。
③ 用C语言写个图书馆系统
下面可以参考参考!
完整的C语言图书管理系统
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include "graphics.h"
#include "math.h"
#define m 1
struct data
{ int year;
int month;
int day;
};
struct ReaderNode
{
char num[20];
struct data bro;
struct data back;
};
struct BookNode
{
char title[15];
char writer[15];
int currentnum;
int totalnum;
char brief[30];
struct ReaderNode reader[20];
};
struct TreeNode
{
int n;
struct TreeNode *prt;
int key[2*m];
struct BookNode *rec[2*m];
struct TreeNode *link[2*m+1];
};
struct BookNode *InputNode();
struct TreeNode *mbsearch(struct TreeNode *bth,int x,int *k,int *flag);
struct TreeNode *mbinsert(struct TreeNode *bth);
struct TreeNode *mbdel(struct TreeNode *bth);
void OutputNode(struct TreeNode *bth);
void borrow(struct TreeNode *bth);
void payback(struct TreeNode *bth);
char menu(void);
struct TreeNode *mbsearch(struct TreeNode *bth,int x,int *k,int *flag)
{
struct TreeNode *p,*q;
p=bth; *flag=0; q=p;
while( (p!=NULL) && (*flag==0) )
{
*k=1;q=p;
while( (*k < q->n) && ( q->key[*k-1] < x) ) *k=*k+1;
if( q->key[*k-1]==x) *flag=1;
else if( ( *k==q->n ) && ( q->key[*k-1] < x) ) {p=q->link[*k];p->prt=q;}
else { p=q->link[*k-1]; p->prt=q;*k=*k-1;}
}
return(q);
}
struct TreeNode *mbinsert(struct TreeNode *bth)
{
int flag,j,k,t;
int y,x,z;
struct TreeNode *p,*q,*u,*s;
struct BookNode *r,*l;
clrscr();
printf("\n\tPlease input the book you want to insert: ");
scanf("%d",&x);
q=mbsearch(bth,x,&k,&flag);
if(flag==1)
{
printf("\n\tHas %d this kind of book,do you want to add another?(y/n)\n",(q->rec[k-1])->totalnum);
z=getch();
if(z=='y'||z=='Y')
{
(q->rec[k-1])->totalnum++; (q->rec[k-1])->currentnum++;
printf("\n\tNow total has %d this kind of book,",(q->rec[k-1])->totalnum);
printf("\n\tand current has %d in the library.",(q->rec[k-1])->currentnum);
}
return(bth);
}
r=InputNode(bth);
if(bth==NULL)
{
bth=p=(struct TreeNode *)malloc(sizeof(struct TreeNode));
p->n=1; p->key[0]=x; p->rec[0]=r;p->prt=NULL;
for(j=1;j<=2*m+1;j++) p->link[j-1]=NULL;
return(p);
}
p=NULL; t=0;
while(t==0)
{
if(k==q->n) {y=x;l=r;u=p;}
else
{
y=q->key[q->n-1]; l=q->rec[q->n-1];u=q->link[q->n];
for(j=(q->n)-1; j>=k+1; j--)
{
q->key[j]=q->key[j-1];q->rec[j]=q->rec[j-1];q->link[j+1]=q->link[j];
}
q->key[k]=x;q->rec[k]=r;q->link[k+1]=p;
if(p!=NULL) p->prt=q;
}
if(q->n<2*m)
{
q->n=(q->n)+1;
t=1;
q->key[(q->n)-1]=y; q->rec[(q->n)-1]=l; q->link[q->n]=u;
if(u!=NULL) u->prt=q;
}
else
{
p=(struct TreeNode *)malloc(sizeof(struct TreeNode));
p->n=m; q->n=m; p->prt=q->prt;
x=q->key[m];r=q->rec[m];
for(j=1;j<=m-1;j++)
{
p->key[j-1]=q->key[m+j];p->rec[j-1]=q->rec[m+j];p->link[j-1]=q->link[m+j];
if(q->link[m+j]!=NULL) (q->link[m+j])->prt=p;
}
p->link[m-1]=q->link[2*m];
p->link[m]=u;
p->key[m-1]=y;
p->rec[m-1]=l;
if(u!=NULL) u->prt=p;
for(j=m+2;j<=2*m+1;j++)
{
q->link[j-1]=NULL;p->link[j-1]=NULL;
}
if(q->prt==NULL)
{
s=(struct TreeNode *)malloc(sizeof(struct TreeNode));
s->key[0]=x; s->rec[0]=r;
s->link[0]=q; s->link[1]=p;
s->n=1; s->prt=NULL; q->prt=s; p->prt=s;
for(j=3;j<=2*m+1;j++) s->link[j-1]=NULL;
bth=s; t=1;
}
else
{
q=q->prt; k=1;
while((k<=q->n)&&(q->key[k-1]<x)) k=k+1;
k=k-1;
}
}
}
return(bth);
}
struct TreeNode *mbdel(struct TreeNode *bth)
{
int flag,j,k,t;
int x,y;
struct TreeNode *u,*s,*p,*q;
struct BookNode *r,*l;
clrscr();
printf("\n\tPlease input the book you want to delete: ");
scanf("%d",&x);
q=mbsearch(bth,x,&k,&flag);
if(flag==0) { printf("\n\tThe book is not exist!\n"); return(bth);}
p=q->link[k];
if(p!=NULL)
{
while(p->link[0]!=NULL) p=p->link[0];
q->key[k-1]=p->key[0];
q->rec[k-1]=p->rec[0];
k=1;q=p;
}
for(j=k;j<=q->n-1;j++)
{
q->key[j-1]=q->key[j];
q->rec[j-1]=q->rec[j];
}
q->n=q->n-1;
while ((q!=bth)&&(q->n<m))
{
p=q->prt;j=1;
while(p->link[j-1]!=q) j=j+1;
if((j<=p->n)&&((p->link[j])->n>m))
{
s=p->link[j];
y=s->key[0];
l=s->rec[0];
u=s->link[0];
for(k=1;k<=s->n-1;k++)
{
s->key[k-1]=s->key[k];
s->rec[k-1]=s->rec[k];
s->link[k-1]=s->link[k];
}
s->link[s->n-1]=s->link[s->n];
s->link[s->n]=NULL;
s->n=s->n-1; q->n=q->n+1;
q->key[q->n-1]=p->key[j-1];
q->rec[q->n-1]=p->rec[j-1];
q->link[q->n]=u;
p->key[j-1]=y;
p->rec[j-1]=l;
if(u!=NULL) u->prt=q;
}
else if((j>1)&&((p->link[j-2])->n>m))
{
s=p->link[j-2];
q->n=q->n+1;
q->link[q->n]=q->link[q->n-1];
for(k=q->n-1;k>=1;k--)
{
q->key[k]=q->key[k-1];
q->rec[k]=q->rec[k-1];
q->link[k]=q->link[k-1];
}
q->key[0]=p->key[j-2];
q->rec[0]=p->rec[j-2];
u=s->link[s->n];
q->link[0]=u;
if(u!=NULL) u->prt=q;
p->key[j-2]=s->key[s->n-1];
p->rec[j-2]=s->rec[s->n-1];
s->link[s->n]=NULL;
s->n=s->n-1;
}
else
{
if(j==p->n+1)
{ q=p->link[j-2]; s=p->link[j-1]; j=j-1;}
else s=p->link[j];
q->key[q->n]=p->key[j-1];
q->rec[q->n]=p->rec[j-1];
t=q->n+1;
for(k=1;k<=s->n;k++)
{ q->key[t+k-1]=s->key[k-1];
q->rec[t+k-1]=s->rec[k-1];
u=s->link[k-1];
q->link[t+k-1]=u;
if(u!=NULL) u->prt=q;
}
u=s->link[s->n]; q->link[t+s->n]=u;
if(u!=NULL) u->prt=q;
q->n=2*m;
free(s);
for(k=j;k<=p->n-1;k++)
{
p->key[k-1]=p->key[k];
p->rec[k-1]=p->rec[k];
p->link[k]=p->link[k+1];
}
p->n=p->n-1; s=q; q=p;
}
}
if((q==bth)&&(q->n==0))
{ free(bth); bth=s; bth->prt=NULL;
if(s->n==0) {bth=NULL; free(s); }
}
printf("\n\tThe book has been delete !");
return(bth);
}
struct BookNode *InputNode()
{
struct BookNode *p;
int i;
p=(struct BookNode *)malloc(sizeof(struct BookNode));
clrscr();
fflush(stdin);
printf("\n\tInput the title: ");
gets(p->title);
printf("\n\tInput the writer: ");
gets(p->writer);
printf("\n\tInput the book current amount: ");
scanf("%d",&p->currentnum);
printf("\n\tInput the book total amount: ");
scanf("%d",&p->totalnum);
fflush(stdin);
printf("\n\tInput the book brief instruction: ");
gets(p->brief);
for(i=0;i<20;i++)
(p->reader[i]).num[0]='\0';
return(p);
}
void OutputNode(struct TreeNode *bth)
{
struct TreeNode *q;
struct BookNode *p;
int k;
int x;
int flag;
clrscr();
printf("\n\tPlease input the book you want to search: ");
scanf("%d",&x);
q=mbsearch(bth,x,&k,&flag);
if(flag==1)
{
p=q->rec[k-1];
printf("\n\tTitle: %s",p->title);
printf("\n\tWriter: %s",p->writer);
printf("\n\tCurrentAmount: %d",p->currentnum);
printf("\n\tTotalAmount: %d",p->totalnum);
printf("\n\tBriefIntroction: %s\n",p->brief);
}
else printf("\n\tThis book is not exist!");
}
void borrow(struct TreeNode *bth)
{
struct TreeNode *q;
struct BookNode *p;
struct ReaderNode *r;
int i,k, x, flag,t;
clrscr();
printf("\n\tPlease input the book you want to borrow: ");
scanf("%d",&x);
q=mbsearch(bth,x,&k,&flag);
if(flag==1)
{
p=q->rec[k-1];
printf("\n\tDo you want this book ?(y/n)");
printf("\n\tTitle: %s",p->title);
printf("\n\tWriter: %s",p->writer);
printf("\n\tCurrentAmount: %d",p->currentnum);
printf("\n\tTotalAmount: %d",p->totalnum);
printf("\n\tBriefIntroction: %s",p->brief);
t=getch();
if(t=='y'||t=='Y')
{
if( (p->currentnum)==0) printf("\n\tSorry,this book has all borrow out...");
else
{
clrscr();
for(i=0;i<20;i++) if( (p->reader[i]).num[0]=='\0') break;
printf("\n\tPlease input your certificate number: ");
scanf("%s",(p->reader[i]).num);
printf("\n\tPlease input the borrow data: ");
printf("\n\tYear: ");
scanf("%d",&((p->reader[i]).bro.year));
printf("\tMonth: ");
scanf("%d",&((p->reader[i]).bro.month));
printf("\tDay: ");
scanf("%d",&((p->reader[i]).bro.day));
printf("\n\tPlease input the payback data: ");
printf("\n\tYear: ");
scanf("%d",&((p->reader[i]).back.year));
printf("\tMonth: ");
scanf("%d",&((p->reader[i]).back.month));
printf("\tDay: ");
scanf("%d",&((p->reader[i]).back.day));
p->currentnum--;
printf("\n\tYou have borrow the book.");}
}
}
else printf("\n\tThis book is not exist!");
}
void payback(struct TreeNode *bth)
{
struct TreeNode *q;
struct BookNode *p;
int i,k, x, flag,t,j;
int year,month,day,d;
float pay;
char temp[20];
clrscr();
printf("\n\tPlease input the book you want to payback: ");
scanf("%d",&x);
q=mbsearch(bth,x,&k,&flag);
if(flag==1)
{
p=q->rec[k-1];
printf("\n\tDo you want to payback this book ?(y/n)");
printf("\n\tTitle: %s",p->title);
printf("\n\tWriter: %s",p->writer);
printf("\n\tCurrentAmount: %d",p->currentnum);
printf("\n\tTotalAmount: %d",p->totalnum);
printf("\n\tBriefIntroction: %s",p->brief);
t=getch();
if(t=='y'||t=='Y')
{
if( (p->currentnum) >=(p->totalnum) )
printf("\n\tYou want to offer a more book ??\n");
else
{
clrscr();
printf("\n\tPlease input your certificate number: ");
scanf("%s",temp);
j=0;
for(i=0;i<20;i++)
{
if(! (strcmp(temp,(p->reader[i]).num))) {j=1;break;}
}
if(j==0) {printf("\n\tYou haven't borrow this book.");return;}
printf("\n\tToday is:");
printf("\n\tYear: ");
scanf("%d",&year);
printf("\tMonth: ");
scanf("%d",&month);
printf("\tDay: ");
scanf("%d",&day);
d=0;
if(year<(p->reader[i]).back.year) d=1;
if(year<=(p->reader[i]).back.year && month<(p->reader[i]).back.month) d=1;
if(year<=(p->reader[i]).back.year && month<=(p->reader[i]).back.month && day<(p->reader[i]).back.day) d=1;
if(d==0)
{
clrscr();
pay=(year-(p->reader[i]).back.year)*365+(month-(p->reader[i]).back.month)*30+(day-(p->reader[i]).back.day);
printf("\n\tYou borrow this book is in %d-%d-%d",(p->reader[i]).bro.year,(p->reader[i]).bro.month,(p->reader[i]).bro.day);
printf("\n\tYou should pay it back in %d-%d-%d",(p->reader[i]).back.year,(p->reader[i]).back.month,(p->reader[i]).back.day);
printf("\n\tToday is %d-%d-%d",year,month,day);
printf("\n\n\tSo you have go out the payback day");
printf("\n\tYou have to pay %2.1f Yuan.",0.1*pay);
}
(p->reader[i]).num[0]='\0';
p->currentnum++;
printf("\n\tYou have payback the book.");
}
}
}
else printf("\n\tYou want to payback an inexistence book ???");
}
donghua()
{int graphdriver=VGA;
int graphmode=VGAHI;
int i,j;
registerbgidriver(EGAVGA_driver);
initgraph(&graphdriver,&graphmode,"");
clrscr();
for(i=0;i<=150;i+=5)
{setcolor(i);
textbackground(RED);
settextstyle(0,0,2);
outtextxy(100,i+140,"Liberary management System");
delay(10000000);
clrscr();
}
setcolor(RED);
outtextxy(50,200,"Loading");
delay(100000000000);
outtextxy(50,200,"Loading.");
delay(100000000000);
outtextxy(50,200,"Loading..");
delay(100000000000);
outtextxy(50,200,"Loading...");
delay(100000000000);
outtextxy(50,200,"Loading....");
delay(100000000000);
outtextxy(50,200,"Loading.....");
delay(100000000000);
outtextxy(50,200,"Loading......");
delay(100000000000);
outtextxy(50,200,"Loading.......");
delay(100000000000);
outtextxy(50,200,"Loading........");
delay(100000000000);
outtextxy(50,200,"Loading.........");
delay(100000000000);
outtextxy(50,200,"Loading..........");
delay(100000000000);
outtextxy(50,200,"Loading...........");
outtextxy(50,200,"Loading............");
delay(100000000000);
for(i=0;i<=10;i++)
delay(100000000000);
clrscr();
}
char menu(void)
{
clrscr();
window(1,1,80,25);
textmode(MONO);
textbackground(BLACK);
textcolor(5);
printf("\n\t ****************************************************");
printf("\n\t ***** Welcome to Liberary management System *****");
printf("\n\t ****************************************************");
printf("\n\t ****************************************************");
printf("\n\t *1.Add a book *");
printf("\n\t ****************************************************");
printf("\n\t *2.Delete a book *");
printf("\n\t ****************************************************");
printf("\n\t *3.Search a book *");
printf("\n\t ****************************************************");
printf("\n\t *4.Borrow a book *");
printf("\n\t ****************************************************");
printf("\n\t *5.Payback a book *");
printf("\n\t ****************************************************");
printf("\n\t *0.exit *");
printf("\n\t ****************************************************");
printf("\n\t please select: ");
return getch();
}
bofangdonghua()
{int graphdriver=VGA;
int graphmode=VGAHI;
int i,j;
char c;
registerbgidriver(EGAVGA_driver);
initgraph(&graphdriver,&graphmode,"");
/*************shi fou bo fang dong hua?**************/
printf:{setcolor(RED);
settextstyle(3,0,5);
outtextxy(100,30,"bo fang dong hua?");
outtextxy(150,80,"Yes");
outtextxy(300,80,"No");
c=getch();
if(c=='Y'||c=='y')
{donghua();
menu();
}
else
if(c=='N'||c=='n')
menu();
else
{setcolor(GREEN);
settextstyle(3,0,8);
outtextxy(200,240,"Error!");
delay(10000000000);
clrscr();
goto printf;
}
}
/**************************************/
}
void main()
{
char c,t;
int x;
int k,flag,p=1;
struct TreeNode *bth=NULL;
bofangdonghua();
while(1)
{
c=menu();
putch(c);
getch();
switch(c)
{
case '1': bth=mbinsert(bth);
break;
case '2': bth=mbdel(bth);
break;
case '3': OutputNode(bth);
break;
case '4': borrow(bth);
break;
case '5': payback(bth);
break;
case '0': clrscr();
printf("\n\tDo you want to return ?(y/n)");
t=getch();
if(t=='y'||t=='Y') exit(0);
break;
defult :break;
}
printf("\n\tPress any key to the main menu....");
getch();
}
}
④ 图书馆图书管理系统(c语言)
完整的C语言图书管理系统
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include "graphics.h"
#include "math.h"
#define m 1
struct data
{ int year;
int month;
int day;
};
struct ReaderNode
{
char num[20];
struct data bro;
struct data back;
};
struct BookNode
{
char title[15];
char writer[15];
int currentnum;
int totalnum;
char brief[30];
struct ReaderNode reader[20];
};
struct TreeNode
{
int n;
struct TreeNode *prt;
int key[2*m];
struct BookNode *rec[2*m];
struct TreeNode *link[2*m+1];
};
struct BookNode *InputNode();
struct TreeNode *mbsearch(struct TreeNode *bth,int x,int *k,int *flag);
struct TreeNode *mbinsert(struct TreeNode *bth);
struct TreeNode *mbdel(struct TreeNode *bth);
void OutputNode(struct TreeNode *bth);
void borrow(struct TreeNode *bth);
void payback(struct TreeNode *bth);
char menu(void);
struct TreeNode *mbsearch(struct TreeNode *bth,int x,int *k,int *flag)
{
struct TreeNode *p,*q;
p=bth; *flag=0; q=p;
while( (p!=NULL) && (*flag==0) )
{
*k=1;q=p;
while( (*k < q->n) && ( q->key[*k-1] < x) ) *k=*k+1;
if( q->key[*k-1]==x) *flag=1;
else if( ( *k==q->n ) && ( q->key[*k-1] < x) ) {p=q->link[*k];p->prt=q;}
else { p=q->link[*k-1]; p->prt=q;*k=*k-1;}
}
return(q);
}
struct TreeNode *mbinsert(struct TreeNode *bth)
{
int flag,j,k,t;
int y,x,z;
struct TreeNode *p,*q,*u,*s;
struct BookNode *r,*l;
clrscr();
printf("\n\tPlease input the book you want to insert: ");
scanf("%d",&x);
q=mbsearch(bth,x,&k,&flag);
if(flag==1)
{
printf("\n\tHas %d this kind of book,do you want to add another?(y/n)\n",(q->rec[k-1])->totalnum);
z=getch();
if(z=='y'||z=='Y')
{
(q->rec[k-1])->totalnum++; (q->rec[k-1])->currentnum++;
printf("\n\tNow total has %d this kind of book,",(q->rec[k-1])->totalnum);
printf("\n\tand current has %d in the library.",(q->rec[k-1])->currentnum);
}
return(bth);
}
r=InputNode(bth);
if(bth==NULL)
{
bth=p=(struct TreeNode *)malloc(sizeof(struct TreeNode));
p->n=1; p->key[0]=x; p->rec[0]=r;p->prt=NULL;
for(j=1;j<=2*m+1;j++) p->link[j-1]=NULL;
return(p);
}
p=NULL; t=0;
while(t==0)
{
if(k==q->n) {y=x;l=r;u=p;}
else
{
y=q->key[q->n-1]; l=q->rec[q->n-1];u=q->link[q->n];
for(j=(q->n)-1; j>=k+1; j--)
{
q->key[j]=q->key[j-1];q->rec[j]=q->rec[j-1];q->link[j+1]=q->link[j];
}
q->key[k]=x;q->rec[k]=r;q->link[k+1]=p;
if(p!=NULL) p->prt=q;
}
if(q->n<2*m)
{
q->n=(q->n)+1;
t=1;
q->key[(q->n)-1]=y; q->rec[(q->n)-1]=l; q->link[q->n]=u;
if(u!=NULL) u->prt=q;
}
else
{
p=(struct TreeNode *)malloc(sizeof(struct TreeNode));
p->n=m; q->n=m; p->prt=q->prt;
x=q->key[m];r=q->rec[m];
for(j=1;j<=m-1;j++)
{
p->key[j-1]=q->key[m+j];p->rec[j-1]=q->rec[m+j];p->link[j-1]=q->link[m+j];
if(q->link[m+j]!=NULL) (q->link[m+j])->prt=p;
}
p->link[m-1]=q->link[2*m];
p->link[m]=u;
p->key[m-1]=y;
p->rec[m-1]=l;
if(u!=NULL) u->prt=p;
for(j=m+2;j<=2*m+1;j++)
{
q->link[j-1]=NULL;p->link[j-1]=NULL;
}
if(q->prt==NULL)
{
s=(struct TreeNode *)malloc(sizeof(struct TreeNode));
s->key[0]=x; s->rec[0]=r;
s->link[0]=q; s->link[1]=p;
s->n=1; s->prt=NULL; q->prt=s; p->prt=s;
for(j=3;j<=2*m+1;j++) s->link[j-1]=NULL;
bth=s; t=1;
}
else
{
q=q->prt; k=1;
while((k<=q->n)&&(q->key[k-1]<x)) k=k+1;
k=k-1;
}
}
}
return(bth);
}
struct TreeNode *mbdel(struct TreeNode *bth)
{
int flag,j,k,t;
int x,y;
struct TreeNode *u,*s,*p,*q;
struct BookNode *r,*l;
clrscr();
printf("\n\tPlease input the book you want to delete: ");
scanf("%d",&x);
q=mbsearch(bth,x,&k,&flag);
if(flag==0) { printf("\n\tThe book is not exist!\n"); return(bth);}
p=q->link[k];
if(p!=NULL)
{
while(p->link[0]!=NULL) p=p->link[0];
q->key[k-1]=p->key[0];
q->rec[k-1]=p->rec[0];
k=1;q=p;
}
for(j=k;j<=q->n-1;j++)
{
q->key[j-1]=q->key[j];
q->rec[j-1]=q->rec[j];
}
q->n=q->n-1;
while ((q!=bth)&&(q->n<m))
{
p=q->prt;j=1;
while(p->link[j-1]!=q) j=j+1;
if((j<=p->n)&&((p->link[j])->n>m))
{
s=p->link[j];
y=s->key[0];
l=s->rec[0];
u=s->link[0];
for(k=1;k<=s->n-1;k++)
{
s->key[k-1]=s->key[k];
s->rec[k-1]=s->rec[k];
s->link[k-1]=s->link[k];
}
s->link[s->n-1]=s->link[s->n];
s->link[s->n]=NULL;
s->n=s->n-1; q->n=q->n+1;
q->key[q->n-1]=p->key[j-1];
q->rec[q->n-1]=p->rec[j-1];
q->link[q->n]=u;
p->key[j-1]=y;
p->rec[j-1]=l;
if(u!=NULL) u->prt=q;
}
else if((j>1)&&((p->link[j-2])->n>m))
{
s=p->link[j-2];
q->n=q->n+1;
q->link[q->n]=q->link[q->n-1];
for(k=q->n-1;k>=1;k--)
{
q->key[k]=q->key[k-1];
q->rec[k]=q->rec[k-1];
q->link[k]=q->link[k-1];
}
q->key[0]=p->key[j-2];
q->rec[0]=p->rec[j-2];
u=s->link[s->n];
q->link[0]=u;
if(u!=NULL) u->prt=q;
p->key[j-2]=s->key[s->n-1];
p->rec[j-2]=s->rec[s->n-1];
s->link[s->n]=NULL;
s->n=s->n-1;
}
else
{
if(j==p->n+1)
{ q=p->link[j-2]; s=p->link[j-1]; j=j-1;}
else s=p->link[j];
q->key[q->n]=p->key[j-1];
q->rec[q->n]=p->rec[j-1];
t=q->n+1;
for(k=1;k<=s->n;k++)
{ q->key[t+k-1]=s->key[k-1];
q->rec[t+k-1]=s->rec[k-1];
u=s->link[k-1];
q->link[t+k-1]=u;
if(u!=NULL) u->prt=q;
}
u=s->link[s->n]; q->link[t+s->n]=u;
if(u!=NULL) u->prt=q;
q->n=2*m;
free(s);
for(k=j;k<=p->n-1;k++)
{
p->key[k-1]=p->key[k];
p->rec[k-1]=p->rec[k];
p->link[k]=p->link[k+1];
}
p->n=p->n-1; s=q; q=p;
}
}
if((q==bth)&&(q->n==0))
{ free(bth); bth=s; bth->prt=NULL;
if(s->n==0) {bth=NULL; free(s); }
}
printf("\n\tThe book has been delete !");
return(bth);
}
struct BookNode *InputNode()
{
struct BookNode *p;
int i;
p=(struct BookNode *)malloc(sizeof(struct BookNode));
clrscr();
fflush(stdin);
printf("\n\tInput the title: ");
gets(p->title);
printf("\n\tInput the writer: ");
gets(p->writer);
printf("\n\tInput the book current amount: ");
scanf("%d",&p->currentnum);
printf("\n\tInput the book total amount: ");
scanf("%d",&p->totalnum);
fflush(stdin);
printf("\n\tInput the book brief instruction: ");
gets(p->brief);
for(i=0;i<20;i++)
(p->reader[i]).num[0]='\0';
return(p);
}
void OutputNode(struct TreeNode *bth)
{
struct TreeNode *q;
struct BookNode *p;
int k;
int x;
int flag;
clrscr();
printf("\n\tPlease input the book you want to search: ");
scanf("%d",&x);
q=mbsearch(bth,x,&k,&flag);
if(flag==1)
{
p=q->rec[k-1];
printf("\n\tTitle: %s",p->title);
printf("\n\tWriter: %s",p->writer);
printf("\n\tCurrentAmount: %d",p->currentnum);
printf("\n\tTotalAmount: %d",p->totalnum);
printf("\n\tBriefIntroction: %s\n",p->brief);
}
else printf("\n\tThis book is not exist!");
}
void borrow(struct TreeNode *bth)
{
struct TreeNode *q;
struct BookNode *p;
struct ReaderNode *r;
int i,k, x, flag,t;
clrscr();
printf("\n\tPlease input the book you want to borrow: ");
scanf("%d",&x);
q=mbsearch(bth,x,&k,&flag);
if(flag==1)
{
p=q->rec[k-1];
printf("\n\tDo you want this book ?(y/n)");
printf("\n\tTitle: %s",p->title);
printf("\n\tWriter: %s",p->writer);
printf("\n\tCurrentAmount: %d",p->currentnum);
printf("\n\tTotalAmount: %d",p->totalnum);
printf("\n\tBriefIntroction: %s",p->brief);
t=getch();
if(t=='y'||t=='Y')
{
if( (p->currentnum)==0) printf("\n\tSorry,this book has all borrow out...");
else
{
clrscr();
for(i=0;i<20;i++) if( (p->reader[i]).num[0]=='\0') break;
printf("\n\tPlease input your certificate number: ");
scanf("%s",(p->reader[i]).num);
printf("\n\tPlease input the borrow data: ");
printf("\n\tYear: ");
scanf("%d",&((p->reader[i]).bro.year));
printf("\tMonth: ");
scanf("%d",&((p->reader[i]).bro.month));
printf("\tDay: ");
scanf("%d",&((p->reader[i]).bro.day));
printf("\n\tPlease input the payback data: ");
printf("\n\tYear: ");
scanf("%d",&((p->reader[i]).back.year));
printf("\tMonth: ");
scanf("%d",&((p->reader[i]).back.month));
printf("\tDay: ");
scanf("%d",&((p->reader[i]).back.day));
p->currentnum--;
printf("\n\tYou have borrow the book.");}
}
}
else printf("\n\tThis book is not exist!");
}
void payback(struct TreeNode *bth)
{
struct TreeNode *q;
struct BookNode *p;
int i,k, x, flag,t,j;
int year,month,day,d;
float pay;
char temp[20];
clrscr();
printf("\n\tPlease input the book you want to payback: ");
scanf("%d",&x);
q=mbsearch(bth,x,&k,&flag);
if(flag==1)
{
p=q->rec[k-1];
printf("\n\tDo you want to payback this book ?(y/n)");
printf("\n\tTitle: %s",p->title);
printf("\n\tWriter: %s",p->writer);
printf("\n\tCurrentAmount: %d",p->currentnum);
printf("\n\tTotalAmount: %d",p->totalnum);
printf("\n\tBriefIntroction: %s",p->brief);
t=getch();
if(t=='y'||t=='Y')
{
if( (p->currentnum) >=(p->totalnum) )
printf("\n\tYou want to offer a more book ??\n");
else
{
clrscr();
printf("\n\tPlease input your certificate number: ");
scanf("%s",temp);
j=0;
for(i=0;i<20;i++)
{
if(! (strcmp(temp,(p->reader[i]).num))) {j=1;break;}
}
if(j==0) {printf("\n\tYou haven't borrow this book.");return;}
printf("\n\tToday is:");
printf("\n\tYear: ");
scanf("%d",&year);
printf("\tMonth: ");
scanf("%d",&month);
printf("\tDay: ");
scanf("%d",&day);
d=0;
if(year<(p->reader[i]).back.year) d=1;
if(year<=(p->reader[i]).back.year && month<(p->reader[i]).back.month) d=1;
if(year<=(p->reader[i]).back.year && month<=(p->reader[i]).back.month && day<(p->reader[i]).back.day) d=1;
if(d==0)
{
clrscr();
pay=(year-(p->reader[i]).back.year)*365+(month-(p->reader[i]).back.month)*30+(day-(p->reader[i]).back.day);
printf("\n\tYou borrow this book is in %d-%d-%d",(p->reader[i]).bro.year,(p->reader[i]).bro.month,(p->reader[i]).bro.day);
printf("\n\tYou should pay it back in %d-%d-%d",(p->reader[i]).back.year,(p->reader[i]).back.month,(p->reader[i]).back.day);
printf("\n\tToday is %d-%d-%d",year,month,day);
printf("\n\n\tSo you have go out the payback day");
printf("\n\tYou have to pay %2.1f Yuan.",0.1*pay);
}
(p->reader[i]).num[0]='\0';
p->currentnum++;
printf("\n\tYou have payback the book.");
}
}
}
else printf("\n\tYou want to payback an inexistence book ???");
}
donghua()
{int graphdriver=VGA;
int graphmode=VGAHI;
int i,j;
registerbgidriver(EGAVGA_driver);
initgraph(&graphdriver,&graphmode,"");
clrscr();
for(i=0;i<=150;i+=5)
{setcolor(i);
textbackground(RED);
settextstyle(0,0,2);
outtextxy(100,i+140,"Liberary management System");
delay(10000000);
clrscr();
}
setcolor(RED);
outtextxy(50,200,"Loading");
delay(100000000000);
outtextxy(50,200,"Loading.");
delay(100000000000);
outtextxy(50,200,"Loading..");
delay(100000000000);
outtextxy(50,200,"Loading...");
delay(100000000000);
outtextxy(50,200,"Loading....");
delay(100000000000);
outtextxy(50,200,"Loading.....");
delay(100000000000);
outtextxy(50,200,"Loading......");
delay(100000000000);
outtextxy(50,200,"Loading.......");
delay(100000000000);
outtextxy(50,200,"Loading........");
delay(100000000000);
outtextxy(50,200,"Loading.........");
delay(100000000000);
outtextxy(50,200,"Loading..........");
delay(100000000000);
outtextxy(50,200,"Loading...........");
outtextxy(50,200,"Loading............");
delay(100000000000);
for(i=0;i<=10;i++)
delay(100000000000);
clrscr();
}
char menu(void)
{
clrscr();
window(1,1,80,25);
textmode(MONO);
textbackground(BLACK);
textcolor(5);
printf("\n\t ****************************************************");
printf("\n\t ***** Welcome to Liberary management System *****");
printf("\n\t ****************************************************");
printf("\n\t ****************************************************");
printf("\n\t *1.Add a book *");
printf("\n\t ****************************************************");
printf("\n\t *2.Delete a book *");
printf("\n\t ****************************************************");
printf("\n\t *3.Search a book *");
printf("\n\t ****************************************************");
printf("\n\t *4.Borrow a book *");
printf("\n\t ****************************************************");
printf("\n\t *5.Payback a book *");
printf("\n\t ****************************************************");
printf("\n\t *0.exit *");
printf("\n\t ****************************************************");
printf("\n\t please select: ");
return getch();
}
bofangdonghua()
{int graphdriver=VGA;
int graphmode=VGAHI;
int i,j;
char c;
registerbgidriver(EGAVGA_driver);
initgraph(&graphdriver,&graphmode,"");
/*************shi fou bo fang dong hua?**************/
printf:{setcolor(RED);
settextstyle(3,0,5);
outtextxy(100,30,"bo fang dong hua?");
outtextxy(150,80,"Yes");
outtextxy(300,80,"No");
c=getch();
if(c=='Y'||c=='y')
{donghua();
menu();
}
else
if(c=='N'||c=='n')
menu();
else
{setcolor(GREEN);
settextstyle(3,0,8);
outtextxy(200,240,"Error!");
delay(10000000000);
clrscr();
goto printf;
}
}
/**************************************/
}
void main()
{
char c,t;
int x;
int k,flag,p=1;
struct TreeNode *bth=NULL;
bofangdonghua();
while(1)
{
c=menu();
putch(c);
getch();
switch(c)
{
case '1': bth=mbinsert(bth);
break;
case '2': bth=mbdel(bth);
break;
case '3': OutputNode(bth);
break;
case '4': borrow(bth);
break;
case '5': payback(bth);
break;
case '0': clrscr();
printf("\n\tDo you want to return ?(y/n)");
t=getch();
if(t=='y'||t=='Y') exit(0);
break;
defult :break;
}
printf("\n\tPress any key to the main menu....");
getch();
}
}
⑤ C语言编译图书管理系统代码
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
struct BOOK
{
int id,usr[10],total,store,days[10];
char name[31],author[21];
}books[100];
/*上面是结构体的定义,用于存放书籍及借书的信息。*/
void page_title(char *menu_item)
{
clrscr();
printf(">>> 图 书 管 理 系 统 <<<\n\n- %s -\n\n",menu_item);
}
/*上面是打印页眉的函数,同时通过参数menu_item,可以显示当前的状态。*/
void return_confirm(void)
{
printf("\n按任意键返回……\n");
getch();
}
/*上面是返回前请求确认的函数,以便在返回前观察结果*/
int search_book(void)
{
int n,i;
printf("请输入图书序号:");
scanf("%d",&i);
for(n=0;n<100;n++)
{
if(books[n].id==i)
{
printf("书名:%s\n",books[n].name);
printf("作者:%s\n",books[n].author);
printf("存数:%d of ",books[n].store);
printf("%d\n",books[n].total);
return n;
}
}
printf("\n输入错误或无效图书序号.\n");
return -1;
}
/*上面的函数是在数组中找到图书号匹配的记录,显示其信息并返
回数组下标,如果找不到相应记录则提示错误并返回-1。*/
void book_out(void)
{
int n,s,l,d;
page_title("借阅图书");
if((n=search_book())!=-1&&books[n].store>0)
{
printf("请输入借书证序号:");
scanf("%d",&s);
printf("请输入可借天数:");
scanf("%d",&d);
for(l=0;l<10;l++)
{
if(books[n].usr[l]==0)
{
books[n].usr[l]=s;
books[n].days[l]=d;
break;
}
}
books[n].store--;
}
if(n!=-1&&books[n].store==0) printf("此书已经全部借出.\n");
return_confirm();
}
/*上面是借书的函数,首先调用找书函数*/
void book_in(void)
{
int n,s,l;
page_title("归还图书");
if((n=search_book())!=-1&&books[n].store<books[n].total)
{
printf("借阅者图书证列表:\n");
for(l=0;l<10;l++)
if (books[n].usr[l]!=0)
printf("[%d] - %d天\n",books[n].usr[l],books[n].days[l]);
printf("请输入借书证序号:");
scanf("%d",&s);
for(l=0;l<10;l++)
{
if(books[n].usr[l]==s)
{
books[n].usr[l]=0;
books[n].days[l]=0;
break;
}
}
books[n].store++;
}
if(n!=-1&&books[n].store==books[n].total)
printf("全部入藏.\n");
return_confirm();
}
void book_add(void)
{
int n;
page_title("注册新书");
for(n=0;n<100;n++)
if(books[n].id==0) break;
printf("序号:");
scanf("%d",&books[n].id);
printf("书名:");
scanf("%s",&books[n].name);
printf("作者:");
scanf("%s",&books[n].author);
printf("数量:");
scanf("%d",&books[n].total);
books[n].store=books[n].total;
return_confirm();
}
void book_del(void)
{
int n;
page_title("注销旧书");
if((n=search_book())!=-1) books[n].id=0;
printf("该书已注销.\n");
return_confirm();
}
void main(void)
{
menu: page_title("操作选单");
printf("请用数字键选择操作\n\n");
printf("1 借阅图书\n2 归还图书\n\n");
printf("3 注册新书\n4 注销旧书\n\n");
printf("\n0 退出\n");
switch(getch())
{
case '1' : book_out();break;
case '2' : book_in();break;
case '3' : book_add();break;
case '4' : book_del();break;
case '0' : exit(0);
}
goto menu;
}
{
int n;
page_title("广?症慕");
if((n=search_book())!=-1) books[n].id=0;
printf("乎慕厮广?.\n");
return_confirm();
}
void main(void)
{
menu: page_title("荷恬佥汽");
printf("萩喘方忖囚佥夲荷恬\n\n");
printf("1 処堋夕慕\n2 拷珊夕慕\n\n");
printf("3 广过仟慕\n4 广?症慕\n\n");
printf("\n0 曜竃\n");
switch(getch())
{
case '1' : book_out();break;
case '2' : book_in();break;
case '3' : book_add();break;
case '4' : book_del();break;
case '0' : exit(0);
}
goto menu;
}
自己运行一下
⑥ 图书信息管理系统C语言
没有安装其他浏览器也没有关系,windows自带的有IE浏览器,进入网络一下页面,搜索
C++图书信息管理系统
,进入二级页面点击下载,选择路径即可
⑦ C语言编写的图书管理系统
你这个问题得拿RMB来求了。。。
⑧ C语言图书管理系统程序
#include<windows.h>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<conio.h>
struct book{
char number[100];
char tittle[100];
char writer[100];
char publisher[100];
char date[100];
char price[100];
char status[100];
char reader[100];
};
void search_book();
void borrow_book();
void return_book();
void add_book();
void delete_book();
void modify_book();
void scan_book();
int main()
{
int c1=0,c2,c3;
int l,x,z;
while(1)
{
system("color 2C");
printf("\t\t\t ^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^ \n");
printf("\t\t\t| * - * - * -图书管理系统 * - * - * |\n");
printf("\t\t\t* [1] 用户登录 *\n");
printf("\t\t\t* [2] 管理员登录 *\n");
printf("\t\t\t^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^ \n");
printf("\n");
printf("请选择你的操作 :");
scanf("%d",&c1);
system("cls");
break;
}
if(c1==1)
{
while(1){
system("color 2C");
printf("\t\t\t ^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^ \n");
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| [5] 退出图书管理系统 |\n");
printf("\t\t\t^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^ \n");
printf("\n");
printf("请选择你的操作 :");
scanf("%d",&c2);
getchar();
switch(c2)
{
case 1:search_book(); break;
case 2:borrow_book(); break;
case 3:return_book(); break;
case 4:scan_book(); break;
case 5:system("cls"); return 0;
}
}
}
if(c1==2)
{
while(1){
system("color 2C");
printf("\t\t\t ^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^ \n");
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| [5] 退出图书管理系统 |\n");
printf("\t\t\t^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^ \n");
printf("\n");
printf("请选择你的操作 :");
scanf("%d",&c3);
getchar();
switch(c3)
{
case 1:add_book(); break;
case 2:delete_book(); break;
case 3:modify_book(); break;
case 4:scan_book(); break;
case 5:system("cls"); return 0;
}
}
}
}
/*查询图书*/
void search_book()
{
FILE*fp;
struct book n;
struct book nn;
int l,r;
char x,z;
fp=fopen("F:\\课程设计\\图书管理系统.txt","rb");
while(1)
{
l=0;
system("cls");
printf("请输入图书名称:");
scanf("%s",n.tittle);
fflush(stdin);
rewind(fp);
while(1)
{
fread(&nn,sizeof(nn),1,fp);
if(feof(fp))
break;
r=strcmp(n.tittle,nn.tittle );
if(r==0)
{
l=1;
break;
}
}
if(l==0)
{
printf("没有要查询的图书!!!\n\n ");
}
else
{
printf("查询的图书为:");
printf("\n");
printf("****************************************\n");
printf("编号 书名 作者 出版社 出版时间 价格 状态 借阅者\n");
printf("\n");
printf("%s %s %s %s %s %s %s",nn.number,nn.tittle,nn.writer,nn.publisher,nn.date,nn.price,nn.status,nn.reader);
printf("\n\n\n");
}
printf("是否继续查询图书 ? [是(y)/否(n)] ? \n\n");
do
{
x=getche();
}while(x!='n'&&x!='y');
if(x=='n')
break;
}
fclose(fp);
system("cls");
}
//添加
void add_book()
{
FILE *fp;
struct book n;
struct book nn;
char x,z;
int l,r;
fp=fopen("F:\\课程设计\\图书管理系统.txt","ab+");
do
{
system("cls");
do
{
l=0;
printf("\n");
printf("编号 书名 作者 出版社 出版时间 价格 状态 借阅者\n");
fflush(stdin);
scanf("%s %s %s %s %s %s %s %s",n.number,n.tittle,n.writer,n.publisher,n.date,n.price,n.status,n.reader);
system("cls");
rewind(fp);
while(!feof(fp))
{
fread(&nn,sizeof(nn),1,fp);
r=strcmp(n.tittle,nn.tittle);
if(r==0)
{
l=1;
printf(" 该图书已存在,请输入新的图书信息: \n\n");
break;
}
}
}while(l);
fwrite(&n,sizeof(n),1,fp);
printf("\n");
printf("是否继续输入新的图书信息[y/n] \n\n");
do
{
x=getche();
}while(x!='n'&&x!='y');
}while(x=='y');
fclose(fp);
system("cls");
}
//删除图书
void delete_book()
{
FILE *fp,*fp1;
char x,z;
struct book n;
struct book nn;
int l,r;
fp=fopen("F:\\课程设计\\图书管理系统.txt","ab+");
while(1)
{
l=0;
system("cls");
printf("\n");
printf("请输入需要删除的图书名: \n\n");
fflush(stdin);
scanf("%s",&n.tittle);
rewind(fp);
while(1)
{
fread(&nn,sizeof(nn),1,fp);
if(feof(fp))
break;
r=strcmp(n.tittle,nn.tittle);
if(r==0)
{
l=1;
break;
}
}
if(l==0)
{
printf("\n");
printf("对不起,未找到该图书 \n");
}
else
{
printf("\n");
printf("****************************************\n");
printf("编号 书名 作者 出版社 出版时间 价格 状态 借阅者\n");
printf("\n");
printf("%s %s %s %s %s %s %s %s",nn.number,nn.tittle,nn.writer,nn.publisher,nn.date,nn.price,nn.status,nn.reader);
printf("\n");
printf("确认删除图书信息? [是(y)/否(n)]\n\n");
do
{
z=getche();
}while(z!='n'&&z!='y');
if(z=='n')
break;
else
{
fp1=fopen("F:\\课程设计\\图书管理系统new.txt","wb");
rewind(fp);
while(1)
{
fread(&nn,sizeof(nn),1,fp);
if(feof(fp))
break;
r=strcmp(n.tittle,nn.tittle);
if(r!=0)
fwrite(&nn,sizeof(nn),1,fp1);
}
fclose(fp);
fclose(fp1);
fp=fopen("F:\\课程设计\\图书管理系统.txt","wb");
fp1=fopen("F:\\课程设计\\图书管理系统new.txt","rb");
while(1)
{
fread(&nn,sizeof(nn),1,fp1);
if(feof(fp1))
break;
fwrite(&nn,sizeof(nn),1,fp);
}
fclose(fp);
fclose(fp1);
}
}
printf("\n");
printf("是否继续删除图书信息? [是(y)/否(n)] \n");
do
{
x=getche();
}while(x!='n'&&x!='y');
if(x=='n')
break;
}
fclose(fp);
system("cls");
}
//修改图书信息
void modify_book()
{
FILE *fp;
struct book n;
struct book nn;
int l,r;
char x,z;
fp=fopen("F:\\课程设计\\图书管理系统.txt","rb+");
while(1)
{
l=0;
printf("\n");
system("cls");
printf("请输入需要修改的图书名: \n\n");
fflush(stdin);
scanf("%s",&n.tittle);
system("cls");
rewind(fp);
while(1)
{
fread(&nn,sizeof(nn),1,fp);
if(feof(fp))
break;
r=strcmp(n.tittle,nn.tittle);
if(r==0)
{
l=1;
break;
}
}
if(l==0)
{
printf("\n");
printf("对不起,未找到该图书信息 \n\n");
}
else
{
printf("\n");
printf("****************************************\n");
printf("编号 书名 作者 出版社 出版时间 价格 状态 借阅者\n");
printf("\n");
printf("%s %s %s %s %s %s %s %s",nn.number,nn.tittle,nn.writer,nn.publisher,nn.date,nn.price,nn.status,nn.reader);
printf("请依次修改图书信息\n\n\n");
fflush(stdin);
scanf("%s %s %s %s %s %s %s %s",n.number,n.tittle,n.writer,n.publisher,n.date,n.price,n.status,n.reader);
fseek(fp,sizeof(nn),1);
fwrite(&n,sizeof(nn),1,fp);
}
printf("\n");
printf(" 是否继续修改用户信息[y/n]? \n\n");
do
{
x=getch();
}while(x!='n'&&x!='y');
if(x=='n')
break;
}
fclose(fp);
system("cls");
}
//借书
void borrow_book()
{
FILE*fp;
struct book n;
struct book nn;
char x,z;
int l,r;
fp=fopen("F:\\课程设计\\图书管理系统.txt","rb+");
while(1)
{
l=0;
system("cls");
printf("\n");
printf("请输入需要借阅的图书名: \n");
fflush(stdin);
scanf("%s",&n.tittle);
rewind(fp);
while(1)
{
fread(&nn,sizeof(nn),1,fp);
if(feof(fp))
break;
r=strcmp(n.tittle,nn.tittle);
if(r==0)
{
l=1;
break;
}
}
if(l==0)
{
printf("\n");
printf("对不起,未找到该图书。 \n");
}
else
{ printf("\n");
printf("****************************************\n");
printf("编号 书名 作者 出版社 出版时间 价格 状态 借阅者\n");
printf("\n");
printf("%s %s %s %s %s %s %s %s",nn.number,nn.tittle,nn.writer,nn.publisher,nn.date,nn.price,nn.status,nn.reader);
printf("\n");
fflush(stdin);
printf("请输入图书信息并修改在库状态及借阅者信息");
printf("****************************************\n");
printf("编号 书名 作者 出版社 出版时间 价格 状态 借阅者\n");
printf("\n");
scanf("%s %s %s %s %s %s %s %s",n.number,n.tittle,n.writer,n.publisher,n.date,n.price,n.status,n.reader);
fseek(fp,sizeof(nn),1);
fwrite(&n,sizeof(nn),1,fp);
}
printf("\n");
printf(" 是否继续借书? [是(y)/否(n)] \n\n");
do
{
x=getch();
}while(x!='n'&&x!='y');
if(x=='n')
break;
}
fclose(fp);
system("cls");
}
//还书
void return_book()
{
FILE*fp;
struct book n;
struct book nn;
char x,z;
int l,r;
fp=fopen("F:\\课程设计\\图书管理系统.txt","rb+");
while(1)
{
l=0;
system("cls");
printf("\n");
printf("请输入需要借还的图书名: \n");
fflush(stdin);
scanf("%s",&n.tittle);
rewind(fp);
while(1)
{
fread(&nn,sizeof(nn),1,fp);
if(feof(fp))
break;
r=strcmp(n.tittle,nn.tittle);
if(r==0)
{
l=1;
break;
}
}
if(l==0)
{
printf("\n");
printf("对不起,未找到该图书。 \n");
}
else
{
printf("\n");
printf("****************************************\n");
printf("编号 书名 作者 出版社 出版时间 价格 状态 借阅者\n");
printf("\n");
printf("%s %s %s %s %s %s %s %s",nn.number,nn.tittle,nn.writer,nn.publisher,nn.date,nn.price,nn.status,nn.reader);
printf("\n");
fflush(stdin);
printf("请输入图书信息并修改在库状态 \n\n");
printf("****************************************\n");
printf("编号 书名 作者 出版社 出版时间 价格 状态 借阅者\n");
printf("\n");
scanf("%s %s %s %s %s %s %s %s",n.number,n.tittle,n.writer,n.publisher,n.date,n.price,n.status,n.reader);
fseek(fp,-(int)sizeof(nn),1);
fwrite(&n,sizeof(nn),1,fp);
}
printf("\n");
printf("是否继续还书? [是(y)/否(n)] \n");
do
{
x=getche();
}while(x!='n'&&x!='y');
if(x=='n')
break;
}
fclose(fp);
system("cls");
}
//浏览
void scan_book()
{
FILE*fp;
char x,z;
struct book n;
fp=fopen("F:\\课程设计\\图书管理系统.txt","rb");
rewind(fp);
system("cls");
while(1)
{
fread(&n,sizeof(n),1,fp);
if(feof(fp))
break;
else
{
printf("********************************************\n");
printf("编号 书名 作者 出版社 出版时间 价格 状态 借阅者\n");
printf("\n");
printf("%s %s %s %s %s %s %s %s",n.number,n.tittle,n.writer,n.publisher,n.date,n.price,n.status,n.reader);
printf("\n");
}
}
printf("\n");
printf("回到主菜单请按回车");
do
{
x=getche();
}while(x!='\r');
if(x=='\r')
{
fclose(fp);
system("cls");
}
}