图书管理系统程序代码.docx

上传人:b****5 文档编号:11635581 上传时间:2023-03-29 格式:DOCX 页数:19 大小:20.07KB
下载 相关 举报
图书管理系统程序代码.docx_第1页
第1页 / 共19页
图书管理系统程序代码.docx_第2页
第2页 / 共19页
图书管理系统程序代码.docx_第3页
第3页 / 共19页
图书管理系统程序代码.docx_第4页
第4页 / 共19页
图书管理系统程序代码.docx_第5页
第5页 / 共19页
点击查看更多>>
下载资源
资源描述

图书管理系统程序代码.docx

《图书管理系统程序代码.docx》由会员分享,可在线阅读,更多相关《图书管理系统程序代码.docx(19页珍藏版)》请在冰豆网上搜索。

图书管理系统程序代码.docx

图书管理系统程序代码

图书管理系统

课程设计程序代码

#include

#include

#include

#include

#include

#defineMAXNUM10

#defineMAXNUM10

#defineNUMBER20/*最大物品数量*/

#defineTRUE1

#defineFALSE0

typedefstructbook

{

longintstarting;//借书日期

longintending;//应还日期

charbookinform[120];//这里面存储书籍的描述信息

longintcallnum;//索书号

charbookname[30];

charwriter[20];

inttotalstorage,nowstorage;//书本的馆藏量,现有量

}book;

/*本结构体用于创建链表的二叉树*/

typedefstructvolume

{

bookbooks;

structvolume*lchild;

structvolume*rchild;

}volume,*Btvolume;

typedefstructlibcard

{

charuserID[12];

charpassword[12];//密码

charclientname[20];//用户的名字

charusermessage[150];//用户信息

bookborrow[10];//每本借书证限借书十本

structlibcard*next;

}libcard;

libcard*clients,*current_client=NULL;

/*

*函数声明

*/

voidcreateBST(Btvolume*bst);

voidinsertBST(Btvolume*bst,book*key);

BtvolumesearchBST(Btvolumebst,longintkey);

voidGetPassword(char*str,intn);

intregisterer();

intlogin();//登录

voidclientsev(volume**Btroot);//客户(学生)

intcheck_client(libcard**client);

voidin_stor(volume**root);//入库

voidbackbook(Btvolume*root,longintcallnum);//还书

intlend(Btvolume*root,longintcallnum);//借书,有学生发出请求

structRecord/*本结构体用于保存每一次结果*/

{

inttotalWeight;/*本次结果的总价值*/

intgoods[NUMBER];/*本次结果对应的下标*/

structRecord*next;

};

structRecord*headLink;

structRecordresult;

intstack[NUMBER];

inttop;

intweight[NUMBER];/*保存物品重量的数组*/

intvalue[NUMBER];/*保存对应(下标相同)物品的价值*/

intknapproblen(intn,intmaxweight,intweight[]);

voidCreateHeadLink(void);

structRecord*MallocNode(void);

voidInsertOneNode(structRecord*t);

voidGetResult(void);

voidShowResult(void);

main(){

inta;

printf("----------------选择访问程序----------------\n");

printf("----------------1.背包问题----------------\n");

printf("----------------2.图书系统----------------\n");

printf("----------------0.退出系统----------------\n");

printf("----------------------------------------------\n");

scanf("%d",&a);

if(a==1)

beibao();

elseif(a==2)

tushuguanli();

}

/*

*建立图书库第一本书

*/

voidcreateBST(Btvolume*bst)

