本文目錄一覽:
- 1、用C語言設計和實現一個「圖書信息管理系統」,滿足以下要求:
- 2、用c語言寫一個書店管理系統,包括圖書信息 會員信息 銷售信息三個系統
- 3、如何使用C語言編寫圖書管理系統?
- 4、c語言課程設計:圖書管理系統設計的基本思路是什麼?
- 5、C語言程序設計;圖書信息管理系統;圖書信息包括:書號、書名、作者名、出版時間、價格,借閱次數等。
用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);
#includestdio.h#includestdlib.h#includeconio.h#includestring.h#includememory.hint 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(select10||select==20||select==40) select=Menu(); else if(select20 select30) select=SubMenu2(); else if(select40 select50) 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(icount) { 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==0i0) printf(“\n”); }}
int output(BOOK b[]) //輸出圖書信息{ if(count0) { 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(icount) { 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(i1 || iLEN) { 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 dup=0; //重複標誌:1 重複 ,0 沒有重複 if(strcmp(name,original)!=0) for(i=0,j=0;jLEN;) { while(strcmp(b[i].book_name,””)==0) i++;
if(strcmp(name,b[i].book_name) ==0) { dup=1; printf(“\n\t重複!請重新輸入:”); break; } i++; j++; } return dup; }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 dup=0; printf(“請輸入您需要查找圖書信息的書名:”); scanf(“%s”,name); if(strcmp(name,key)!=0) for(i=0,j=0;jLEN;) { while(strcmp(b[i].book_name ,””)==0) i++; if(strcmp(name,b[i].book_name) ==0) { dup=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語言寫一個書店管理系統,包括圖書信息 會員信息 銷售信息三個系統
#include
#include
#include
#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);
}
如何使用C語言編寫圖書管理系統?
圖書管理系統是運行於Windows系統下的應用軟體,主要用於對圖書館中的圖書信息進行增、刪、改、查等操作,並且還可對使用該系統的用戶進行登錄名和密碼的管理等。系統給用戶提供了一個簡單的人機界面,使用戶可以根據提示輸入操作項,調用系統提供的管理功能。
所需功能類似於學生成績管理系統,界面可參考附錄C。用戶分為管理員和一般人員兩大類。
功能需求描述如下。
①用戶登錄:根據用戶輸入的用戶名和密碼判斷是否允許該用戶使用本系統,並且當用戶登錄後根據用戶許可權判斷用戶可以使用哪些功能。學生只有瀏覽等許可權而不能進行實質性改動。
②提供系統主控平台:系統主控平台也應根據用戶許可權不同而有所區別,只列出在用戶許可權範圍內的功能供用戶選擇。系統主控平台包括輸入功能選項、調用相應程序兩大需求。教師和學生對應的系統主控平台是不同的。所能進行的操作也不相同。
③創建圖書信息文件:用戶根據提示輸入圖書編號、圖書分類號、書名、作者姓名、出版社名、出版年月、定價、存庫數量和借閱和上架情況等等信息存儲在系統磁碟的文件中。以便進行管理、查找和備份。
④增加圖書信息:可在原有圖書信息文件的基礎上增加新的圖書信息記錄並繼續保存至磁碟,並且將增加後的文件存儲狀況顯示給用戶。
⑤刪除圖書信息:提示用戶輸入要進行刪除操作的圖書編號,如果在文件中有該信息存在,則將該書號所對應的記錄刪除。並選擇是否繼續進行刪除操作。
⑥修改圖書信息:提示用戶輸入要進行修改操作的書號,如果在文件中有該息存在,則將提示用戶輸入該書號對應的要修改的選項,結果存儲於文件。該部分需求也需要提示用戶選擇是否繼續進行修改操作。
⑦查詢圖書信息:提供按書號或書名等查詢。在該功能中,也需提示用戶是否需要繼續查再繼續查找,則返回主界面。
⑧一般用戶查詢個人的借閱情況並按日期進行排序:。
⑨管理員和一般用戶管理:管理員對用戶的管理也需要進行用戶的創建、增加、刪除、瀏覽。管理員創建的用戶存儲在名為yonghu的磁碟文件中,每當有用戶登錄系統時,會根據該文件中的用戶名和密碼進行核實判斷,用戶才能夠順利登錄。管理員還具有用戶的功能。增加的用戶及密碼、許可權等也被繼續存儲在yonghu文件中。當某些用一用該系統時,還可以進行刪除操作,並且管理員具有修改用戶許可權的功能,一般用戶和管理員對於系統的許可權是不一樣的。
c語言課程設計:圖書管理系統設計的基本思路是什麼?
圖書管理系統主要要求可以錄入書籍,添加書目,查找書本信息,刪除或修改信息,有的還要求顯示是否被借閱等。
一般採用結構體數組,鏈表,文件操作和自定義函數。主要是需要對基礎知識掌握牢固。
先定義結構體,然後對結構體的成員進行定義,選擇數組存儲書本各種信息。錄入信息可以用for和do while循環等來做。
存放信息需要文件操作函數,比如fopen,fwrite等。
刪除和添加可以刪除節點或者增加節點。
查找之類的可以用字元串操作的各種函數實現。
附上參考源代碼
#include stdio.h
#include string.h
#include stdlib.h
#include conio.h
#define books “f:\\books.txt”
#define booksbak “f:\\booksbak.txt”
struct bookinfo
{
char isbn[20];
char title[30];
char author[20];
int count;
};
struct book
{
struct bookinfo onebook;
struct book *next;
};
struct book *searchBook ( struct book *listptr,char isbn[])
{
while(listptr!=(struct book *)0)
if (strcmp(listptr-onebook.isbn,isbn)==0)
return listptr;
else
listptr=listptr-next;
return (struct book *)0;
}
void MainSearchbook(struct book *firstptr)
{
struct book *ptr;
char isbnno[20];
printf(“請輸入ISBN:”);
scanf(“%s”,isbnno);
ptr=searchBook(firstptr,isbnno);
if (ptr!=(struct book *)0)
{
printf(“找到了!!!\n”);
printf(“ISBN:%s\n”,ptr-onebook.isbn);
printf(“Title:%s\n”,ptr-onebook.title);
printf(“Author:%s\n”,ptr-onebook.author);
}
else
printf(“sorry,not found!!!\n”);
}
int addBook(struct book *listptr,struct bookinfo note)
{
while(listptr-next!=0)
listptr=listptr-next;
listptr-next=(struct book *)malloc(sizeof(struct book));
listptr-next-onebook=note;
listptr-next-next=0;
return 0;
}
void MainAdd(struct book *listptr,FILE *fp)
{
int ok;
struct bookinfo note;
printf(“請輸入ISBN:”);
scanf(“%s”,¬e.isbn);
printf(“請輸入Title:”);
scanf(“%s”,¬e.title);
printf(“請輸入Author:”);
scanf(“%s”,¬e.author);
ok=addBook(listptr,note);
if (ok==0)
{
//將加入的圖書寫到文件中保存
fprintf(fp,”\n%s %s %s %d”,note.isbn,note.title,note.author,0);
printf(“添加圖書成功!!!\n”);
}
else
printf(“添加圖書失敗!!!\n”);
}
int removeBook(struct book *listptr,char isbn[])
{
while(listptr-next!=(struct book *)0)
{
if (strcmp(listptr-next-onebook.isbn,isbn)==0)
{
listptr-next=listptr-next-next;
return 0;
}
else
listptr=listptr-next;
}
return -1;
}
void MainRemove(struct book *listptr,FILE *fp)
/************************************************************************/
/* 刪除書籍函數,通過ISBN刪除鏈表節點,同時刪除文件中對應信息 */
/* 刪除文件中一行,用的是笨方法,把需要的信息寫到新文件,刪除舊文件,重命名..*/
/************************************************************************/
{
char isbnno[20];
int ok;
struct bookinfo onebook;
printf(“請輸入ISBN:”);
scanf(“%s”,isbnno);
ok=removeBook(listptr,isbnno);
if (!ok)
{
FILE *fpbak;
if ((fpbak=fopen(booksbak,”a+”))==NULL)
printf(“文件打開失敗!!!\n”);
fseek(fp,0,SEEK_SET); //移到文件開始
while((fscanf(fp,”%s %s %s %d\n”,onebook.isbn,onebook.title,onebook.author,onebook.count))!=EOF)
{
if (strcmp(onebook.isbn,isbnno)!=0)
{
fprintf(fpbak,”%s %s %s %d\n”,onebook.isbn,onebook.title,onebook.author,onebook.count);
}
}
fclose(fp);
fclose(fpbak);
if (remove(books)) //刪除失敗返回非0
{
printf(“刪除文件失敗!!!\n”);
return ;
}
else
if (rename(booksbak,books)) //重命名失敗返回非0值
{
printf(“重命名失敗!!!\n”);
return ;
}
printf(“刪除成功!!!\n”);
}
else
printf(“查無此書!!!”);
}
int choice(void)
{
int c;
printf(“1.查看圖書\n”);
printf(“2.添加圖書\n”);
printf(“3.刪除圖書\n”);
printf(“4.退出程序\n”);
printf(“請選擇序號:”);
return c=getchar();
//return c=getche();
printf(“\n\n”);
}
int addEntry(FILE *fp,struct book *firstptr)
/************************************************************************/
/* 主要用來載入文件中存放的圖書信息 */
/************************************************************************/
{
struct bookinfo onebook;
while((fscanf(fp,”%s %s %s %d\n”,onebook.isbn,onebook.title,onebook.author,onebook.count))!=EOF)
{
while(firstptr-next!=0)
firstptr=firstptr-next;
firstptr-next=(struct book *)malloc(sizeof(struct book));
firstptr-next-onebook=onebook;
firstptr-next-next=0;
}
return 0;
}
int main(int argc,char *argv[])
{
int ch;
struct book first;
strcpy(first.onebook.isbn,”123456″);
strcpy(first.onebook.title,”Programming C”);
strcpy(first.onebook.author,”yhb”);
first.next=0;
struct book *firstptr=first; //鏈表頭指針
FILE *fp;
if ((fp=fopen(books,”a+”))==NULL)
printf(“文件打開失敗!!!”);
addEntry(fp,firstptr);
while(1)
{
system(“CLS”); //清屏
/************************************************************************/
/* 想想這裡為什麼要清空緩衝區? */
/*由於上一次(choice函數)的getchar(),還有一個’\n’留在緩衝區…. */
/*可以把這句話注釋掉看看,沒有這句話會遇到麻煩 */
/*如果不用fflush,可以將上面的getchar()換成getche() */
/*比較getchar(),getch(),getche()…… */
/************************************************************************/
fflush(stdin);
ch=choice()-48;
switch (ch)
{
case 1:
MainSearchbook(firstptr);
break;
case 2:
MainAdd(firstptr,fp);
break;
case 3:
MainRemove(firstptr,fp);
break;
case 4:
printf(“謝謝使用…\n”);
exit(0);
default:
printf(“請輸入正確序號!”);
}
system(“PAUSE”);
}
return 0;
}
C語言程序設計;圖書信息管理系統;圖書信息包括:書號、書名、作者名、出版時間、價格,借閱次數等。
// 圖書管理的實驗報告
#include stdio.h
#include stdlib.h
#include conio.h
struct BOOK
{
int id,usr[10],total,store,days[10];
char name[30],author[20];
}books[100];
void page_title(char *menu_item)
{
printf(“\n- %s -\n\n”,menu_item);
}
void book_add(void)
{
int n;
page_title(“註冊”);
for(n=0;n100;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;
}
int search_book(void)
{
int n,i;
page_title(“查找”);
printf(“請輸入圖書序號:”);
scanf(“%d”,i);
for(n=0;n100;n++)
{
if(books[n].id==i)
{
printf(“書名:%s\n”,books[n].name);
printf(“作者:%s\n”,books[n].author);
printf(“存數:%d\n”,books[n].store);
printf(“總數:%d\n”,books[n].total);
return n;
}
}
printf(“\n輸入有錯或圖書序號不存在.\n”);
return -1;
}
void book_out(void)
{
int n,s,l,d;
page_title(“借書”);
if((n=search_book())!=-1books[n].store0)
{
printf(“請輸入借書證序號:”);
scanf(“%d”,s);
printf(“請輸入可借天數:”);
scanf(“%d”,d);
for(l=0;l10;l++)
{
if(books[n].usr[l]==0)
{
books[n].usr[l]=s;
books[n].days[l]=d;
break;
}
}
books[n].store–;
}
if(n!=-1books[n].store==0) printf(“此書已經全部借出.\n”);
}
/*借書的函數,首先調用找書函數*/
void book_in(void)
{
int n,s,l;
page_title(“還書”);
if((n=search_book())!=-1books[n].storebooks[n].total)
{
printf(“借閱者圖書證列表:\n”);
for(l=0;l10;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;l10;l++)
{
if(books[n].usr[l]==s)
{
books[n].usr[l]=0;
books[n].days[l]=0;
break;
}
}
books[n].store++;
}
if(n!=-1books[n].store==books[n].total)
printf(“全部入藏.\n”);
}
void book_del(void)
{
int n;
page_title(“註銷”);
if((n=search_book())!=-1) books[n].id=0;
printf(“該書已註銷.\n”);
}
void main(void)
{ char n;
page_title(“請選擇”);
printf(“1 註冊\n2 查找\n”);
printf(“3 借書\n4 還書\n5 註銷書”);
printf(“\n0 退出\n”);
while(n=getchar()){
switch(n)
{
case ‘1’ : book_add();break;
case ‘2’ :search_book();break;
case ‘3’ : book_out();break;
case ‘4’ : book_in();break;
case ‘5’ : book_del();break;
case ‘0’ :exit(0);
}printf(“\n\n請選擇\n1 註冊\n2 查找\n3 借書\n4 還書\n5 註銷書\n0 退出\n\n”);
getchar();
}
}
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/185733.html