❶ c語言程序設計 圖書館管理系統
圖書管理系統,我剛做的,符合你的內容
❷ 怎樣用C語言製作圖書館管理系統
這個是自己寫的
注釋很清楚地
有什麼不清楚的問我
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
struct books_list
{
char author[20]; /*作者名*/
char bookname[20]; /*書名*/
char publisher[20]; /*出版單位*/
char pbtime[15]; /*出版時間*/
char loginnum[10]; /*登陸號*/
float price; /*價格*/
char classfy[10]; /*分類號*/
struct books_list * next; /*鏈表的指針域*/
};
struct books_list * Create_Books_Doc(); /*新建鏈表*/
void InsertDoc(struct books_list * head); /*插入*/
void DeleteDoc(struct books_list * head , int num);/*刪除*/
void Print_Book_Doc(struct books_list * head);/*瀏覽*/
void search_book(struct books_list * head); /*查詢*/
void info_change(struct books_list * head);/*修改*/
void save(struct books_list * head);/*保存數據至文件*/
/*新建鏈表頭節點*/
struct books_list * Create_Books_Doc()
{
struct books_list * head;
head=(struct books_list *)malloc(sizeof(struct books_list)); /*分配頭節點空間*/
head->next=NULL; /*頭節點指針域初始化,定為空*/
return head;
}
/*保存數據至文件*/
void save(struct books_list * head)
{
struct books_list *p;
FILE *fp;
p=head;
fp=fopen("data.txt","w+"); /*以寫方式新建並打開 data.txt文件*/
fprintf(fp,"┏━━━┳━━━━━┳━━━━━┳━━━━━┳━━━━━━┳━━━┳━━━━┓\n"); /*向文件輸出表格*/
fprintf(fp,"┃登錄號┃ 書 名 ┃ 作 者┃ 出版單位 ┃ 出版時間 ┃分類號┃ 價格 ┃\n");
fprintf(fp,"┣━━━╋━━━━━╋━━━━━╋━━━━━╋━━━━━━╋━━━╋━━━━┫\n");
/*指針從頭節點開始移動,遍歷至尾結點,依次輸出圖書信息*/
while(p->next!= NULL)
{
p=p->next;
fprintf(fp,"┃%-6.6s┃%-10.10s┃%-10.10s┃%-10.10s┃%-12.12s┃%-6.6s┃%.2f ┃\n",p->loginnum,p->bookname,p->author,p->publisher,p->pbtime,p->classfy,p->price);
}
fprintf(fp,"┗━━━┻━━━━━┻━━━━━┻━━━━━┻━━━━━━┻━━━┻━━━━┛\n");
fclose(fp);
printf(" 已將圖書數據保存到 data.txt 文件\n");
}
/*插入*/
void InsertDoc(struct books_list *head)
{
/*定義結構體指針變數 s指向開辟的新結點首地址 p為中間變數*/
struct books_list *s, *p;
char flag='Y'; /*定義flag,方便用戶選擇重復輸入*/
p=head;
/*遍歷到尾結點,p指向尾結點*/
while(p->next!= NULL)
{
p=p->next;
}
/*開辟新空間,存入數據,添加進鏈表*/
while(flag=='Y'||flag=='y')
{
s=(struct books_list *)malloc(sizeof(struct books_list));
printf("\n 請輸入圖書登陸號:");
fflush(stdin);
scanf("%s",s->loginnum);
printf("\n 請輸入圖書書名:");
fflush(stdin);
scanf("%s",s->bookname);
printf("\n 請輸入圖書作者名:");
fflush(stdin);
scanf("%s",s->author);
printf("\n 請輸入圖書出版社:");
fflush(stdin);
scanf("%s",s->publisher);
printf("\n 請輸入圖書出版時間:");
fflush(stdin);
scanf("%s",s->pbtime);
printf("\n 請輸入圖書分類號:");
fflush(stdin);
scanf("%s",s->classfy);
printf("\n 請輸入圖書價格:");
fflush(stdin);
scanf("%f",&s->price);
printf("\n");
p->next=s; /*將新增加的節點添加進鏈表*/
p=s; /*p指向尾節點,向後移*/
s->next=NULL;
printf(" ━━━━ 添加成功!━━━━");
printf("\n 繼續添加?(Y/N):");
fflush(stdin);
scanf("%c",&flag);
printf("\n");
if(flag=='N'||flag=='n')
{break;}
else if(flag=='Y'||flag=='y')
{continue;}
}
save(head); /*保存數據至文件*/
return;
}
/*查詢操作*/
void search_book(struct books_list *head)
{
struct books_list * p;
char temp[20];
p=head;
if(head==NULL || head->next==NULL) /*判斷資料庫是否為空*/
{
printf(" ━━━━ 圖書庫為空!━━━━\n");
}
else
{
printf("請輸入您要查找的書名: ");
fflush(stdin);
scanf("%s",temp);
/*指針從頭節點開始移動,遍歷至尾結點,查找書目信息*/
while(p->next!= NULL)
{
p=p->next;
if(strcmp(p->bookname,temp)==0)
{
printf("\n圖書已找到!\n");
printf("\n");
printf("登錄號: %s\t\n",p->loginnum);
printf("書名: %s\t\n",p->bookname);
printf("作者名: %s\t\n",p->author);
printf("出版單位: %s\t\n",p->publisher);
printf("出版時間: %s\t\n",p->pbtime);
printf("分類號: %s\t\n",p->classfy);
printf("價格: %.2f\t\n",p->price);
}
if(p->next==NULL)
{
printf("\n查詢完畢!\n");
}
}
}
return;
}
/*瀏覽操作*/
void Print_Book_Doc(struct books_list * head)
{
struct books_list * p;
if(head==NULL || head->next==NULL) /*判斷資料庫是否為空*/
{
printf("\n ━━━━ 沒有圖書記錄! ━━━━\n\n");
return;
}
p=head;
printf("┏━━━┳━━━━━┳━━━━━┳━━━━━┳━━━━━━┳━━━┳━━━━┓\n");
printf("┃登錄號┃ 書 名 ┃ 作 者┃ 出版單位 ┃ 出版時間 ┃分類號┃ 價格 ┃\n");
printf("┣━━━╋━━━━━╋━━━━━╋━━━━━╋━━━━━━╋━━━╋━━━━┫\n");
/*指針從頭節點開始移動,遍歷至尾結點,依次輸出圖書信息*/
while(p->next!= NULL)
{
p=p->next;
printf("┃%-6.6s┃%-10.10s┃%-10.10s┃%-10.10s┃%-12.12s┃%-6.6s┃%.2f ┃\n",p->loginnum,p->bookname,p->author,p->publisher,p->pbtime,p->classfy,p->price); /*循環輸出表格*/
}
printf("┗━━━┻━━━━━┻━━━━━┻━━━━━┻━━━━━━┻━━━┻━━━━┛\n");
printf("\n");
}
/*修改操作*/
void info_change(struct books_list * head)
{
struct books_list * p;
int panan=0; /*此變數用於判斷是否找到書目*/
char temp[20];
p=head;
printf("請輸入要修改的書名:");
scanf("%s",temp);
while(p->next!= NULL)
{
p=p->next;
if(strcmp(p->bookname,temp)==0)
{
printf("\n 請輸入圖書登陸卡號:");
fflush(stdin);
scanf("%s",p->loginnum);
printf("\n 請輸入圖書書名:");
fflush(stdin);
scanf("%s",p->bookname);
printf("\n 請輸入圖書作者名:");
fflush(stdin);
scanf("%s",p->author);
printf("\n 請輸入圖書出版社:");
fflush(stdin);
scanf("%s",p->publisher);
printf("\n 請輸入圖書出版時間:");
fflush(stdin);
scanf("%s",p->pbtime);
printf("\n 請輸入圖書分類號:");
fflush(stdin);
scanf("%s",p->classfy);
printf("\n 請輸入圖書價格:");
fflush(stdin);
scanf("%f",&p->price);
printf("\n");
panan=1;
}
}
if(panan==0)
{
printf("\n ━━━━ 沒有圖書記錄! ━━━━\n\n");
}
return;
}
/*刪除操作*/
void DeleteDoc(struct books_list * head)
{
struct books_list *s,*p; /*s為中間變數,p為遍歷時使用的指針*/
char temp[20];
int panan; /*此變數用於判斷是否找到了書目*/
panan=0;
p=s=head;
printf(" [請輸入您要刪除的書名]:");
scanf("%s",temp);
/*遍歷到尾結點*/
while(p!= NULL)
{
if(strcmp(p->bookname,temp)==0)
{
panan++;
break;
}
p=p->next;
}
if(panan==1)
{
for(;s->next!=p;) /*找到所需刪除卡號結點的上一個結點*/
{
s=s->next;
}
s->next=p->next; /*將後一節點地址賦值給前一節點的指針域*/
free(p);
printf("\n ━━━━ 刪除成功! ━━━━\n");
}
else /*未找到相應書目*/
{
printf(" 您輸入的書目不存在,請確認後輸入!\n");
}
return;
}
int main(void)
{
struct books_list * head;
char choice;
head=NULL;
for(;;) /*實現反復輸入選擇*/
{
printf(" ┏━┓━━━━━━━━━━━━━━━━━━━┏━┓\n");
printf(" ┃ ┃ socat 圖書管理系統 ┃ ┃\n");
printf(" ┃ ┗━━━━━━━━━━━━━━━━━━━┛ ┃\n");
printf(" ┃ ●[1]圖書信息錄入 ┃\n");
printf(" ┃ ┃\n");
printf(" ┃ ●[2]圖書信息瀏覽 ┃\n");
printf(" ┃ ┃\n");
printf(" ┃ ●[3]圖書信息查詢 ┃\n");
printf(" ┃ ┃\n");
printf(" ┃ ●[4]圖書信息修改 ┃\n");
printf(" ┃ ┃\n");
printf(" ┃ ●[5]圖書信息刪除 ┃\n");
printf(" ┃ ┃\n");
printf(" ┃ ●[6]退出系統 ┃\n");
printf(" ┗━━━━━━━━━━━━━━━━━━━━━━━┛\n");
printf(" 請選擇:");
fflush(stdin);
scanf("%c",&choice);
if(choice=='1')
{
if(head==NULL)
{
head=Create_Books_Doc();
}
InsertDoc(head);
}
else if(choice=='2')
{
Print_Book_Doc(head);
}
else if(choice=='3')
{
search_book(head);
}
else if(choice=='4')
{
info_change(head);
}
else if(choice=='5')
{
DeleteDoc(head);
}
else if(choice=='6')
{
printf("\n");
printf(" ━━━━━━━━ 感謝使用圖書管理系統 ━━━━━━━━\n");
break;
}
else
{
printf(" ━━━━ 輸入錯誤,請重新輸入!━━━━");
break;
}
}
return 0;
}
❸ c語言程序設計圖書館管理系統
你好!看你的要求還是蠻多的,都要實現嗎,有個類似的你看看
❹ 求好心高手指導如何用c語言設計一個簡單的圖書館圖書管理系統
功能簡單啊。。就是排序。。添加。。
用一個結構體包含id(就是索引),名字。。然後設計他的添加功能,添加就是把結構體的信息存到文件中。。索引就是排序就完了
❺ C語言課程設計 圖書借閱管理系統
首先要設計一個結構體存放借閱系統中包含的信息名,如書目,類型,數量等,然後設計主函數以制定系統的主界面或菜單界面,最後設計各種函數以實現你所設想的各種功能(函數名需要在編譯預處理階段設定,否則無法執行)。具體的例子我給不了,太長了,最少800多行呢!
❻ 用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語言編程(圖書館管理系統)
針對你 de 題目C語言編程(圖書館管理系統),
可以為你提供 1 份適用於初學者 de 代碼,
有進 1 步需求,可以我們聯系,
給我留 1 個你 de 問題和Email,
有時間可以幫你,肯定救急,
使用網路_Hi給我留言,
此回復針對所有來訪者和需求者有效,
ES:\\
❽ c語言課程設計:圖書館系統
#include<stdio.h>
#include<string.h>
#include<conio.h>
#include<stdlib.h>
#define N sizeof(struct book)
#define PT "%-5d %10s %6s %6s %8s %3d \n",p->num,p->name,p->where,p->author,p->pub,p->count
struct book /*圖書信息*/
{
int num; /*書號*/
char name[10]; /*書名*/
char where[10]; /*所在書庫*/
char author[15]; /*作者*/
char pub[20]; /*出版社*/
int count; /*數量*/
struct book *next;
};
/*輸出模塊*/
void print(struct book *p0)
{
struct book *p;
p=p0->next;
printf("\n\n\t\t^^^^^^^^^^^^^^圖書信息表^^^^^^^^^^^^^^");
printf("\n\n圖書編號---圖書名稱---所在書庫----作者----出版社---數量\n");
while(p!=NULL)
{
printf(PT);
p=p->next;
}
getch();
}
/*輸入模塊*/
struct book *creat()
{
struct book *head,*p1,*p2;
int i=0;
head=p2=(struct book *)malloc(N);
head->next=NULL;
printf("\n\n\t\t錄入圖書信息");
printf("\n\t---------------------------------------");
while(1)
{ p1=(struct book *)malloc(N);
printf("\n 請輸入圖書編號(書號為0結束): ");
scanf("%d",&p1->num);
if(p1->num!=0)
{
printf("\n\n書名 所在書庫 作者 出版社 圖書數量\n");
scanf("%s%s%s%s%d",p1->name,p1->where,p1->author,p1->pub,&p1->count);
p2->next=p1;
p2=p1;
i++;
}
else
break;
}
p2->next=NULL;
free(p1);
printf("\n\t\t----------------------------------------");
printf("\n\t\t %d 種書錄入完畢",i);
getch();
return head;
}
/*查找模塊*/
void find(struct book *p0)
{
char name[10];
int flag=1;
struct book *p;
p=p0->next;
printf("請輸入要查找的書名:\n");
scanf("%s",name);
for(p=p0;p;p=p->next)
if(strcmp(p->name,name)==0)
{
printf("\n\n圖書編號---圖書名稱---所在書庫----作者----出版社---數量\n");
printf(PT);
flag=0;
break;
}
if(flag) printf("\n 暫無此圖書信息\n");
getch();
}
/*刪除模塊*/
void del(struct book *p0)
{
char name[10];
int flag=1;
struct book *p;
p=p0;
printf("請輸入要刪除的書名:\n");
scanf("%s",name);
while(p!=NULL)
{
if(strcmp(p->name,name)==0)
{
p0->next=p->next; /*後續節點連接到前驅節點之後*/
free(p);
printf("\t該書資料已刪除.");
flag=0;
break;
}
p0=p;
p=p->next;
}
if(flag) printf("\n\t無此圖書信息。");
getch();
}
/*增加模塊*/
void insert(struct book *p0)
{
struct book *p;
p=(struct book *)malloc(N);
while(1)
{
printf("\n 請輸入要增加的圖書編號(書號為0 退出): ");
scanf("%d",&p->num);
if(p->num!=0)
{
if(p0->next!=NULL&&p0->next->num==p->num) /*找到重號*/
{
p=p->next;
free(p);
printf("\t該書已存在");
}
else
{printf("\n\n書名 所在書庫 作者 出版社 圖書數量\n");
scanf("%s%s%s%s%d",p->name,p->where,p->author,p->pub,&p->count);
p->next=p0->next;
p0->next=p;
printf("\t已成功插入.");
}
}
else
break;
}
getch();
}
/*修改模塊*/
void modify(struct book *p0)
{
char name[10];
int flag=1;
int choice;
struct book *p;
p=p0->next;
printf("請輸入要修改的書名:\n");
scanf("%s",name);
while(p!=NULL&&flag==1)
{
if(strcmp(p->name,name)==0)
{
printf("\n\t請選擇要修改的項:");
printf("\n\t 1.修改圖書編號\n");
printf("\n\t 2.修改圖書所在書庫\n");
printf("\n\t 3.修改圖書作者\n");
printf("\n\t 4.修改圖書出版社\n");
printf("\n\t 5.修改圖書庫存量\n");
scanf("%d",&choice);
switch(choice)
{
case 1: { printf("\n 請輸入新的圖書編號:");
scanf("%d",p->num); break;
}
case 2: { printf("\n 請輸入新的圖書書庫:");
scanf("%s",p->where); break;
}
case 3: { printf("\n 請輸入新的圖書作者:");
scanf("%s",p->author); break;
}
case 4: {printf("\n 請輸入新的圖書出版社:");
scanf("%s",p->pub); break;
}
case 5: {printf("\n 請輸入新的圖書庫存量:");
scanf("%d",p->count); break;
}
}
printf("\n\t該項已成功修改。\n\t 新的圖書信息:");
printf("\n\n圖書編號---圖書名稱---所在書庫----作者----出版社---數量\n");
printf(PT);
flag=0;
}
p0=p;
p=p0->next;
}
if(flag) printf("\n\t暫無此圖書信息。");
getch();
}
/*讀文件*/
struct book *read_file()
{
int i=0;
struct book *p,*p1,*head=NULL;
FILE *fp;
if((fp=fopen("library.txt","rb"))==NULL)
{printf("\n\n\n\n\n \t********庫文件不存在,請創建!**********");
getch();
return NULL;
}
head=(struct book *)malloc(N);
p1=head;
head->next=NULL;
printf("\n 已有圖書信息:");
printf("\n\n圖書編號---圖書名稱---所在書庫----作者----出版社---數量\n");
while(!feof(fp))
{
p=(struct book *)malloc(N); /*開辟空間以存放的取得信息*/
while(fscanf(fp,"%d%s%s%s%s%d",&p->num,p->name,p->where,p->author,p->pub,&p->count)!=EOF)
{
printf(PT);
i++;
}
p1->next=p;
p1=p;
}
p1->next=NULL;
fclose(fp);
printf("\n 共種%d 圖書信息",i);
printf("\n\n\n 文件中的信息以正確讀出。按任意鍵返回。");
getch();
return (head);
}
/*保存文件*/
void save(struct book *head)
{
FILE *fp;
struct book *p;
fp=fopen("library.txt","wb"); /*以只寫方式打開二進制文件*/
if(fp==NULL) /*打開文件失敗*/
{
printf("\n=====>打開文件失敗!\n");
getch();
return ;
}
else
for(p=head->next;p!=NULL;p=p->next)
fprintf(fp,"%d %s %s %s %s %d\n",p->num,p->name,p->where,p->author,p->pub,p->count);
fclose(fp);
printf("\n\t保存文件成功!\n");
}
void main()
{
struct book *head=NULL;
int choice=1;
head=read_file();
if(head==NULL)
{
printf("\n\t\t**********");
getch();
head=creat();
}
do
{
system("cls");
printf("\t\t----------Welcome---------\n");
printf("\n\n\t歡迎您,圖書管理員.\n");
printf("\n\n\n\n\n");
printf("\n\t 請選擇:");
printf("\n\t 1.查詢圖書信息\n");
printf("\n\t 2.修改圖書信息\n");
printf("\n\t 3.增加圖書信息\n");
printf("\n\t 4.刪除圖書信息\n");
printf("\n\t 5.顯示所有圖書信息\n");
printf("\n\t 0.退出系統\n");
scanf("%d",&choice);
switch(choice)
{
case 1: find(head); break;
case 2: modify(head); break;
case 3: insert(head); break;
case 4: del(head); break;
case 5: print(head); break;
case 0: system("cls");
printf("\n\n\n\n\n\t^^^^^^^^^^謝謝使用,再見^^^^^^^^^^!\n\n");
break;
}
}while(choice!=0);
save(head);
}
❾ 圖書館圖書管理系統(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
#include
#include
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;
}