A. 用c語言做圖書館圖書信息管理軟體設計
呵呵,誰會為了那20個沒用的玩意兒浪費自己的時間為你寫程序
B. 用C語言設計和實現一個「圖書信息管理系統」,滿足以下要求:
const int MAXLEN=100;int count; //記錄書籍數量char fName[20]="backup.dat"; //磁碟文件:書籍信息文件名 int LEN; //全局變數,通訊錄中當前聯系人總數int n;char *key;
typedef struct book //聯系人數據結構
{ char no[20]; //序號 char book_name[20]; // 書名 char writer[30]; //作者名 char booknum[20]; //書籍分類 char press[20]; //出版單位 char price[10]; //書籍價格 }BOOK;BOOK b[MAXLEN];
typedef struct index{ int len; //數組長度 BOOK b[MAXLEN]; //指針數組}Index;
int Select();int Menu(void);int SubMenu2(void);int SubMenu4(void);int addbook(BOOK b[]);int output(BOOK b[]);int deletebook(BOOK b[]);void printno(BOOK b[]);int modifyIndo(BOOK b[]);int Save(BOOK b[]); int loaddata(BOOK b[]);int Copy(void);void New(BOOK b[]);int Load(BOOK b[]);void List(BOOK b[]);//void findbook(char *name,BOOK b[],char *key);
#include<stdio.h>#include<stdlib.h>#include<conio.h>#include<string.h>#include<memory.h>int main(int argc, char* argv[]){ int select=0;
/*int select;用戶所選的菜單項代碼: 主菜單:1 查找圖書信息、2 更新圖書信息 、3 備份圖書信息、0 退出程序 更新圖書信息子菜單:21 新增圖書信息、 22 編輯圖書信息、 23 刪除圖書信息、 20 返回主菜單 查看圖書信息子菜單:11 圖書信息庫 、12書名查找、13 作者名查找、14 序號查找 */
BOOK b[MAXLEN]; memset(b,0,sizeof(b)); //將b初始化為空,memory.h loaddata(b); //從圖書庫文件中讀取信息 //循環顯示菜單,供用戶選擇 do{
if(select<10||select==20||select==40) select=Menu(); else if(select>20 && select<30) select=SubMenu2(); else if(select>40 && select<50) select=SubMenu4(); switch(select) { case 11:// 圖書信息庫 break; case 12://書名查找 break;
case 13://作者名查找 break; case 14://類別查找 break;
case 21://新增圖書信息、 break; case 22://編輯圖書信息、 break; case 23://刪除圖書信息、 break; case 20://返回主菜單 break; case 3: system("cls"); Save(b); Copy(); break; case 0://退出程序 break; } }while(select!=0); return 0;}
int SubMenu4(void){ char menu; do{ system("cls");//清屏,需要使用到stdlib.h puts("\n\t======更新圖書信息======\n"); puts("\t 1.新增圖書信息"); puts("\t 2.刪除圖書信息"); puts("\t 3.編輯圖書信息"); puts("\t 0.返回主菜單"); puts("\n\t=================="); printf("\t請選擇:");//提示選擇 menu=getche(); switch(menu) { case '0': puts("\n\n\t返回主菜單!"); break; case '1': addbook(b); break; case '2': deletebook(b); break; case '3': modifyIndo(b); break; default: puts("\n\n\t選擇錯誤!"); menu='9'; } }while(menu=='9'); return 40+menu-'0';}
void New(BOOK b[]){ int t=0; //找到BOOK中第一個空的位置,存放新輸入 if(LEN>=MAXLEN) { printf("\n\n\t圖書庫已滿!"); return ; }
while(strcmp(b[t].book_name,"")!=0) //找到b中第一個空的位置t t++; addbook(b); //新增,輸入 LEN++; //增1}
int modifyIndo(BOOK b[])//編輯圖書信息{ char no[20]; int i; printno(b);again: printf("\n請輸入你想要編輯的書籍編號:"); fflush(stdin); gets(no); for(i=0;i<=count;i++) { if(strcmp(no,b[i].no)==0) break; } if(i>count) { printf("對不起,你輸入的編號不存在,是否繼續?Y/N:"); if((getchar()=='Y')||(getchar()=='y')) goto again; else return 0; } printf("\n正在修改《%s》的信息……\n",b[i].book_name); printf("請輸入圖書的名字:"); gets(b[i].book_name); printf("請輸入圖書的作者名:"); gets(b[i].writer); printf("請輸入書籍類別:"); gets(b[i].booknum); printf("請輸入書籍的出版單位:"); gets(b[i].press); printf("請輸入書籍的價格:"); gets(b[i].price); printf("\n圖書信息編輯成功!\n");
}
void printno(BOOK b[]){ int i; printf("\n當前庫存中的書籍目錄:\n"); for( i=0;i<=count;i++) { printf("%s %s ",b[i].no,b[i].book_name); if(i%3==0&&i>0) printf("\n"); }}
int output(BOOK b[]) //輸出圖書信息{ if(count<0) { printf("對不起,當前圖書數量為0\n"); return 0; } for(int i=0;i<=count;i++) { printf("\n*************************書籍信息*****************************\n"); printf("序號:%s\n",b[i].no); printf("書名:%s\n",b[i].book_name); printf("作者名:%s\n",b[i].writer); printf("書籍類別:%s\n",b[i].booknum); printf("出版單位:%s\n",b[i].press); printf("書籍價格:%s\n",b[i].price); } return 1; }
int deletebook(BOOK b[]) { char no[20]; int i; printno(b);loop: printf("\n請輸入你要刪除的書籍編號:"); fflush(stdin); gets(no); for(i=0;i<=count;i++) { if(strcmp(no,b[i].no)==0) break; } if(i>count) { printf("對不起,你輸入的編號不存在,是否繼續?Y/N:"); if((getchar()=='Y')||(getchar()=='y')) goto loop; else return 0; } printf("您確定要刪除《%s》嗎?Y/N:",b[i].book_name); if((getchar()=='Y')||(getchar()=='y'))
{ if(i==count) { count--; } else { for(;i<=count;i++) { b[i]=b[i+1]; count--; }
}
} else return 0; }
int loaddata(BOOK b[]){ int i=0; //i:b數組的下標 FILE *fp=fopen(fName,"r"); if(!fp) { printf("\n\t對不起,路徑或者文件錯誤,無法讀入!請重新增加!"); getch(); return 0; } fscanf(fp,"書籍編號\t書名\t作者\t類別\t出版單位\t價格"); while((!feof(fp))) { fscanf(fp,"\n%s\t%s\t%s\t%s\t%s\t%s",&b[i].no,&b[i].book_name,&b[i].writer,&b[i].booknum,&b[i].press,&b[i].price); i++; } count=i; fclose(fp); printf("載入成功!!"); return 1;}
int Select(){ int i=0; int c; //c:scanf輸入的返回值,輸入成功返回1;否則返回0 printf("\n\t請按需要選擇圖書信息:"); c=scanf("%d",&i); while(i<1 || i>LEN) { printf("\n\t輸入錯誤!請按序號選擇圖書信息:"); if(c==0) fflush(stdin); c=scanf("%d",&i); } return i-1;} int addbook(BOOK b[]) //增加圖書信息{ int i=0; char c; printf("\n*******************************新增圖書信息****************************\n"); for(;;i++) { if(i>=MAXLEN) { printf("\n對不起,庫存已滿!不能繼續添加。"); } printf("請輸入圖書的序號:"); gets(b[i].no); printf("請輸入圖書的名字:"); gets(b[i].book_name); printf("請輸入圖書的作者名:"); gets(b[i].writer); printf("請輸入書籍類別:"); gets(b[i].booknum); printf("請輸入書籍的出版單位:"); gets(b[i].press); printf("請輸入書籍的價格:"); gets(b[i].price); printf("圖書增加成功!\n"); printf("請問您要繼續添加書籍信息嗎?(Y/N): "); c=getchar(); if(c=='Y'||c=='y') { getchar(); printf("\n"); continue; } else break; } count=i; return i;
}//查重。int Duplicate(char *name,BOOK b[],char *original){ int i,j; int p=0; //重復標志:1 重復 ,0 沒有重復 if(strcmp(name,original)!=0) for(i=0,j=0;j<LEN;) { while(strcmp(b[i].book_name,"")==0) i++;
if(strcmp(name,b[i].book_name) ==0) { p=1; printf("\n\t重復!請重新輸入:"); break; } i++; j++; } return p; }int SubMenu2(void){ char menu,*name; do{ system("cls"); //清屏,需要使用到stdlib.h puts("\n\t======查找圖書信息======\n"); puts("\t 1.圖書信息庫"); puts("\t 2.書名查找"); puts("\t 3.作者名查找"); puts("\t 4.序號查找"); puts("\t 0.返回主菜單"); puts("\n\t=================="); printf("\t請選擇:"); //提示選擇 menu=getche(); switch(menu) { case '0': puts("\n\n\t返回主菜單!"); break; case '1': output(b); getch(); break; case '2': //findbook(name,b,key); getch(); break; case '3': case '4': printno(b); break; default: puts("\n\n\t選擇錯誤!"); menu='9'; } }while(menu=='9'); return 20+menu-'0';}
int Menu(void){ char menu; do{ system("cls"); puts("\n\t======主菜單======\n"); puts("\t 1.查找圖書信息"); puts("\t 2.更新圖書信息"); puts("\t 3.備份圖書信息"); puts("\t 0.退出程序"); puts("\n\t=================="); printf("\t請選擇:"); //提示選擇 menu=getche(); switch(menu) //將用戶輸入的選項menu轉換成系統定義的菜單代碼 {
case '0': puts("\n\n\t退出程序!"); menu=menu-'0'; break;
case '2': menu=SubMenu4();
break; case '3': menu=menu-'0';
break; case '1': menu=SubMenu2();
break; default: puts("\n\n\t選擇錯誤!"); menu='9'; //輸入了無效的菜單代碼,需要重新輸入 } }while(menu=='9'); return menu;}
int Load(BOOK b[]){ FILE *fin; int i=0; fin=fopen(fName,"rb"); if(!fin) { printf("\n\t書籍信息不存在,請先新增加圖書信息!\n\n按任意鍵繼續……"); getch(); return 0; } while(1) { fread(&b[i],sizeof(BOOK),1,fin); if(feof(fin)) break; i++; } fclose(fin); LEN=i; return i;
}
int Save(BOOK b[])//存入文件 {
int i; //i:b數組的下標 FILE *fp=fopen(fName,"w"); if(!fp) { printf("\n\t不能正確保存書籍信息!按任意鍵繼續……"); getch(); return 0; } fprintf(fp,"書籍編號\t書名\t作者\t類別\t出版單位\t價格"); for( i = 0; i <=count; i++) { fprintf(fp,"\n%s\t%s\t%s\t%s\t%s\t%s",b[i].no,b[i].book_name,b[i].writer,b[i].booknum,b[i].press,b[i].price); } fclose(fp); printf("保存成功!!"); return 1;}
int Copy(void) //備份圖書信息,復制圖書信息文件{ FILE *fout,*fin; BOOK *p=(BOOK *)malloc(sizeof(BOOK)); //存放從圖書信息庫讀入的臨時數據 char name[20];
fin=fopen(fName,"rb"); if(!fin) { printf("\n\t沒有此圖書信息!"); return 0; }
do{ printf("\n\t請輸入備份文件名:"); scanf("%s",name); strcat(name,".bak"); fout=fopen(name,"wb"); if(!fout) printf("\t無效文件名或路徑!\n"); }while(!fout);
while(1) { fread(p,sizeof(BOOK),1,fin); if(feof(fin)) break; fwrite(p,sizeof(BOOK),1,fout); }
printf("\n\t備份成功!"); free(p); return 1;}
void findbook(char *name,BOOK b[],char *key){
int i,j; //i:數組下標 j:除姓名為空串以外的實際人數 int p=0; printf("請輸入您需要查找圖書信息的書名:"); scanf("%s",name); if(strcmp(name,key)!=0) for(i=0,j=0;j<LEN;) { while(strcmp(b[i].book_name ,"")==0) i++; if(strcmp(name,b[i].book_name) ==0) { p=1; printf("\n%s\t%s\t%s\t%s\t%s\t%s",&b[i].no,&b[i].book_name,&b[i].writer,&b[i].booknum,&b[i].press,&b[i].price); } }}
C. 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;
}
D. 用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();
}
}
E. 圖書信息管理系統設計c語言(急求!!!)
#include<stdio.h>
#include<ctype.h>
#include<stdlib.h>
#include<string.h>
typedefstructrecord{
chartitle[64];
charauthor[24];
charisbn[24];
doubleprice;
intcopies;
structrecord*next;
}Node,*LinkList,*pNode;
LinkListInitList(){
LinkListhead=(pNode)malloc(sizeof(Node));
head->title[0]='