當前位置:首頁 » 編程語言 » 圖書管理系統c語言
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

圖書管理系統c語言

發布時間: 2022-02-10 17:45:45

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");
}
}