数据结构课程设计图书馆管理系统
Ⅰ 数据结构课程设计(基于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这个网站上搜索!