數據結構課程設計圖書館管理系統
Ⅰ 數據結構課程設計(基於C) 圖書管理系統
頭文件:
============
#ifndef _DATA_STRUCT_H_
#define _DATA_STRUCT_H_
/*圖書結構*/
struct Book
{
unsigned long BookID;/*圖書編號*/
char BookName[512];/*書名*/
char Writer[512];/*作者*/
int CurrentNumber;/*現存量*/
Book *pNext;/*下一個圖書信息*/
};
/*圖書索引結構*/
struct Index
{
unsigned long BookID;/*圖書編號*/
Index *pNext;/*下一個索引指針*/
};
/*借閱信息結構*/
struct Borrow
{
unsigned long BookID;/*借閱圖書編號*/
char BookName[512];/*書名*/
unsigned long StuID;/*圖書證號*/
char ReturnTime[512];/*歸還日期*/
Borrow *pNext;/*下一個借閱信息*/
};
#endif/*_DATA_STRUCT_H_*/
實現文件:
===============
// BookManage.cpp : 定義控制台應用程序的入口點。
//
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "DataStruct.h"
/*
數據結構課程設計(基於C) 圖書管理系統
懸賞分:100 - 離問題結束還有 14 天 23 小時
【問題描述】
圖書管理基本業務活動包括,對一本書的采編入庫、清楚庫存、借閱和歸還等等。試設計一個圖書管理系統,將上述業務活動藉助於計算機系統完成。
【基本要求】
(1) 每種書的登記至少包括書號書名作者現存量總庫存量5項
(2)對書號建立索引表(線性表)以提高查找效率
(3) 系統要實現的操作及其功能定義如下:
1 采編入庫:新購入一種書,經分類和確定數好之後登記到圖書館賬目中去。如果這種書在賬戶中已有,則只將總庫存量增加。
2借閱:如果一本書的現存量大於零,則借出一本,登出借閱者的圖書證號和歸還日期
3歸還:注銷對借閱者的登記,改變該書的現存量
*/
/*獲取輸入字元串*/
void GetInput(char *pInOutStr,int StrLen,bool OnlyGetNumber = false);
/*顯示主菜單 並返回選擇*/
int ShowMainMenu();
/*圖書入庫操作,傳入參數為圖書列表頭指針的指針和索引信息的頭指針的指針,因為在此函數內部可能會改變頭指針的值*/
void PutBookInLib(Book **pHead,Index **pIndex);
/*查詢圖書館庫存,查詢不改變數據,故傳入指針即可*/
void QueryBookLib(Book *pHead);
/*借閱圖書*/
void BorrowBook(Borrow **pBorrow,Book *pHead);
/*查詢借閱*/
void QueryBorrow(Borrow *pBorrow);
/*歸還圖書*/
void ReturnBook(Borrow **pBorrow,Book *pHead);
/*釋放圖書鏈表及索引鏈表及借閱信息鏈表*/
void DeleteBookList(Book **pHead);
void DeleteIndexList(Index **pIndex);
void DeleteBorrowList(Borrow **pBorrow);
int main()
{
/*圖書列表頭指針*/
Book *pBookHead = NULL;
/*圖書索引頭指針*/
Index *pIndexHead = NULL;
/*借閱信息頭指針*/
Borrow *pBorrowHead = NULL;
/*用來保存當前用戶的輸入*/
int ChoosedNum = -1;
while ( true )
{
ChoosedNum = ShowMainMenu();
switch(ChoosedNum)
{
case 0 :/*退出*/
{
return 0;
break;
}
case 1:/*圖書入庫*/
{
PutBookInLib(&pBookHead,&pIndexHead);
break;
}
case 2:/*查詢庫存*/
{
QueryBookLib(pBookHead);
printf("按回車鍵繼續...");
fflush(stdin);
getchar();
system("cls");
break;
}
case 3:/*借閱圖書*/
{
QueryBookLib(pBookHead);
BorrowBook(&pBorrowHead,pBookHead);
break;
}
case 4:/*查詢借閱*/
{
QueryBorrow(pBorrowHead);
printf("按回車鍵繼續...");
fflush(stdin);
getchar();
system("cls");
break;
}
case 5:/*歸還圖書*/
{
QueryBorrow(pBorrowHead);
ReturnBook(&pBorrowHead,pBookHead);
break;
}
}
}
DeleteBookList(&pBookHead);
DeleteIndexList(&pIndexHead);
DeleteBorrowList(&pBorrowHead);
fflush(stdin);
getchar();
return 0;
}
/*獲取輸入字元串*/
void GetInput(char *pInOutStr,int StrLen,bool OnlyGetNumber)
{
memset(pInOutStr,0x0,StrLen);
fflush(stdin);
int Count = 0;
while ( true )
{
char TmpC = 0;
fread(&TmpC,1,1,stdin);
if ( 10 == TmpC )
{
break;
}
if ( OnlyGetNumber && TmpC >= '0' && TmpC <= '9' )
{
pInOutStr[Count] = TmpC;
Count++;
}
else
{
pInOutStr[Count] = TmpC;
Count++;
}
}
}
/*顯示主菜單 並返回選擇*/
int ShowMainMenu()
{
char InPutStr[1024];
NO_INPUT:
printf("\n\n\n");
printf("******************************************************************\n");
printf("* 圖書管理系統 *\n");
printf("******************************************************************\n");
printf("\n");
printf("請選擇:\n");
printf("\t1.圖書入庫\n");
printf("\t2.查詢庫存\n");
printf("\t3.借閱圖書\n");
printf("\t4.查詢借閱\n");
printf("\t5.歸還圖書\n");
printf("\t0.退出\n");
printf("\n");
printf("\t輸入 : ");
GetInput(InPutStr,1024,true);
if ( strlen(InPutStr) < 1 )
{
system("cls");
goto NO_INPUT;
}
return atoi(InPutStr);
}
/*圖書入庫操作*/
void PutBookInLib(Book **pHead,Index **pIndex)
{
Book *pWork = *pHead;
unsigned long BookID = 1;
char InPutStr[1024];
/*先計算處當前入庫圖書的ID號*/
if ( NULL == pWork )
{
BookID = 1;
}
else
{
while ( pWork->pNext != NULL )
{
pWork = pWork->pNext;
}
BookID = pWork->BookID + 1;
}
Book *pTmpNewBook = (Book *)(malloc(sizeof(Book)));
memset(pTmpNewBook,0x0,sizeof(Book));
Index *pTmpIndex = (Index *)(malloc(sizeof(Index)));
memset(pTmpIndex,0x0,sizeof(Index));
pTmpNewBook->BookID = BookID;
pTmpIndex->BookID = BookID;
system("cls");
printf("輸入圖書名稱 : ");
GetInput(InPutStr,1024);
strcpy(pTmpNewBook->BookName,InPutStr);
system("cls");
printf("<<%s>>\n",pTmpNewBook->BookName);
printf("圖書作者 : ");
GetInput(InPutStr,1024);
strcpy(pTmpNewBook->Writer,InPutStr);
system("cls");
printf("<<%s>>\n",pTmpNewBook->BookName);
printf("作者:%s\n",pTmpNewBook->Writer);
printf("入庫數量 : ");
GetInput(InPutStr,1024,true);
pTmpNewBook->CurrentNumber = atoi(InPutStr);
if ( pTmpNewBook->CurrentNumber < 1 )
{
system("cls");
printf("入庫數量錯誤!(按回車鍵繼續...)");
fflush(stdin);
getchar();
system("cls");
return;
}
if ( NULL == *pHead )
{
*pHead = pTmpNewBook;
*pIndex = pTmpIndex;
}
else
{
Book *pWork = *pHead;
while ( pWork != NULL )
{
if ( strcmp(pWork->BookName,pTmpNewBook->BookName) == 0 && strcmp(pWork->Writer,pTmpNewBook->Writer) == 0 )
{
pWork->CurrentNumber += pTmpNewBook->CurrentNumber;
return;
}
pWork = pWork->pNext;
}
pWork = *pHead;
while ( pWork->pNext != NULL )
{
pWork = pWork->pNext;
}
pWork->pNext = pTmpNewBook;
Index *pWork2 = *pIndex;
while ( pWork2->pNext != NULL )
{
pWork2 = pWork2->pNext;
}
pWork2->pNext = pTmpIndex;
}
system("cls");
printf("圖書:<<%s>>\n作者:%s\n入庫數:%d\n\n入庫操作成功!(按回車鍵繼續...)",pTmpNewBook->BookName,pTmpNewBook->Writer,pTmpNewBook->CurrentNumber);
fflush(stdin);
getchar();
system("cls");
}
/*釋放圖書鏈表及索引鏈表*/
void DeleteBookList(Book **pHead)
{
Book *pWork = *pHead;
Book *pNext = pWork;
while ( NULL != pWork )
{
pNext = pWork->pNext;
free(pWork);
pWork = pNext;
}
}
void DeleteIndexList(Index **pIndex)
{
Index *pWork = *pIndex;
Index *pNext = pWork;
while ( NULL != pWork )
{
pNext = pWork->pNext;
free(pWork);
pWork = pNext;
}
}
void DeleteBorrowList(Borrow **pBorrow)
{
Borrow *pWork = *pBorrow;
Borrow *pNext = pWork;
while ( NULL != pWork )
{
pNext = pWork->pNext;
free(pWork);
pWork = pNext;
}
}
/*查詢圖書館庫存,查詢不改變數據,故傳入指針即可*/
void QueryBookLib(Book *pHead)
{
Book *pWork = pHead;
int TotalCount = 0;
while ( NULL != pWork )
{
TotalCount++;
pWork = pWork->pNext;
}
system("cls");
printf("當前庫存共%d種圖書,列表如下:\n=====================================================\n",TotalCount);
pWork = pHead;
while ( NULL != pWork )
{
printf("編號:[%d] 書名:<<%s>> 作者:%s 當前庫存:%d\n",pWork->BookID,pWork->BookName,pWork->Writer,pWork->CurrentNumber);
pWork = pWork->pNext;
}
printf("=====================================================\n",TotalCount);
}
/*借閱圖書*/
void BorrowBook(Borrow **pBorrow,Book *pHead)
{
char InPutStr[1024];
bool HadTheBook = false;
Borrow *pTmpBorrow = (Borrow *)(malloc(sizeof(Borrow)));
memset(pTmpBorrow,0x0,sizeof(Borrow));
printf("請輸入你想借書的編號 : ");
GetInput(InPutStr,1024,true);
pTmpBorrow->BookID = atoi(InPutStr);
Book *pWorkBook = pHead;
while ( pWorkBook != NULL )
{
if ( pWorkBook->BookID == pTmpBorrow->BookID )
{
HadTheBook = true;
break;
}
pWorkBook = pWorkBook->pNext;
}
if ( HadTheBook )
{
if ( pWorkBook->CurrentNumber < 1 )
{
system("cls");
printf("圖書<<%s>>當前無庫存,無法借閱!\n(按回車鍵繼續...)",pWorkBook->BookName);
fflush(stdin);
getchar();
system("cls");
free(pTmpBorrow);
return;
}
}
else
{
system("cls");
printf("圖書編號%d不存在!\n(按回車鍵繼續...)",pTmpBorrow->BookID);
fflush(stdin);
getchar();
system("cls");
free(pTmpBorrow);
return;
}
strcpy(pTmpBorrow->BookName,pWorkBook->BookName);
printf("請輸入借書證號 : ");
GetInput(InPutStr,1024,true);
pTmpBorrow->StuID = atoi(InPutStr);
if ( 0 == pTmpBorrow->StuID )
{
system("cls");
printf("借書證號不存在(借書證號輸入整數)!\n(按回車鍵繼續...)");
fflush(stdin);
getchar();
system("cls");
free(pTmpBorrow);
return;
}
time_t ltime;
struct tm *today;
time(<ime);
ltime += 60 * 60 * 24 * 30;
today = localtime(<ime);
sprintf(pTmpBorrow->ReturnTime,"%d年%d月%d日", today->tm_year+1900,
today->tm_mon+1,
today->tm_mday);
if ( *pBorrow == NULL )
{
*pBorrow = pTmpBorrow;
}
else
{
Borrow *pWork = *pBorrow;
while ( NULL != pWork->pNext )
{
pWork = pWork->pNext;
}
pWork->pNext = pTmpBorrow;
}
pWorkBook->CurrentNumber--;
system("cls");
printf("借書證號:%d\n借閱圖書:<<%s>>\n\n操作成功!(按回車鍵繼續...)",pTmpBorrow->StuID,pTmpBorrow->BookName);
fflush(stdin);
getchar();
system("cls");
}
/*查詢借閱*/
void QueryBorrow(Borrow *pBorrow)
{
Borrow *pWork = pBorrow;
int TotalCount = 0;
while ( NULL != pWork )
{
TotalCount++;
pWork = pWork->pNext;
}
system("cls");
printf("當前借閱信息共%d條,列表如下:\n=====================================================\n",TotalCount);
pWork = pBorrow;
while ( NULL != pWork )
{
printf("借數證號:[%d] 借書名:<<%s>> 圖書編號:%d 歸還日期:%s\n",pWork->StuID,pWork->BookName,pWork->BookID,pWork->ReturnTime);
pWork = pWork->pNext;
}
printf("=====================================================\n",TotalCount);
}
/*歸還圖書*/
void ReturnBook(Borrow **pBorrow,Book *pHead)
{
char InPutStr[1024];
Borrow TmpBorrow;
bool HasFindBorrwo = false;
memset(&TmpBorrow,0x0,sizeof(TmpBorrow));
printf("請輸入借書證號 : ");
GetInput(InPutStr,1024,true);
TmpBorrow.StuID = atoi(InPutStr);
printf("請輸入所還圖書編號 : ");
GetInput(InPutStr,1024,true);
TmpBorrow.BookID = atoi(InPutStr);
Borrow *pWorkBorrow = *pBorrow;
Borrow *pDeletePre = NULL;
while ( NULL != pWorkBorrow )
{
if ( pWorkBorrow->BookID == TmpBorrow.BookID && pWorkBorrow->StuID == TmpBorrow.StuID )
{
HasFindBorrwo = true;
break;
}
pDeletePre = pWorkBorrow;
pWorkBorrow = pWorkBorrow->pNext;
}
if ( ! HasFindBorrwo )
{
system("cls");
printf("你輸入的借書信息不存在!\n(按回車鍵繼續...)");
fflush(stdin);
getchar();
system("cls");
return;
}
if ( NULL == pDeletePre )
{
*pBorrow = pWorkBorrow->pNext;
}
else
{
pDeletePre->pNext = pWorkBorrow->pNext;
}
Book *pWorkBook = pHead;
while ( NULL != pWorkBook )
{
if ( pWorkBook->BookID == pWorkBorrow->BookID )
{
pWorkBook->CurrentNumber ++;
}
pWorkBook = pWorkBook->pNext;
}
system("cls");
printf("借書證號:%d\n歸還圖書:<<%s>>\n\n操作成功!(按回車鍵繼續...)",pWorkBorrow->StuID,pWorkBorrow->BookName);
fflush(stdin);
getchar();
system("cls");
free(pWorkBorrow);
}
Ⅱ 數據結構課程設計,要求做圖書館管理系統。。已經用mysql寫好了資料庫和求C++和sql鏈接和使用~~
csdn上有很多源碼,去下載吧
還有很多論文都寫好的
使用說明啊等等都寫好的
好像有個網址,可以隨便下
有需要了,改天給你找個鏈接
Ⅲ 數據結構課程設計:小型圖書管理系統
^^#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);
}
Ⅳ 圖書館借閱管理系統,(數據結構課程設計)
網路搜索51aspx這個網站上搜索!