{

book*key;

*bst=NULL;

key=(book*)malloc(sizeof(book));

key->starting=0;

key->ending=0;

printf("输入索书号:

");

scanf("%ld",&(key->callnum));

if(key->callnum==0){

free(key);

}

printf("输入入库量:

");

scanf("%d",&(key->totalstorage));

key->nowstorage=key->totalstorage;

printf("输入书本名:

");

scanf("%s",&(key->bookname));

printf("输入著作者:

");

scanf("%s",&(key->writer));

printf("输入书描述:

");

scanf("%s",&(key->bookinform));

if(key!

=NULL)

insertBST(bst,key);

}

/*

*二叉排序树的插入模块,采用递归算法实现*/

voidinsertBST(Btvolume*bst,book*key)

{

Btvolumes;

if(*bst==NULL)//递归结束条件

{

s=(Btvolume)malloc(sizeof(volume));

s->books.callnum=key->callnum;

s->books.nowstorage=key->nowstorage;

s->books.totalstorage=key->totalstorage;

s->books.starting=key->starting;

s->books.ending=key->ending;

strcpy(&(s->books.bookinform),&(key->bookinform));

strcpy(&(s->books.bookname),&(key->bookname));

strcpy(&(s->books.writer),&(key->writer));

s->lchild=NULL;

s->rchild=NULL;

*bst=s;

}

elseif(key->callnum<(*bst)->books.callnum)

{

insertBST(&((*bst)->lchild),key);

}

elseif(key->callnum>(*bst)->books.callnum)

{

insertBST(&((*bst)->rchild),key);

}

else

{

(*bst)->books.nowstorage+=key->nowstorage;

(*bst)->books.totalstorage+=key->totalstorage;

}

}

/*

*二叉排序树的查找算法按索书号为关键字进行二分查找*/

BtvolumesearchBST(Btvolumebst,longintkey)

{

if(bst==NULL)

returnNULL;

if(bst->books.callnum==key)

returnbst;

if(bst->books.callnum

returnsearchBST(bst->rchild,key);

returnsearchBST(bst->lchild,key);

}

/*

*入库函数,用于增加书本库存函数无返回值实现:

1、排序二叉树的建立2、排序二叉树的查找3、排序二叉树的插入4、排序二叉树的删除

*说明:

在这里并没有对物理层进行操作

*/

voidin_stor(volume**root)

{

Btvolumep,q;

book*key;

/*输入数据*/

key=(book*)malloc(sizeof(book));

printf("输入索书号:

");

scanf("%ld",&(key->callnum));

printf("输入入库量:

");

scanf("%d",&(key->totalstorage));

key->nowstorage=key->totalstorage;

printf("输入书本名:

");

scanf("%s",&(key->bookname));

printf("输入著作者:

");

scanf("%s",&(key->writer));

printf("输入书描述:

");

scanf("%s",&(key->bookinform));

key->starting=0;

key->ending=0;

insertBST(root,key);

}

/*

*借书模块,由学生发出请求返回借书是否成功如果当前的可借阅量大于0且学生当前借书量未超过限制则借书成功否则失败*/

intlend(Btvolume*root,longintcallnum)

{

intsuccess=0;//作为返回值,用于标记借阅是否成功

inti=0;

time_tt;

Btvolumetemp;

while(current_client->borrow[i].callnum>0)

i++;

if(i>=10)

printf("对不起,您借的书过多,请先还书!

\n");

else

{

temp=searchBST(*root,callnum);

if(temp==NULL)

printf("对不起,本馆没有收藏此书!

\n");

elseif(temp->books.nowstorage>0)

{

time(&t);

temp->books.nowstorage-=1;

current_client->borrow[i].callnum=callnum;

current_client->borrow[i].starting=t;//获取当前系统时间

current_client->borrow[i].ending=current_client->borrow[i].starting+2592000;

current_client->borrow[i].totalstorage=temp->books.totalstorage;

current_client->borrow[i].nowstorage=temp->books.nowstorage;

strcpy(current_client->borrow[i].bookinform,temp->books.bookinform);

strcpy(current_client->borrow[i].bookname,temp->books.bookname);

strcpy(current_client->borrow[i].writer,temp->books.writer);

success=1;

printf("您已经成功借书,欢迎下次光临!

\n");

}

else

printf("对不起,该书已被借完!

\n");

}

returnsuccess;

}

/*

*还书模块,有学生发出请求每次只能还一本书即便是两本同样的书也需还两次!

无返回值还书后相应库存量增加,同时学生的当前借阅量减少

*如果超期,返回超期天数

*/

voidbackbook(Btvolume*root,longintcallnum)

{

Btvolumetemp;

time_tt;

inti=0;

doubleovertime;

while(i<=10)

{

if(current_client->borrow[i].callnum==callnum)

break;

i++;

}

if(i>=10)

{

printf("对不起,您并未借过此书!

\n");

return;

}

temp=searchBST(*(root),callnum);

if(temp==NULL)

{

printf("您好,本馆并未藏有此书,因此你所还的书不是本馆!

\n");

return;

}

if(temp->books.nowstorage>=temp->books.totalstorage)

{

printf("对不起,本馆未借出此书!

\n");

return;

}

time(&t);

if(t>current_client->borrow[i].ending)

{

overtime=((t-current_client->borrow[i].ending)/43200)+1;

printf("对不起,您所借的书已经超期%0.0f天\n",overtime);

}

/*还书后所做的处理*/

temp->books.nowstorage++;

current_client->borrow[i].bookinform[0]='\0';

current_client->borrow[i].bookname[0]='\0';

current_client->borrow[i].callnum=0;

current_client->borrow[i].ending=2004967296;//

current_client->borrow[i].starting=0;

current_client->borrow[i].nowstorage=0;

current_client->borrow[i].totalstorage=0;

current_client->borrow[i].writer[0]='\0';

printf("书已成功归还,欢迎下次光临!

\n");

}

/*注册模块*/

intregisterer()

{

libcard*client,*client_temp=NULL;

chartemp[13];

inttype,success=0;

inti;

while

(1){

while

(1){

client=(libcard*)malloc(sizeof(libcard));//这里很重要

client->next=NULL;

printf("------------按要求填写有关注册信息--------------\n");

printf("用户ID:

");

scanf("%s",&client->userID);

/*

*检测是否为重复注册

*/

client_temp=clients;

while(client_temp!

=NULL)

{

if(!

strcmp(client->userID,client_temp->userID))//不允许相同ID但允许相同密码

break;

client_temp=client_temp->next;

}

if(client_temp==NULL)//没有相同的ID

{

/*

*注册成功后应对信息进行初始化

*/

for(i=0;i<10;i++)

{

client->borrow[i].bookinform[0]='\0';

client->borrow[i].bookname[0]='\0';

client->borrow[i].writer[0]='\0';

client->borrow[i].callnum=0;

client->borrow[i].starting=0;

client->borrow[i].ending=315360000;//将归还日期初始为无穷大

client->borrow[i].nowstorage=0;

client->borrow[i].totalstorage=0;

}

client->next=clients;

clients=client;

}

else

{

printf("对不起,该ID已被占用,注册失败!

\n");

break;

}

while

(1)

{

printf("密码:

");

GetPassword(&client->password,12);

//scanf("%s",&client->password);

printf("确认密码:

");

GetPassword(&temp,12);

//scanf("%s",&temp);

if(!

strcmp(client->password,temp))//检测密码是否有误

break;

printf("您的密码输入有误,请从新输入\n");

}

printf("请输入用户名字:

");

scanf("%s",&client->clientname);

printf("请输入用户描述:

");

scanf("%s",&client->usermessage);

break;

}

printf("是否继续注册?

(1、继续)(0、退出)");

scanf("%d",&type);

if(!

type)

break;

}

returnsuccess;

}

/*核对用户信息*/

intcheck_client(libcard**client)

{

intsuccess=0;

libcard*temp=clients;

while(temp!

=NULL)//循环验证借书证

{

if(!

strcmp((*client)->userID,temp->userID)&&!

strcmp((*client)->password,temp->password))//如果有其一不对应,则跳入下面一个用户验证

{

free(*client);

*client=temp;

success=1;

break;

}

temp=temp->next;

}

returnsuccess;

}

/*

*客户

*/

voidclientsev(volume**Btroot)

{

inta,b;

volume*temp;

libcard*p=NULL;//用作临时指针

if(current_client==NULL)

{

printf("您还未登录,请登录!

\n");

login();

return;//不管是否成功登陆都将返回原处

}

while

(1)

{

system("cls");////////////清屏

printf("-----------------图书管理系统-----------------\n");

printf("-------------------客户用户---------------------\n");

printf("---------------1、图书借阅--------------------\n");

printf("---------------2、图书归还--------------------\n");

printf("---------------0、退出------------------------\n");

scanf("%d",&a);

switch(a)

{

case1:

printf("输入索书号:

\n");

scanf("%d",&b);

lend(Btroot,b);

break;

case2:

printf("输入索书号:

\n");

scanf("%d",&b);

backbook(Btroot,b);

b

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 高中教育 > 初中教育

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1