本次期末实训历经八天终于做完了,感觉对于能力的提升还是蛮大的,不管是对于代码能力还是各个方面来讲,也让自己看到了不足之处。话不多说直接上源码。

链接:https://pan.baidu.com/s/1osRKznMSEj1LAjDJ2rN19w
提取码:z1in

系统使用了链表来储存数据,并且使用了easyx制作了可视化界面并添加了鼠标操作。系统本身并没有什么优化,所以代码量很多,后期可能会做一些算法优化等等。

person.h 头文件

#define _CRT_SECURE_NO_WARNINGS 
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<conio.h>
#include<windows.h>
#include<graphics.h>
#include<time.h>
/*
int time()
{
time_t timep;
struct tm* p;
time(&timep);
p = gmtime(&timep);
printf("%d\n", p->tm_year); //年
printf("%d\n", p->tm_mon); //月
printf("%d\n", p->tm_mday); //日
printf("%d\n", 8 + p->tm_hour); //小时
printf("%d\n", p->tm_min); //分钟
}*/

struct brrowbook
{
char name[30];
int time ;
};

struct zhanghao
{
char schoolnumber[30];
char name[30];
char sex[20];
brrowbook book[3];
int many; //借阅的图书数量
};

struct personmessage //登录信息
{
struct zhanghao zhanghao; //信息
char password[20]; //密码
};

struct node_pe //创建链表储存数据
{
struct personmessage data;
struct node_pe* next; //指向下一个数据
};

struct node_pe* creatpehead() //定义一个node*类型的函数,用来储存链表信息
{
struct node_pe* peheadnode = (struct node_pe*)malloc(sizeof(struct node_pe));
//此时headnote是结构体变量,然后初始化
peheadnode->next = NULL;
return peheadnode;
}

struct node_pe* creatpenode(struct personmessage data) //创建结点,为插入做准备
{
struct node_pe* penewnode = (struct node_pe*)malloc(sizeof(struct node_pe));
penewnode->data = data;
penewnode->next = NULL;
return penewnode;
};

void printflist(struct node_pe* peheadnode) //打印链表
{
struct node_pe* pepmove = peheadnode->next;
while (pepmove != NULL) //一直打印直至为空(也说明数据打印完毕)
{
printf("请输入读者的学号");
scanf("%s", pepmove->data.zhanghao.schoolnumber);
printf("请输入读者的姓名");
scanf("%f", pepmove->data.zhanghao.name);
printf("请输入读者的性别");
scanf("%s", pepmove->data.zhanghao.sex);
pepmove = pepmove->next;
}
}

void peinsertnodebyhead(struct node_pe* peheadnode, struct personmessage data) //表头法插入链表
{
struct node_pe* penewnode = creatpenode(data); //要想插入节点必须创建一个新的节点,通过子函数创建节点
penewnode->next = peheadnode->next; //将新节点指向表头的next从而指向表头的下一个节点
peheadnode->next = penewnode; //再将标头的next指向新节点从而使新节点成为表头的下一个节点
}

struct node_pe* pelist = NULL;

void pedeletenotebyname(struct node_pe* peheadnode, char* bookname) // 删除书本
{
struct node_pe* peposleftnode = peheadnode; //定义一个节点指向表头,从而可实现从表头开始查询
struct node_pe* peposnode = peheadnode->next; //定义一个新的结构体实现双线并进
while (peposnode != NULL && strcmp(peposnode->data.zhanghao.name, bookname))
{
peposleftnode = peposnode; //不断地指向下一个,直到查到书名
peposnode = peposleftnode->next;
}
if (peposleftnode == NULL) //说明找不到,结束函数
{
printf("该读者不存在哦");
return;
}
else
{
printf("删除成功,正在返回中,请稍后........."); //将前一个节点的指向指向到下一个节点指向的结构体,从而实现删除
Sleep(1500);
peposleftnode->next = peposnode->next;
free(peposnode); //释放掉动态内存分配的空间
peposnode = NULL;
}
}

struct node_pe* pesearchbyname(struct node_pe* peheadnode, char* bookname) //通过读者姓名查找读者
{
struct node_pe* peposnode = peheadnode->next;
while (peposnode != NULL && strcmp(peposnode->data.zhanghao.name, bookname))
{
peposnode = peposnode->next;
}
return peposnode;
}

struct node_pe* pesearchbynumber(struct node_pe* peheadnode, char* schoolnumber) //通过学号查找
{
struct node_pe* peposnode = peheadnode->next;
while (peposnode != NULL && strcmp(peposnode->data.zhanghao.schoolnumber, schoolnumber))
{
peposnode = peposnode->next;
}
return peposnode;
}

void pesaveinfotofile(const char* filename, struct node_pe* headnode)
{
FILE* fp = fopen(filename, "w");
struct node_pe* pmove = headnode->next;
while (pmove != NULL)
{
fprintf(fp, "%s\t%s\t%s\t%s\t%d\t%s\t%d\t%s\t%d\t%s\t%d\n", pmove->data.zhanghao.schoolnumber, pmove->data.zhanghao.name, pmove->data.zhanghao.sex, pmove->data.password, pmove->data.zhanghao.many, pmove->data.zhanghao.book[0].name, pmove->data.zhanghao.book[0].time, pmove->data.zhanghao.book[1].name, pmove->data.zhanghao.book[1].time, pmove->data.zhanghao.book[2].name, pmove->data.zhanghao.book[2].time);
pmove = pmove->next;
}
fclose(fp);
}

void pereadinfofromfile(const char* filename, struct node_pe* headnode)
{
FILE* fp = fopen(filename, "r");
if (fp == NULL)
{
fp = fopen(filename, "w+");
}
struct personmessage tempdata;
while (fscanf(fp, "%s\t%s\t%s\t%s\t%d\t%s\t%d\t%s\t%d\t%s\t%d\n", tempdata.zhanghao.schoolnumber, tempdata.zhanghao.name, tempdata.zhanghao.sex, tempdata.password, &tempdata.zhanghao.many, tempdata.zhanghao.book[0].name, &tempdata.zhanghao.book[0].time, tempdata.zhanghao.book[1].name, &tempdata.zhanghao.book[1].time, tempdata.zhanghao.book[2].name, &tempdata.zhanghao.book[2].time) != EOF)
{
peinsertnodebyhead(pelist, tempdata);
}

fclose(fp);
}

int dif(int a) //计算借书时间
{
char tempstr[100];
time_t b = time(NULL);
int c = b % 1000000;
int mile = c - a;
int minute = 0, hour = 0, day = 0;
for (; mile >= 60;)
{
mile -= 60;
minute++;
if (minute >= 60)
{
minute -= 60;
hour++;
}
if (hour >= 12)
{
hour -= 12;
day++;
}
}
sprintf(tempstr, "您已借阅%d天/%d时/%d分/%d秒\n", day, hour, minute, mile);
MessageBox(NULL, tempstr, "来自z1in的提醒.", MB_OK | MB_SYSTEMMODAL);
if (day >= 30)
{
MessageBox(NULL, "您已借阅超时,以后记得及时归还", "来自z1in的提醒.", MB_OK | MB_SYSTEMMODAL);
}
return 0;
}


源.cpp

#include"person.h"
using namespace std;

//数据储存

struct bookmessage //与书有关的信息
{
char name[50]; // 书名
float price; //价格
char chubanshe[50]; //出版社
char author[50]; //作者
int num; //数量
int jieyue; //借阅量
};

struct node //创建链表储存数据
{
struct bookmessage data;
struct node* next; //指向下一个数据
};

struct node* creathead() //定义一个node*类型的函数,用来储存链表信息
{
struct node* headnode = (struct node*)malloc(sizeof(struct node));
//此时headnote是结构体变量,然后初始化
headnode->next = NULL;
return headnode;
}

struct node* creatnode(struct bookmessage data) //创建结点,为插入做准备
{
struct node* newnode = (struct node*)malloc(sizeof(struct node));
newnode->data = data;
newnode->next = NULL;
return newnode;
};

void printflist(struct node* headnode) //打印链表
{
IMAGE backimg;
IMAGE choiseimg;
system("cls");
int select;
initgraph(640, 480);
loadimage(&backimg, "004.jpg", 640, 480);
loadimage(&choiseimg, "001.jfif", 420, 30);
//BeginBatchDraw();
putimage(0, 0, &backimg);
putimage(120, 130, &choiseimg);
putimage(120, 180, &choiseimg);
putimage(120, 230, &choiseimg);
putimage(120, 280, &choiseimg);
putimage(120, 330, &choiseimg);
putimage(120, 380, &choiseimg);
putimage(120, 430, &choiseimg);

setbkmode(TRANSPARENT);
setcolor(YELLOW);
settextstyle(40, 0, "Century Gothic");
outtextxy(205, 10, "z1in图书管理系统");
setcolor(BLUE);
settextstyle(20, 0, "Century Gothic");
outtextxy(135, 135, "------------------------------图书信息-----------------------------");
outtextxy(135, 185, "书名 作者 出版社 单价 馆藏量 借阅数");
struct node* pmove = headnode->next;
char tempstr[150];
int x = 0;
while (pmove != NULL) //一直打印直至为空(也说明数据打印完毕)
{
sprintf(tempstr, "%-10s %-10s %-14s %-10.1f %-14d %-6d\n", pmove->data.name, pmove->data.author, pmove->data.chubanshe, pmove->data.price, pmove->data.num, pmove->data.jieyue);
outtextxy(135, 235+x, tempstr);
x += 50;
pmove = pmove->next;
}
outtextxy(315, 435, "退出");
MOUSEMSG msg;
while (1)
{
msg = GetMouseMsg();
switch (msg.uMsg)
{
case WM_LBUTTONDOWN:
if (msg.x >= 120 && msg.x <= 540 && msg.y >= 430 && msg.y <= 460)
{
closegraph();
return;
}
}
}
}

void insertnodebyhead(struct node* headnode, struct bookmessage data) //表头法插入链表
{
struct node* newnode = creatnode(data); //要想插入节点必须创建一个新的节点,通过子函数创建节点
newnode->next = headnode->next; //将新节点指向表头的next从而指向表头的下一个节点
headnode->next = newnode; //再将标头的next指向新节点从而使新节点成为表头的下一个节点
}

//初始化储存图书信息的链表
struct node* list = NULL;

void deletenotebyname(struct node* headnode, char* bookname) // 删除书本
{
struct node* posleftnode = headnode; //定义一个节点指向表头,从而可实现从表头开始查询
struct node* posnode = headnode->next; //定义一个新的结构体实现双线并进
while (posnode != NULL && strcmp(posnode->data.name, bookname))
{
posleftnode = posnode; //不断地指向下一个,直到查到书名
posnode = posleftnode->next;
}
if (posnode == NULL) //说明找不到,结束函数
{
cout << "该书不存在哦" << endl;
return;
}
else
{
cout << "删除成功,正在返回中,请稍后........." << endl; //将前一个节点的指向指向到下一个节点指向的结构体,从而实现删除
Sleep(1500);
posleftnode->next = posnode->next;
free(posnode); //释放掉动态内存分配的空间
posnode = NULL;
}
}

struct node* searchbyname(struct node* headnode, char* bookname) //通过书名查找书
{
struct node* posnode = headnode->next;
while (posnode != NULL && strcmp(posnode->data.name, bookname))
{
posnode = posnode->next;
}
return posnode;
}

struct node* searchbyauthor(struct node* headnode, char* authorname) //通过作者查找书
{
struct node* posnode = headnode->next;
while (posnode != NULL && strcmp(posnode->data.author, authorname))
{
posnode = posnode->next;
}
return posnode;
}

struct node* searchbychubanshe(struct node* headnode, char* chubanshe) //通过出版社查找书
{
struct node* posnode = headnode->next;
while (posnode != NULL && strcmp(posnode->data.chubanshe, chubanshe))
{
posnode = posnode->next;
}
return posnode;
}

/*菜单函数区*/
void showpower();
void showreader();
void password_circle();

/*图书管理区*/
void adb();
int reb();
void deb();
int seb();

/*读者管理区*/
void adp();
int rep();
int dep();
int sep();


IMAGE backimg;
IMAGE choiseimg;

/*用户功能使用区*/
int jieshu(struct node_pe*** reader);
int huanshu(struct node_pe*** reader);
int xujie(struct node_pe*** reader);

/*集中管理函数*/
void bookcon();
void personcon();
void readers( struct node_pe* reader);

/*注册登录选择*/
int rogin();
struct personmessage register_();
void quit();
int login();

//介绍自己
void aboutme()
{
IMAGE backimg;
IMAGE choiseimg;
initgraph(640, 480);
loadimage(&backimg, "004.jpg", 640, 480);
loadimage(&choiseimg, "002.jfif", 60,30);
//BeginBatchDraw();
putimage(0, 0, &backimg);
putimage(280, 400, &choiseimg);

setbkmode(TRANSPARENT);
setcolor(YELLOW);
settextstyle(40, 0, "Century Gothic");
outtextxy(205, 10, "z1in图书管理系统");
setcolor(BLUE);
settextstyle(20, 0, "Century Gothic");
outtextxy(105, 160, "这是一个来自03组的图书管理系统,可能还会有很多的bug");
outtextxy(105, 210, "和不成熟的地方,欢迎大家的指导与纠正。");
outtextxy(295, 405, "返回");

MOUSEMSG msg;
while (1)
{
msg = GetMouseMsg();
switch (msg.uMsg)
{
case WM_LBUTTONDOWN:
if (msg.x >= 280 && msg.x <= 400 && msg.y >= 400 && msg.y <= 430)
{
closegraph();
return;
}
}
}
}

void bubblesort(struct node* headnode)
{
struct node* firstnode = headnode->next;
struct node* secondnode = headnode;
while (firstnode != NULL)
{
while (firstnode->next != NULL)
{
if (firstnode->data.jieyue < firstnode->next->data.jieyue)
{
struct bookmessage temp = firstnode->data;
firstnode->data = firstnode->next->data;
firstnode->next->data = temp;
}
firstnode = firstnode->next;
}
firstnode = secondnode->next;
secondnode = firstnode;
}
}

void saveinfotofile(const char* filename, struct node* headnode)
{
FILE* fp = fopen(filename, "w");
struct node* pmove = headnode->next;
while (pmove != NULL)
{
fprintf(fp, "%s\t%s\t%.1f\t%s\t%d\t%d\n", pmove->data.name, pmove->data.author, pmove->data.price, pmove->data.chubanshe, pmove->data.num, pmove->data.jieyue);
pmove = pmove->next;
}
fclose(fp);
}

void readinfofromfile(const char* filename, struct node* headnode)
{
FILE* fp = fopen(filename, "r");
if (fp == NULL)
{
fp = fopen(filename, "w+");
}
struct bookmessage tempdata;
while (fscanf(fp, "%s\t%s\t%f\t%s\t%d\t%d\n", tempdata.name, tempdata.author, &tempdata.price, tempdata.chubanshe, &tempdata.num, &tempdata.jieyue) != EOF)
{
insertnodebyhead(list, tempdata);
}

fclose(fp);
}

void showpower() //加载菜单
{
system("title 计科20061107-z1in");
cout << "\n\n\n\n\n\n\n" << endl;
cout << "\t\t\t正在打开03组的图书管理系统,请稍等........" << endl;
printf("\t\t\t 欢迎使用图书管理系统\n\n\n\n");
printf("\t\t****************************************************\n");
printf("\t\t* ********** ********** *\n");
printf("\t\t* * * * *\n");
printf("\t\t* * * * *\n");
printf("\t\t* * * * *\n");
printf("\t\t* * * ********** *\n");
printf("\t\t* * * * *\n");
printf("\t\t* * * * *\n");
printf("\t\t* * * * *\n");
printf("\t\t* * * * *\n");
printf("\t\t* ********** ********** *\n");
printf("\t\t****************************************************\n");
Sleep(2500);
}

void password_circle()/*画框函数*/
{
system("cls");
printf("\n\n\n\t\t\t***================================*** \n");
printf("\t\t\t \n");
printf("\t\t\t 学号 (account):");
}

//增加书本
void adb()
{
IMAGE backimg;
IMAGE choiseimg;
IMAGE selectimg;

system("cls");
int select;
zxy:initgraph(640, 480);
loadimage(&backimg, "004.jpg", 640, 480);
loadimage(&choiseimg, "001.jfif", 420, 30);
loadimage(&selectimg, "002.jfif", 80, 30);

//BeginBatchDraw();
putimage(0, 0, &backimg);
putimage(100, 130, &choiseimg);
putimage(100, 180, &choiseimg);
putimage(100, 230, &choiseimg);
putimage(100, 280, &choiseimg);
putimage(100, 330, &choiseimg);
putimage(120, 430, &selectimg);
putimage(430, 430, &selectimg);

setbkmode(TRANSPARENT);
setcolor(YELLOW);
settextstyle(40, 0, "Century Gothic");
outtextxy(205, 10, "z1in图书管理系统");
setcolor(BLUE);
settextstyle(20, 0, "Century Gothic");
outtextxy(130, 135, "请输入书籍的名称");
outtextxy(130, 185, "请输入书籍的价格");
outtextxy(130, 235, "请输入书籍的作者");
outtextxy(130, 285, "请输入书籍的出版社");
outtextxy(130, 335, "请输入书籍的数量");
outtextxy(125, 435, "继续添加");
outtextxy(435, 435, " 退出");

bookmessage a;
char tempprice[20];
char tempnum[10]; //接收inputbox输入的值然后转换为整形

InputBox(a.name, 50, "请输入书籍的名称");
outtextxy(335, 135, a.name);
InputBox(tempprice, 20, "请输入书籍的价格");
outtextxy(335, 185, tempprice);
a.price = atoi(tempprice);
InputBox(a.author, 50, "请输入书籍的作者");
outtextxy(335, 235, a.author);
InputBox(a.chubanshe,50, "请输入书籍的出版社");
outtextxy(335, 285, a.chubanshe);
InputBox(tempnum, 10, "请输入书籍的数量");
outtextxy(335, 335, tempnum);
a.jieyue=0;
a.num = atoi(tempnum);
insertnodebyhead(list, a);
saveinfotofile("book.txt", list);
MessageBox(NULL, "添加成功", "来自z1in的提醒", MB_YESNO | MB_SYSTEMMODAL);
MOUSEMSG msg;
while (1)
{
msg = GetMouseMsg();
switch (msg.uMsg)
{
case WM_LBUTTONDOWN:
if (msg.x >= 120 && msg.x <= 200 && msg.y >= 430 && msg.y <= 460)
{
closegraph();
goto zxy;

}
else if (msg.x >= 430 && msg.x <= 510 && msg.y >= 430 && msg.y <= 460)
{
closegraph();
return;
}
}
}
}

int reb() //更新书本
{
IMAGE backimg;
IMAGE choiseimg;
IMAGE selectimg;

system("cls");
int select;
zxy:initgraph(640, 480);
loadimage(&backimg, "004.jpg", 640, 480);
loadimage(&choiseimg, "001.jfif", 420, 30);
loadimage(&selectimg, "002.jfif", 80, 30);

//BeginBatchDraw();
putimage(0, 0, &backimg);
putimage(130, 60, &choiseimg);
putimage(130, 100, &choiseimg);
putimage(130, 140, &choiseimg);
putimage(130, 180, &choiseimg);
putimage(130, 220, &choiseimg);
putimage(130, 260, &choiseimg);
putimage(130, 300, &choiseimg);
putimage(130, 340, &choiseimg);
putimage(140, 420, &selectimg);
putimage(440, 420, &selectimg);

setbkmode(TRANSPARENT);
setcolor(YELLOW);
settextstyle(40, 0, "Century Gothic");
outtextxy(205, 10, "z1in图书管理系统");
setcolor(BLUE);
settextstyle(20, 0, "Century Gothic");
outtextxy(140, 185, "请输入书籍的名称");
outtextxy(140, 225, "请输入书籍的价格");
outtextxy(140, 265, "请输入书籍的作者");
outtextxy(140, 305, "请输入书籍的出版社");
outtextxy(140, 345, "请输入书籍的数量");
outtextxy(145, 425, "继续修改");
outtextxy(445, 425, " 退出");

char tempprice[20];
char tempnum[10]; //接收inputbox输入的值然后转换为整形
char name[40];
char tempstr[100];

InputBox(name, 40, "请输入想要修改的书籍的名称");
struct node* book = searchbyname(list, name);
if (book != NULL)
{
MessageBox(NULL, "该书存在", "来自z1in的提醒", MB_OK | MB_SYSTEMMODAL);
setcolor(BLUE);
settextstyle(20, 0, "Century Gothic");
outtextxy(145, 65, "------------------------------图书信息-----------------------------");
outtextxy(145, 105, "书名 作者 出版社 单价 馆藏量 借阅数");
sprintf(tempstr, "%-10s %-10s %-14s %-10.1f %-14d %-6d\n", book->data.name, book->data.author, book->data.chubanshe, book->data.price, book->data.num, book->data.jieyue);
outtextxy(145, 145, tempstr);
Sleep(1500);
InputBox(book->data.name, 50, "请输入书籍的名称");
outtextxy(345, 185, book->data.name);
InputBox(tempprice, 20, "请输入书籍的价格");
outtextxy(345, 225, tempprice);
book->data.price = atoi(tempprice);
InputBox(book->data.author, 50, "请输入书籍的作者");
outtextxy(345, 265, book->data.author);
InputBox(book->data.chubanshe, 50, "请输入书籍的出版社");
outtextxy(345, 305, book->data.chubanshe);
InputBox(tempnum, 10, "请输入书籍的数量");
outtextxy(345, 345, tempnum);
book->data.num = atoi(tempnum);
saveinfotofile("book.txt", list);
MessageBox(NULL, "修改成功", "来自z1in的提醒.", MB_OK | MB_SYSTEMMODAL);
}
else
{
MessageBox(NULL, TEXT("没有改书哦。"), TEXT("来自z1in的提醒."), MB_OK | MB_SYSTEMMODAL);
}
MOUSEMSG msg;
while (1)
{
msg = GetMouseMsg();
switch (msg.uMsg)
{
case WM_LBUTTONDOWN:
if (msg.x >= 100 && msg.x <= 180 && msg.y >= 420 && msg.y <= 450)
{
closegraph();
goto zxy;

}
else if (msg.x >= 440 && msg.x <= 520 && msg.y >= 420 && msg.y <= 450)
{
closegraph();
return 0;
}
}
}
}

void deb() // 删除书本
{
IMAGE backimg;
IMAGE choiseimg;
IMAGE selectimg;

system("cls");
int select;
zxy:initgraph(640, 480);
loadimage(&backimg, "004.jpg", 640, 480);
loadimage(&choiseimg, "001.jfif", 420, 30);
loadimage(&selectimg, "002.jfif", 80, 30);

//BeginBatchDraw();
putimage(0, 0, &backimg);
putimage(100, 130, &choiseimg);
putimage(100, 180, &choiseimg);
putimage(100, 230, &choiseimg);
putimage(120, 430, &selectimg);
putimage(430, 430, &selectimg);

setbkmode(TRANSPARENT);
setcolor(YELLOW);
settextstyle(40, 0, "Century Gothic");
outtextxy(205, 10, "z1in图书管理系统");
setcolor(BLUE);
settextstyle(20, 0, "Century Gothic");
outtextxy(125, 435, " 删除");
outtextxy(435, 435, " 退出");

char name[20];
char tempstr[100];
InputBox(name, 20, "请输入您想删除的书本的名称");
struct node* book = searchbyname(list, name);

if (book != NULL)
{
setcolor(BLUE);
settextstyle(20, 0, "Century Gothic");
outtextxy(105, 135, "------------------------------图书信息-----------------------------");
outtextxy(105, 185, "书名 作者 出版社 单价 馆藏量 借阅数");
sprintf(tempstr, "%-10s %-10s %-14s %-10.1f %-14d %-6d\n", book->data.name, book->data.author, book->data.chubanshe, book->data.price, book->data.num, book->data.jieyue);
outtextxy(105, 235, tempstr);

deletenotebyname(list, name);
saveinfotofile("book.txt", list);
MessageBox(NULL, "删除成功", "来自z1in的提醒.", MB_OK | MB_SYSTEMMODAL);
}
else
MessageBox(NULL, "没有您想删除的的书籍哦.", "来自z1in的提醒.", MB_OK | MB_SYSTEMMODAL);

MOUSEMSG msg;
while (1)
{
msg = GetMouseMsg();
switch (msg.uMsg)
{
case WM_LBUTTONDOWN:
if (msg.x >= 100 && msg.x <= 180 && msg.y >= 420 && msg.y <= 450)
{
closegraph();
goto zxy;
}
else if (msg.x >= 440 && msg.x <= 520 && msg.y >= 420 && msg.y <= 450)
{
closegraph();
return;
}
}
}
}

void showseb(struct node* book)
{
IMAGE backimg;
IMAGE choiseimg;
system("cls");
int select;
initgraph(640, 480);
loadimage(&backimg, "004.jpg", 640, 480);
loadimage(&choiseimg, "001.jfif", 420, 30);
//BeginBatchDraw();
putimage(0, 0, &backimg);
putimage(120, 130, &choiseimg);
putimage(120, 180, &choiseimg);
putimage(120, 230, &choiseimg);
putimage(120, 430, &choiseimg);

setbkmode(TRANSPARENT);
setcolor(YELLOW);
settextstyle(40, 0, "Century Gothic");
outtextxy(205, 10, "z1in图书管理系统");
setcolor(BLUE);
settextstyle(20, 0, "Century Gothic");
outtextxy(315, 435, "退出");

char tempstr[100];

sprintf(tempstr, "%-10s %-10s %-14s %-10.1f %-14d %-6d\n", book->data.name, book->data.author, book->data.chubanshe, book->data.price, book->data.num, book->data.jieyue);
setcolor(BLUE);
settextstyle(20, 0, "Century Gothic");
outtextxy(135, 135, "------------------------------图书信息-----------------------------");
outtextxy(135, 185, "书名 作者 出版社 单价 馆藏量 借阅数");
outtextxy(135, 235, tempstr);

MOUSEMSG msg;
while (1)
{
msg = GetMouseMsg();
switch (msg.uMsg)
{
case WM_LBUTTONDOWN:
if (msg.x >= 120 && msg.x <= 540 && msg.y >= 430 && msg.y <= 460)
{
closegraph();
return;
}
}
}
}

int seb() //查找书本
{
IMAGE backimg;
IMAGE choiseimg;
IMAGE selectimg;

system("cls");
zxy:initgraph(640, 480);
loadimage(&backimg, "004.jpg", 640, 480);
loadimage(&choiseimg, "001.jfif", 220, 30);
loadimage(&selectimg, "002.jfif", 80, 30);

//BeginBatchDraw();
putimage(0, 0, &backimg);
putimage(220, 130, &choiseimg);
putimage(220, 180, &choiseimg);
putimage(220, 230, &choiseimg);
putimage(120, 430, &selectimg);
putimage(430, 430, &selectimg);

setbkmode(TRANSPARENT);
setcolor(YELLOW);
settextstyle(40, 0, "Century Gothic");
outtextxy(205, 10, "z1in图书管理系统");
setcolor(BLUE);
settextstyle(20, 0, "Century Gothic");
outtextxy(265, 135, "通过书名查询");
outtextxy(265, 185, "通过书的作者查询");
outtextxy(265, 235, "通过书的出版社查询");
outtextxy(125, 435, " 刷新");
outtextxy(435, 435, " 退出");

int select;
char name[40];
MOUSEMSG msg;
while (1)
{
msg = GetMouseMsg();
switch (msg.uMsg)
{
case WM_LBUTTONDOWN:
if (msg.x >= 220 && msg.x <= 440 && msg.y >= 130 && msg.y <= 160)
{
InputBox(name, 40, "请输入书籍名称");
struct node* book = searchbyname(list, name);
if (book != NULL)
{
MessageBox(NULL, "查询成功", "来自z1in的提醒.", MB_OK | MB_SYSTEMMODAL);
closegraph();
showseb(book);
}
else
{
MessageBox(NULL, TEXT("没有该书哦。"), TEXT("来自z1in的提醒."), MB_OK | MB_SYSTEMMODAL);
}
goto zxy;
}
else if (msg.x >= 220 && msg.x <= 440 && msg.y >= 180 && msg.y <= 210)
{
InputBox(name, 40, "请输入作者名称");
struct node* book = searchbyauthor(list, name);
if (book != NULL)
{
MessageBox(NULL, "查询成功", "来自z1in的提醒.", MB_OK | MB_SYSTEMMODAL);
closegraph();
showseb(book);
}
else
{
MessageBox(NULL, TEXT("没有改书哦。"), TEXT("来自z1in的提醒."), MB_OK | MB_SYSTEMMODAL);
}
goto zxy;
}
else if (msg.x >= 220 && msg.x <= 440 && msg.y >= 230 && msg.y <= 260)
{
InputBox(name, 40, "请输入出版社名称");
struct node* book = searchbychubanshe(list, name);
if (book != NULL)
{
MessageBox(NULL, "查询成功", "来自z1in的提醒.", MB_OK | MB_SYSTEMMODAL);
closegraph();
showseb(book);
}
else
{
MessageBox(NULL, TEXT("没有该书哦。"), TEXT("来自z1in的提醒."), MB_OK | MB_SYSTEMMODAL);
}
goto zxy;
}
else if (msg.x >= 120 && msg.x <= 200 && msg.y >= 430 && msg.y <= 460)
{
closegraph();
goto zxy;
}
else if (msg.x >= 430 && msg.x <= 510 && msg.y >= 430 && msg.y <= 460)
{
closegraph();
return 0;
}
}
}
}

void adp() //读者注册
{
IMAGE backimg;
IMAGE choiseimg;
IMAGE selectimg;

system("cls");
int select;
zxy:initgraph(640, 480);
loadimage(&backimg, "004.jpg", 640, 480);
loadimage(&choiseimg, "001.jfif", 420, 30);
loadimage(&selectimg, "002.jfif", 80, 30);

//BeginBatchDraw();
putimage(0, 0, &backimg);
putimage(100, 130, &choiseimg);
putimage(100, 180, &choiseimg);
putimage(100, 230, &choiseimg);
putimage(100, 280, &choiseimg);
putimage(120, 430, &selectimg);
putimage(430, 430, &selectimg);

setbkmode(TRANSPARENT);
setcolor(YELLOW);
settextstyle(40, 0, "Century Gothic");
outtextxy(205, 10, "z1in图书管理系统");
setcolor(BLUE);
settextstyle(20, 0, "Century Gothic");
outtextxy(130, 135, "请输入读者的学号");
outtextxy(130, 185, "请输入读者的姓名");
outtextxy(130, 235, "请输入读者的性别");
outtextxy(130, 285, "请输入读者的账号密码");
outtextxy(125, 435, "继续添加");
outtextxy(435, 435, " 退出");

personmessage a;
char tempnumber[20]; //接收inputbox输入的值然后转换为整形

InputBox(a.zhanghao.schoolnumber, 50, "请输入读者的学号");
outtextxy(335, 135, a.zhanghao.schoolnumber);
InputBox(a.zhanghao.name, 20, "请输入读者的姓名");
outtextxy(335, 185, a.zhanghao.name);
InputBox(a.zhanghao.sex, 50, "请输入读者的性别");
outtextxy(335, 235, a.zhanghao.sex);
InputBox(a.password, 50, "请输入读者的账号密码");
outtextxy(335, 285, a.password);
a.zhanghao.many = 0;
strcpy(a.zhanghao.book[0].name, "0");
strcpy(a.zhanghao.book[1].name, "0");
strcpy(a.zhanghao.book[2].name, "0");
a.zhanghao.book[0].time = 0;
a.zhanghao.book[1].time = 0;
a.zhanghao.book[2].time = 0;
peinsertnodebyhead(pelist, a);
pesaveinfotofile("person.txt", pelist);
MessageBox(NULL, "添加成功", "来自z1in的提醒", MB_YESNO | MB_SYSTEMMODAL);
MOUSEMSG msg;
while (1)
{
msg = GetMouseMsg();
switch (msg.uMsg)
{
case WM_LBUTTONDOWN:
if (msg.x >= 120 && msg.x <= 200 && msg.y >= 430 && msg.y <= 460)
{
closegraph();
goto zxy;

}
else if (msg.x >= 430 && msg.x <= 510 && msg.y >= 430 && msg.y <= 460)
{
closegraph();
return;
}
}
}
}

int rep() //更新读者
{
IMAGE backimg;
IMAGE choiseimg;
IMAGE selectimg;

system("cls");
int select;
zxy:initgraph(640, 480);
loadimage(&backimg, "004.jpg", 640, 480);
loadimage(&choiseimg, "001.jfif", 420, 30);
loadimage(&selectimg, "002.jfif", 80, 30);

//BeginBatchDraw();
putimage(0, 0, &backimg);
putimage(100, 130, &choiseimg);
putimage(100, 180, &choiseimg);
putimage(100, 230, &choiseimg);
putimage(100, 280, &choiseimg);
putimage(120, 430, &selectimg);
putimage(430, 430, &selectimg);

setbkmode(TRANSPARENT);
setcolor(YELLOW);
settextstyle(40, 0, "Century Gothic");
outtextxy(205, 10, "z1in图书管理系统");
setcolor(BLUE);
settextstyle(20, 0, "Century Gothic");
outtextxy(130, 135, "请输入读者的学号");
outtextxy(130, 185, "请输入读者的姓名");
outtextxy(130, 235, "请输入读者的性别");
outtextxy(130, 285, "请输入读者的账号密码");
outtextxy(125, 435, "继续添加");
outtextxy(435, 435, " 退出");

char tempnumber[50];
char tempnum[10]; //接收inputbox输入的值然后转换为整形
char name[40];
char tempstr[100];
InputBox(name, 40, "请输入想修改的读者的姓名.");
struct node_pe* person = pesearchbyname(pelist, name);

if (person != NULL)
{
MessageBox(NULL, "该读者存在", "来自z1in的提醒.", MB_OK | MB_SYSTEMMODAL);
InputBox(person->data.zhanghao.schoolnumber, 50, "请输入读者的学号");
outtextxy(335, 135, person->data.zhanghao.schoolnumber);
InputBox(person->data.zhanghao.name, 30, "请输入读者的姓名");
outtextxy(335, 185, person->data.zhanghao.name);
InputBox(person->data.zhanghao.sex, 20, "请输入读者的性别");
outtextxy(335, 235, person->data.zhanghao.sex);
InputBox(person->data.password, 20, "请输入读者的账号密码");
outtextxy(335, 285, person->data.password);
pesaveinfotofile("person.txt", pelist);
MessageBox(NULL, "修改成功", "来自z1in的提醒.", MB_OK | MB_SYSTEMMODAL);
}
else
{
MessageBox(NULL, TEXT("没有改读者哦。"), TEXT("提示框"), MB_OK | MB_SYSTEMMODAL);
}
MOUSEMSG msg;
while (1)
{
msg = GetMouseMsg();
switch (msg.uMsg)
{
case WM_LBUTTONDOWN:
if (msg.x >= 100 && msg.x <= 180 && msg.y >= 420 && msg.y <= 450)
{
closegraph();
goto zxy;
}
else if (msg.x >= 440 && msg.x <= 520 && msg.y >= 420 && msg.y <= 450)
{
closegraph();
return 0;
}
}
}
}

int dep() //删除读者
{
IMAGE backimg;
IMAGE choiseimg;
IMAGE selectimg;

system("cls");
int select;
zxy:initgraph(640, 480);
loadimage(&backimg, "004.jpg", 640, 480);
loadimage(&choiseimg, "001.jfif", 420, 30);
loadimage(&selectimg, "002.jfif", 80, 30);

//BeginBatchDraw();
putimage(0, 0, &backimg);
putimage(100, 130, &choiseimg);
putimage(100, 180, &choiseimg);
putimage(100, 230, &choiseimg);
putimage(100, 280, &choiseimg);
putimage(120, 430, &selectimg);
putimage(430, 430, &selectimg);

setbkmode(TRANSPARENT);
setcolor(YELLOW);
settextstyle(40, 0, "Century Gothic");
outtextxy(205, 10, "z1in图书管理系统");
setcolor(BLUE);
settextstyle(20, 0, "Century Gothic");
outtextxy(280, 135, "读者的信息");
outtextxy(125, 435, "继续删除");
outtextxy(435, 435, " 退出");

char name[20];
char tempstr[100];

InputBox(name, 20, "请输入您想删除的读者的姓名");
struct node_pe* person = pesearchbyname(pelist, name);
if (person != NULL)
{
MessageBox(NULL, "该读者存在", "来自z1in的提醒", MB_OK | MB_SYSTEMMODAL);
outtextxy(205,185,"-----------------读者信息-------------------\n");
outtextxy(205,235,"学号 姓名 性别 \n");
sprintf(tempstr, "%-19d %-14s %-8s \n", person->data.zhanghao.schoolnumber, person->data.zhanghao.name, person->data.zhanghao.sex);
outtextxy(205, 285, tempstr);
int i = MessageBox(NULL, "确认删除吗?", "来自z1in的提醒.", MB_YESNO | MB_SYSTEMMODAL);
if (i == 6)
{
pedeletenotebyname(pelist, name);
pesaveinfotofile("person.txt", pelist);
MessageBox(NULL, "读者删除成功", "来自z1in的提醒.", MB_OK | MB_SYSTEMMODAL);
}
}
else
MessageBox(NULL, "您想删除的读者不存在!", "来自z1in的提醒.", MB_OK | MB_SYSTEMMODAL);
MOUSEMSG msg;
while (1)
{
msg = GetMouseMsg();
switch (msg.uMsg)
{
case WM_LBUTTONDOWN:
if (msg.x >= 100 && msg.x <= 180 && msg.y >= 420 && msg.y <= 450)
{
goto zxy;
closegraph();
}
else if (msg.x >= 440 && msg.x <= 520 && msg.y >= 420 && msg.y <= 450)
{
closegraph();
return 0;
}
}
}
}

//显示sep的查找结果
void showsep(struct node_pe* person)
{
IMAGE backimg;
IMAGE choiseimg;
system("cls");
int select;
initgraph(640, 480);
loadimage(&backimg, "004.jpg", 640, 480);
loadimage(&choiseimg, "001.jfif", 420, 30);
//BeginBatchDraw();
putimage(0, 0, &backimg);
putimage(120, 130, &choiseimg);
putimage(120, 180, &choiseimg);
putimage(120, 230, &choiseimg);
putimage(120, 430, &choiseimg);

setbkmode(TRANSPARENT);
setcolor(YELLOW);
settextstyle(40, 0, "Century Gothic");
outtextxy(205, 10, "z1in图书管理系统");
setcolor(BLUE);
settextstyle(20, 0, "Century Gothic");
outtextxy(315, 435, "退出");

char tempstr[100];

sprintf(tempstr, "%-19s %-14s %-8s \n", person->data.zhanghao.schoolnumber, person->data.zhanghao.name, person->data.zhanghao.sex);
setcolor(BLUE);
settextstyle(20, 0, "Century Gothic");
outtextxy(205, 135, "-----------------读者信息-------------------\n");
outtextxy(205, 185, "学号 姓名 性别 \n");
outtextxy(205, 235, tempstr);

MOUSEMSG msg;
while (1)
{
msg = GetMouseMsg();
switch (msg.uMsg)
{
case WM_LBUTTONDOWN:
if (msg.x >= 120 && msg.x <= 540 && msg.y >= 430 && msg.y <= 460)
{
closegraph();
return;
}
}
}
}

int sep() //查找读者
{
IMAGE backimg;
IMAGE choiseimg;
IMAGE selectimg;

system("cls");
zxy:initgraph(640, 480);
loadimage(&backimg, "004.jpg", 640, 480);
loadimage(&choiseimg, "001.jfif", 220, 30);
loadimage(&selectimg, "002.jfif", 80, 30);

//BeginBatchDraw();
putimage(0, 0, &backimg);
putimage(220, 130, &choiseimg);
putimage(220, 180, &choiseimg);
putimage(120, 430, &selectimg);
putimage(430, 430, &selectimg);

setbkmode(TRANSPARENT);
setcolor(YELLOW);
settextstyle(40, 0, "Century Gothic");
outtextxy(205, 10, "z1in图书管理系统");
setcolor(BLUE);
settextstyle(20, 0, "Century Gothic");
outtextxy(265, 135, "通过读者姓名查询");
outtextxy(265, 185, "通过读者学号查询");
outtextxy(125, 435, " 刷新");
outtextxy(435, 435, " 退出");

int select;
char name[40];
char number[30];

MOUSEMSG msg;
while (1)
{
msg = GetMouseMsg();
switch (msg.uMsg)
{
case WM_LBUTTONDOWN:
if (msg.x >= 220 && msg.x <= 440 && msg.y >= 130 && msg.y <= 160)
{
InputBox(name, 40, "请输入读者姓名");
struct node_pe* person = pesearchbyname(pelist, name);
if (person != NULL)
{
MessageBox(NULL, "查询成功", "来自z1in的提醒.", MB_OK | MB_SYSTEMMODAL);
closegraph();
showsep(person);
}
else
{
MessageBox(NULL, TEXT("没有该读者哦。"), TEXT("来自z1in的提醒."), MB_OK | MB_SYSTEMMODAL);
}
goto zxy;
}
else if (msg.x >= 220 && msg.x <= 440 && msg.y >= 180 && msg.y <= 210)
{
InputBox(number, 30, "请输入读者学号");
struct node_pe* person = pesearchbynumber(pelist, number);
if (person != NULL)
{
MessageBox(NULL, "查询成功", "来自z1in的提醒.", MB_OK | MB_SYSTEMMODAL);
closegraph();
showsep(person);
}
else
{
MessageBox(NULL, TEXT("没有改读者哦。"), TEXT("来自z1in的提醒."), MB_OK | MB_SYSTEMMODAL);
}
goto zxy;
}
else if (msg.x >= 120 && msg.x <= 200 && msg.y >= 430 && msg.y <= 460)
{
closegraph();
goto zxy;
}
else if (msg.x >= 430 && msg.x <= 510 && msg.y >= 430 && msg.y <= 460)
{
closegraph();
return 0;
}
}
}
}


//与登陆管理员有关的函数
int rogin() //简单的登陆管理员函数
{
char console[20] = "1234563"; //设置管理员密钥
system("cls");
initgraph(640, 480);
loadimage(&backimg, "004.jpg", 720, 1280);
loadimage(&choiseimg, "001.jfif", 220, 30);
//BeginBatchDraw();
putimage(0, 0, &backimg);
putimage(220, 130, &choiseimg);
putimage(220, 180, &choiseimg);
putimage(220, 230, &choiseimg);

setbkmode(TRANSPARENT);
setcolor(YELLOW);
settextstyle(40, 0, "Century Gothic");
outtextxy(205, 10, "z1in图书管理系统");
setcolor(BLUE);
settextstyle(20, 0, "Century Gothic");
outtextxy(265, 135, " 管 理 员 登 陆");
outtextxy(265, 185, " 读 者 登 录");
outtextxy(265, 235, " 退 出 ");
//EndBatchDraw();

int select;
int select_;
zxy:select = select = MessageBox(NULL, "您需要获得管理员权限,是否登陆管理员.", "来自z1in的提醒:", MB_YESNO | MB_SYSTEMMODAL);
char crypto[20]="0";
for (;;) //for循环避免重复输入y、n以外的值导致无法实现登录
{
if (select == 6 )
{
InputBox(crypto, 20, "请输入管理员密钥:");
if (strcmp(crypto,console) !=0 ) //判断密码是否正确
{
zxy_:select_ = MessageBox(NULL, "密钥不正确,是否继续登录.", "来自z1in的提醒.", MB_YESNO | MB_SYSTEMMODAL);
for (;;)
{
if (select_ == 6 )
{
select = 6;
break;
}
else if (select_ == 7 )
{
select = 7;
return 0;
}
}
}
else
{
return 1; //正确的话返回函数值为1
}
}
else if (select == 7 )
{
return 0; //若不登陆管理员则返回函数值为0
}
}
}

int jieshu(struct node_pe*** reader) //借书
{
IMAGE backimg;
IMAGE choiseimg;
system("cls");
int select;
initgraph(640, 480);
loadimage(&backimg, "004.jpg", 640, 480);
loadimage(&choiseimg, "001.jfif", 420, 30);
//BeginBatchDraw();
putimage(0, 0, &backimg);
putimage(120, 130, &choiseimg);
putimage(120, 180, &choiseimg);
putimage(120, 230, &choiseimg);
putimage(120, 430, &choiseimg);

setbkmode(TRANSPARENT);
setcolor(YELLOW);
settextstyle(40, 0, "Century Gothic");
outtextxy(205, 10, "z1in图书管理系统");
setcolor(BLUE);
settextstyle(20, 0, "Century Gothic");
outtextxy(315, 435, "退出");
char tempbook[40];
char tempstr[60];
InputBox(tempbook, 40, "请输入您想借阅的书籍");
struct node* book = searchbyname(list, tempbook);
if (book != NULL )
{
if ((**reader)->data.zhanghao.many < 3 && book->data.num>0)
{
time_t b = time(NULL);
strcpy((**reader)->data.zhanghao.book[(**reader)->data.zhanghao.many].name, book->data.name);
(**reader)->data.zhanghao.book[(**reader)->data.zhanghao.many].time = b %1000000;
(**reader)->data.zhanghao.many++;
book->data.num--;
book->data.jieyue++;
sprintf(tempstr, "借阅成功,您当前已借阅%d本,还可借阅%d本,记得及时还书哦!\n", (**reader)->data.zhanghao.many, (3 - (**reader)->data.zhanghao.many));
MessageBox(NULL, tempstr, "来自z1in的提醒", MB_OK | MB_SYSTEMMODAL);
sprintf(tempstr, "%-10s %-10s %-14s %-10.1f %-14d %-6d\n", book->data.name, book->data.author, book->data.chubanshe, book->data.price, book->data.num, book->data.jieyue);
setcolor(BLUE);
settextstyle(20, 0, "Century Gothic");
outtextxy(135, 135, "------------------------------图书信息-----------------------------");
outtextxy(135, 185, "书名 作者 出版社 单价 馆藏量 借阅数");
outtextxy(135, 235, tempstr);
}
else
MessageBox(NULL, "您的借阅本书以达到上限, 看完书再来借哦", "来自z1in的提醒", MB_OK | MB_SYSTEMMODAL);
}
else
MessageBox(NULL, "暂时没有该书哦,可以向管理员反应哦", "来自z1in的提醒", MB_OK | MB_SYSTEMMODAL);

MOUSEMSG msg;
while (1)
{
msg = GetMouseMsg();
switch (msg.uMsg)
{
case WM_LBUTTONDOWN:
if (msg.x >= 120 && msg.x <= 540 && msg.y >= 430 && msg.y <= 460)
{
closegraph();
return 0;
}
}
}
}

int huanshu(struct node_pe*** reader) //还书
{
IMAGE backimg;
IMAGE choiseimg;
IMAGE selectimg;
system("cls");
int select;
initgraph(640, 480);
loadimage(&backimg, "004.jpg", 640, 480);
loadimage(&choiseimg, "001.jfif", 420, 30);
loadimage(&selectimg, "002.jfif", 60, 30);
//BeginBatchDraw();
putimage(0, 0, &backimg);
putimage(120, 80, &choiseimg);
putimage(120, 130, &choiseimg);
putimage(120, 180, &choiseimg);
putimage(120, 230, &choiseimg);
putimage(120, 430, &selectimg);
putimage(490, 430, &selectimg);

setbkmode(TRANSPARENT);
setcolor(YELLOW);
settextstyle(40, 0, "Century Gothic");
outtextxy(205, 10, "z1in图书管理系统");
setcolor(BLUE);
settextstyle(20, 0, "Century Gothic");
outtextxy(125, 435, "还书");
outtextxy(495, 435, "退出");
char tempstr[100];

if ((**reader)->data.zhanghao.many != 0)
{
outtextxy(275, 85, "您已借阅的书籍");
settextstyle(20, 0, "Century Gothic");
outtextxy(135, 135, "------------------------------图书信息-----------------------------");
outtextxy(135, 185, "书名 作者 出版社 单价 馆藏量 借阅数");
int x = 0;
for (int i = 0; i < 3; i++)
{
if (searchbyname(list, (**reader)->data.zhanghao.book[i].name) != NULL)
{
node* tempbook = searchbyname(list, (**reader)->data.zhanghao.book[i].name);
sprintf(tempstr, "%-10s %-10s %-14s %-10.1f %-14d %-6d\n", tempbook->data.name, tempbook->data.author, tempbook->data.chubanshe, tempbook->data.price, tempbook->data.num, tempbook->data.jieyue);
outtextxy(135, 235 + x, tempstr);
x += 50;
putimage(120, 230+x, &choiseimg);
}
}
char tempbook[30];
int flag = 1;
int flag1 = 0;
MOUSEMSG msg;
while (1)
{
msg = GetMouseMsg();
switch (msg.uMsg)
{
case WM_LBUTTONDOWN:
if (msg.x >= 120 && msg.x <= 180 && msg.y >= 430 && msg.y <= 460)
{
InputBox(tempbook, 30, "请输入您要归还的书籍名称");
for (int i = 0; i < 3; i++)
{
if (strcmp((**reader)->data.zhanghao.book[i].name, tempbook) == 0)
{
time_t b = time(NULL);
char qingkong[30] = { "0" };
strcpy((**reader)->data.zhanghao.book[i].name, qingkong);
dif((**reader)->data.zhanghao.book[i].time);
(**reader)->data.zhanghao.many--;
(**reader)->data.zhanghao.book[i].time = 0;
struct node* book1 = searchbyname(list, tempbook);
book1->data.num++;
MessageBox(NULL, "您已归还成功.", "来自z1in的提醒.", MB_OK | MB_SYSTEMMODAL);
break;
}
else if (i == 3)
{
MessageBox(NULL, "您并没有借阅该书哦.", "来自z1in的提醒.", MB_OK | MB_SYSTEMMODAL);
break;
}
}
}
if (msg.x >= 490 && msg.x <= 550 && msg.y >= 430 && msg.y <= 460)
{
closegraph();
return 0;
}
}
}
}
else
MessageBox(NULL, "您没有未归还的书籍哦.", "来自z1in的提醒.", MB_OK | MB_SYSTEMMODAL);
return 0;
}

int xujie(struct node_pe*** reader) //续借图书
{
IMAGE backimg;
IMAGE choiseimg;
IMAGE selectimg;
system("cls");
int select;
initgraph(640, 480);
loadimage(&backimg, "004.jpg", 640, 480);
loadimage(&choiseimg, "001.jfif", 420, 30);
loadimage(&selectimg, "002.jfif", 60, 30);
//BeginBatchDraw();
putimage(0, 0, &backimg);
putimage(120, 130, &choiseimg);
putimage(120, 180, &choiseimg);
putimage(120, 230, &choiseimg);
putimage(120, 280, &choiseimg);
putimage(120, 430, &selectimg);
putimage(490, 430, &selectimg);

setbkmode(TRANSPARENT);
setcolor(YELLOW);
settextstyle(40, 0, "Century Gothic");
outtextxy(205, 10, "z1in图书管理系统");
setcolor(BLUE);
settextstyle(20, 0, "Century Gothic");
outtextxy(125, 435, "续借");
outtextxy(495, 435, "退出");
int i = 0;
int flag = 0;
char tempname[40];
char tempbook[30];
char tempstr[100];

if ((**reader)->data.zhanghao.many != 0)
{
outtextxy(275, 135, "您已借阅的书籍");
settextstyle(20, 0, "Century Gothic");
outtextxy(135, 185, "------------------------------图书信息-----------------------------");
outtextxy(135, 235, "书名 作者 出版社 单价 馆藏量 借阅数");
int x = 0;
for (int i = 0; i < 3; i++)
{
if (searchbyname(list, (**reader)->data.zhanghao.book[i].name) != NULL)
{
node* tempbook = searchbyname(list, (**reader)->data.zhanghao.book[i].name);
sprintf(tempstr, "%-10s %-10s %-14s %-10.1f %-14d %-6d\n", tempbook->data.name, tempbook->data.author, tempbook->data.chubanshe, tempbook->data.price, tempbook->data.num, tempbook->data.jieyue);
outtextxy(135, 285 + x, tempstr);
x += 50;
putimage(120, 280 + x, &choiseimg);
}
}
MOUSEMSG msg;
while (1)
{
msg = GetMouseMsg();
switch (msg.uMsg)
{
case WM_LBUTTONDOWN:
if (msg.x >= 120 && msg.x <= 180 && msg.y >= 430 && msg.y <= 460)
{
InputBox(tempbook, 30, "请输入您要续借的书籍名称");
for (int i = 0; i < 3; i++)
{
if (strcmp((**reader)->data.zhanghao.book[i].name, tempbook) == 0)
{
(**reader)->data.zhanghao.book[i].time = 0;
MessageBox(NULL, "您已续借成功.", "来自z1in的提醒.", MB_OK | MB_SYSTEMMODAL);
flag += 1;
}
}
if (flag == 0)
{
MessageBox(NULL, "您并没有借阅该书哦.", "来自z1in的提醒.", MB_OK | MB_SYSTEMMODAL);
}
}
if (msg.x >= 490 && msg.x <= 550 && msg.y >= 430 && msg.y <= 460)
{
closegraph();
return 0;
}
}
}
}
else
MessageBox(NULL, "您还没有未归还的书哦.", "来自z1in的提醒.", MB_OK | MB_SYSTEMMODAL);
//dif((**reader)->data.zhanghao.book->a);
}

void popular(struct node* list)
{
bubblesort(list);
printflist(list);
return;
}

void tuijian(struct node* list)
{
IMAGE backimg;
IMAGE choiseimg;
IMAGE selectimg;
system("cls");
int select;
initgraph(640, 480);
loadimage(&backimg, "004.jpg", 640, 480);
loadimage(&choiseimg, "001.jfif", 420, 30);
loadimage(&selectimg, "002.jfif", 80, 30);
//BeginBatchDraw();
putimage(0, 0, &backimg);
putimage(120, 130, &choiseimg);
putimage(120, 180, &choiseimg);
putimage(120, 230, &choiseimg);
putimage(120, 280, &choiseimg);
putimage(110, 430, &selectimg);
putimage(490, 430, &selectimg);

setbkmode(TRANSPARENT);
setcolor(YELLOW);
settextstyle(40, 0, "Century Gothic");
outtextxy(205, 10, "z1in图书管理系统");
setcolor(BLUE);
settextstyle(20, 0, "Century Gothic");
outtextxy(115, 435, "修改价位");
outtextxy(495, 435, "退出");

zxy:int flag = 0;
char target[20];
char tempstr[100];

InputBox(target, 20, "请输入您的理想价格,我们将推荐与您理想价格稍低的书.");
float idea = atoi(target);
bubblesort(list);
struct node* pmove = list->next;
system("cls");
outtextxy(275, 135, "为您查询到以下书籍");
settextstyle(20, 0, "Century Gothic");
outtextxy(135, 185, "------------------------------图书信息-----------------------------");
outtextxy(135, 235, "书名 作者 出版社 单价 馆藏量 借阅数");

int x = 0;

while (pmove != NULL) //一直打印直至为空(也说明数据打印完毕)
{
if (pmove->data.price <= idea && flag < 4)
{
sprintf(tempstr, "%-10s %-10s %-14s %-10.1f %-14d %-6d\n", pmove->data.name, pmove->data.author, pmove->data.chubanshe, pmove->data.price, pmove->data.num, pmove->data.jieyue);
outtextxy(135, 285 + x, tempstr);
x += 50;
putimage(120, 280+x, &choiseimg);
flag++;
}
pmove = pmove->next;
}
if (flag == 0)
{
MessageBox(NULL, "没有理想价位的书哦.", "来自z1in的提醒.", MB_OK | MB_SYSTEMMODAL);
}
MOUSEMSG msg;
while (1)
{
msg = GetMouseMsg();
switch (msg.uMsg)
{
case WM_LBUTTONDOWN:
if (msg.x >= 110 && msg.x <= 170 && msg.y >= 430 && msg.y <= 460)
{
goto zxy;
}
if (msg.x >= 490 && msg.x <= 550 && msg.y >= 430 && msg.y <= 460)
{
closegraph();
return;
}
}
}
}

void bookcon() //图书管理函数
{
IMAGE backimg;
IMAGE choiseimg;
system("cls");
zxy:initgraph(640, 480);
loadimage(&backimg, "004.jpg", 640, 480);
loadimage(&choiseimg, "001.jfif", 220, 30);
//BeginBatchDraw();
putimage(0, 0, &backimg);
putimage(220, 130, &choiseimg);
putimage(220, 180, &choiseimg);
putimage(220, 230, &choiseimg);
putimage(220, 280, &choiseimg);
putimage(220, 330, &choiseimg);

setbkmode(TRANSPARENT);
setcolor(YELLOW);
settextstyle(40, 0, "Century Gothic");
outtextxy(205, 10, "z1in图书管理系统");
setcolor(BLUE);
settextstyle(20, 0, "Century Gothic");
outtextxy(265, 135, " 增加图书");
outtextxy(265, 185, " 删除图书");
outtextxy(265, 235, " 更新图书");
outtextxy(265, 285, " 查询图书 ");
outtextxy(265, 335, " 退 出 ");
//EndBatchDraw();
MOUSEMSG msg;
while (1)
{
msg = GetMouseMsg();
switch (msg.uMsg)
{
case WM_LBUTTONDOWN:
if (msg.x >= 220 && msg.x <= 420 && msg.y >= 130 && msg.y <= 160)
{
closegraph();
adb();
goto zxy;
}
else if (msg.x >= 220 && msg.x <= 420 && msg.y >= 180 && msg.y <= 210)
{
closegraph();
deb();
goto zxy;
}
else if (msg.x >= 220 && msg.x <= 440 && msg.y >= 230 && msg.y <= 260)
{
closegraph();
reb();
goto zxy;
}
else if (msg.x >= 220 && msg.x <= 420 && msg.y >= 280 && msg.y <= 310)
{
closegraph();
seb();
goto zxy;
}
else if (msg.x >= 220 && msg.x <= 440 && msg.y >= 330 && msg.y <= 360)
{
outtextxy(265, 335, " 退出中,请稍等...... ");
closegraph();
return;
}
}
}
}

void personcon() //读者管理系统
{
IMAGE backimg;
IMAGE choiseimg;
zxy:system("cls");
initgraph(640, 480);
loadimage(&backimg, "004.jpg", 640, 480);
loadimage(&choiseimg, "001.jfif", 220, 30);
//BeginBatchDraw();
putimage(0, 0, &backimg);
putimage(220, 130, &choiseimg);
putimage(220, 180, &choiseimg);
putimage(220, 230, &choiseimg);
putimage(220, 280, &choiseimg);
putimage(220, 330, &choiseimg);

setbkmode(TRANSPARENT);
setcolor(YELLOW);
settextstyle(40, 0, "Century Gothic");
outtextxy(205, 10, "z1in图书管理系统");
setcolor(BLUE);
settextstyle(20, 0, "Century Gothic");
outtextxy(265, 135, " 增加读者");
outtextxy(265, 185, " 删除读者");
outtextxy(265, 235, " 更新读者");
outtextxy(265, 285, " 查询读者 ");
outtextxy(265, 335, " 退 出 ");
//EndBatchDraw();
MOUSEMSG msg;
while (1)
{
msg = GetMouseMsg();
switch (msg.uMsg)
{
case WM_LBUTTONDOWN:
if (msg.x >= 220 && msg.x <= 420 && msg.y >= 130 && msg.y <= 160)
{
closegraph();
adp();
goto zxy;
}
else if (msg.x >= 220 && msg.x <= 420 && msg.y >= 180 && msg.y <= 210)
{
closegraph();
dep();
goto zxy;
}
else if (msg.x >= 220 && msg.x <= 440 && msg.y >= 230 && msg.y <= 260)
{
closegraph();
rep();
goto zxy;
}
else if (msg.x >= 220 && msg.x <= 420 && msg.y >= 280 && msg.y <= 310)
{
closegraph();
sep();
goto zxy;
}
else if (msg.x >= 220 && msg.x <= 440 && msg.y >= 330 && msg.y <= 360)
{
closegraph();
outtextxy(265, 335, " 退出中,请稍等...... ");
return;
}
}
}
}

void readers(struct node_pe** reader) //读者的操作
{
zxy:IMAGE backimg;
IMAGE choiseimg;
system("cls");
int select;
initgraph(640, 480);
loadimage(&backimg, "004.jpg", 640, 480);
loadimage(&choiseimg, "001.jfif", 220, 30);
//BeginBatchDraw();
putimage(0, 0, &backimg);
putimage(220, 130, &choiseimg);
putimage(220, 180, &choiseimg);
putimage(220, 230, &choiseimg);
putimage(220, 280, &choiseimg);
putimage(220, 330, &choiseimg);
putimage(220, 380, &choiseimg);
setbkmode(TRANSPARENT);
setcolor(YELLOW);
settextstyle(40, 0, "Century Gothic");
outtextxy(205, 10, "z1in图书管理系统");
setcolor(BLUE);
settextstyle(20, 0, "Century Gothic");
outtextxy(265, 135, " 借书");
outtextxy(265, 185, " 还书");
outtextxy(265, 235, " 续借");
outtextxy(255, 285, " 图书受欢迎度排行榜");
outtextxy(255, 335, " 价位书籍推荐");
outtextxy(265, 385, " 退出 ");
//EndBatchDraw();
MOUSEMSG msg;
while (1)
{
msg = GetMouseMsg();
switch (msg.uMsg)
{
case WM_LBUTTONDOWN:
if (msg.x >= 220 && msg.x <= 420 && msg.y >= 130 && msg.y <= 160)
{
closegraph();
jieshu(&reader);
goto zxy;
}
else if (msg.x >= 220 && msg.x <= 420 && msg.y >= 180 && msg.y <= 210)
{
closegraph();
huanshu(&reader);
goto zxy;
}
else if (msg.x >= 220 && msg.x <= 440 && msg.y >= 230 && msg.y <= 260)
{
closegraph();
xujie(&reader);
goto zxy;
}
else if (msg.x >= 220 && msg.x <= 420 && msg.y >= 280 && msg.y <= 310)
{
closegraph();
popular(list);
goto zxy;
}
else if (msg.x >= 220 && msg.x <= 440 && msg.y >= 330 && msg.y <= 360)
{
closegraph();
tuijian(list);
goto zxy;
}
else if (msg.x >= 220 && msg.x <= 420 && msg.y >= 380 && msg.y <= 410)
{
closegraph();
return;
}
}
}
}

struct personmessage register_()
{
IMAGE backimg;
IMAGE choiseimg;
system("cls");
int select;
initgraph(640, 480);
loadimage(&backimg, "004.jpg", 640, 480);
loadimage(&choiseimg, "001.jfif", 420, 30);

//BeginBatchDraw();
putimage(0, 0, &backimg);
putimage(100, 130, &choiseimg);
putimage(100, 180, &choiseimg);
putimage(100, 230, &choiseimg);

setbkmode(TRANSPARENT);
setcolor(YELLOW);
settextstyle(40, 0, "Century Gothic");
outtextxy(205, 10, "z1in图书管理系统");
setcolor(BLUE);
settextstyle(20, 0, "Century Gothic");
outtextxy(130, 135, "请输入您的姓名");
outtextxy(130, 185, "请输入您的性别");
outtextxy(130, 235, "请输入您的账户密码 ");
//EndBatchDraw();

int flag = 1; int flag1 = 1;
char tempnumber[20]; //学号
char crypto[20]; //密码
struct personmessage reader;
system("cls");
password_circle();
fflush(stdin);
char number[30];
InputBox(number, 30, "请输入您的学号:");
if (pesearchbynumber(pelist, number) != NULL)
{
while (flag)
{
system("cls");
struct node_pe* pereader = pesearchbynumber(pelist, number);
InputBox(crypto, 20, "请输入您的密码:");
if (strcmp(crypto,pereader->data.password)==0)
{
flag = 0;
MessageBox(NULL, "您已成功登录","来自z1in的提醒:",MB_OK | MB_SYSTEMMODAL);
readers(&pereader);
pesaveinfotofile("person.txt", pelist);
saveinfotofile("book.txt", list);
}
else
{
int select = MessageBox(NULL, "密码错误,是否继续登录.", "来自z1in的提醒", MB_YESNO | MB_SYSTEMMODAL);
if (select == 6)
flag = 1;
else if (select == 7)
flag = 0;
}
}
}
else
{
MessageBox(NULL, "该账户还未注册,请先注册", "来自z1in的提醒.", MB_OK | MB_SYSTEMMODAL);
strcpy(reader.zhanghao.schoolnumber, number);
char ch;
int x = 350;
InputBox(reader.zhanghao.name, 30, "请输入您的姓名");
outtextxy(335, 135, reader.zhanghao.name);
InputBox(reader.zhanghao.sex, 20, "请输入您的性别");
outtextxy(335, 185, reader.zhanghao.sex);
InputBox(reader.password, 20, "请输入您的账户密码");
outtextxy(335, 235, reader.password);
reader.zhanghao.many = 0;
strcpy(reader.zhanghao.book[0].name, "0");
strcpy(reader.zhanghao.book[1].name, "0");
strcpy(reader.zhanghao.book[2].name, "0");
reader.zhanghao.book[0].time = 0;
reader.zhanghao.book[1].time = 0;
reader.zhanghao.book[2].time = 0;
settextstyle(25, 0, "Century Gothic");
setcolor(YELLOW);
outtextxy(155, 400, "注册成功,正在返回中,请稍后.......");
Sleep(2000);
closegraph();
peinsertnodebyhead(pelist, reader);
struct node_pe* pereader = pesearchbynumber(pelist,number);
readers(&pereader);
pesaveinfotofile("person.txt", pelist);
saveinfotofile("book.txt", list);
}
return reader;
}

void quit()
{
int select;
cout << "您确定要退出吗?" << "是/y,否/n" << endl;
for(;;)
{
select = _getch();
if (select == 'y')
exit(0);
else if (select == 'n')
break;
else
cout << "输入不正确,请重新输入" << endl;
}
system("cls");
}

//选择登陆方式的函数
int login()
{
system("cls");
int select;
zxy:initgraph(640, 480);
loadimage(&backimg, "004.jpg", 640, 480);
loadimage(&choiseimg, "001.jfif", 220, 30);
//BeginBatchDraw();
putimage(0, 0, &backimg);
putimage(220, 130, &choiseimg);
putimage(220, 180, &choiseimg);
putimage(220, 230, &choiseimg);
putimage(220, 280, &choiseimg);

setbkmode(TRANSPARENT);
setcolor(YELLOW);
settextstyle(40, 0, "Century Gothic");
outtextxy(205, 10, "z1in图书管理系统");
setcolor(BLUE);
settextstyle(20, 0, "Century Gothic");
outtextxy(265, 135, " 管 理 员 登 陆");
outtextxy(265, 185, " 读 者 登 录");
outtextxy(265, 235, " 退 出 ");
outtextxy(265, 285, " about me");
//EndBatchDraw();
MOUSEMSG msg;
while (1)
{
msg = GetMouseMsg();
switch (msg.uMsg)
{
case WM_LBUTTONDOWN:
if (msg.x >= 220 && msg.x <= 420 && msg.y >= 130 && msg.y <= 160)
{
closegraph();
int i = rogin();
if (i == 1)
{
MessageBoxA(NULL, "您已成功登陆管理员。", "来自z1in的提醒",MB_OK | MB_SYSTEMMODAL);
return 1;
}
}
else if (msg.x >= 220 && msg.x <= 420 && msg.y >= 180 && msg.y <= 210)
{
closegraph();
register_();
return -1;;//调用第二个函数
}
else if (msg.x >= 220 && msg.x <= 440 && msg.y >= 230 && msg.y <= 260)
{
closegraph();
exit(0);
}
else if (msg.x >= 220 && msg.x <= 440 && msg.y >= 280 && msg.y <= 310)
{
closegraph();
aboutme();
goto zxy;
}
}
}
}

//初始化链表和文件读的地方并提供管理员模式的功能入口
int main()
{
/*time_t b = time(NULL);
printf("%lld", b);
system("pause");*/
list = creathead();
pelist = creatpehead();
readinfofromfile("book.txt", list);
pereadinfofromfile("person.txt", pelist);

showpower();
system("cls");
zxy:int i = login();
int select;
while (1)
{
if (i == 1)
{
system("cls");
zxy1:initgraph(640, 480);
loadimage(&backimg, "004.jpg", 640, 480);
loadimage(&choiseimg, "001.jfif", 220, 30);
//BeginBatchDraw();
putimage(0, 0, &backimg);
putimage(220, 130, &choiseimg);
putimage(220, 180, &choiseimg);
putimage(220, 230, &choiseimg);

setbkmode(TRANSPARENT);
setcolor(YELLOW);
settextstyle(40, 0, "Century Gothic");
outtextxy(205, 10, "z1in图书管理系统");
setcolor(BLUE);
settextstyle(20, 0, "Century Gothic");
outtextxy(265, 135, " 图 书 管 理");
outtextxy(265, 185, " 读 者 管 理");
outtextxy(265, 235, " 退 出 ");
//EndBatchDraw();
MOUSEMSG msg;
while (1)
{
msg = GetMouseMsg();
switch (msg.uMsg)
{
case WM_LBUTTONDOWN:
if (msg.x >= 220 && msg.x <= 420 && msg.y >= 130 && msg.y <= 160)
{
closegraph();
bookcon();
goto zxy1;
}
else if (msg.x >= 220 && msg.x <= 420 && msg.y >= 180 && msg.y <= 210)
{
closegraph();
personcon();
goto zxy1;
}
else if (msg.x >= 220 && msg.x <= 440 && msg.y >= 230 && msg.y <= 260)
{
closegraph();
goto zxy;
}
}
}
}
else if (i == -1)
{
/*system("cls");
initgraph(640, 480);
loadimage(&backimg, "003.jfif", 640, 480);
loadimage(&choiseimg, "001.jfif", 220, 30);
//BeginBatchDraw();
putimage(0, 0, &backimg);
putimage(220, 130, &choiseimg);
putimage(220, 180, &choiseimg);

setbkmode(TRANSPARENT);
setcolor(YELLOW);
settextstyle(40, 0, "Century Gothic");
outtextxy(205, 10, "z1in图书管理系统");
setcolor(BLUE);
settextstyle(20, 0, "Century Gothic");
outtextxy(265, 135, " 借 书 管 理");
outtextxy(265, 185, " 退 出 ");
//EndBatchDraw();
MOUSEMSG msg;
while (1)
{
msg = GetMouseMsg();
switch (msg.uMsg)
{
case WM_LBUTTONDOWN:
if (msg.x >= 220 && msg.x <= 420 && msg.y >= 130 && msg.y <= 160)
{
register_();
closegraph();
}
else if (msg.x >= 220 && msg.x <= 420 && msg.y >= 180 && msg.y <= 210)
{
goto zxy;
closegraph();
}
}
}*/
goto zxy;
}
}
return 0;
}

}

另外说一下敲代码的时候遇到的bug吧,最麻烦的bug应该就是使用链表的时候的异常报错了: ….指向nullptr的问题等等,后来发现是因为自己竟然傻到通过参数传递去修改链表的数据,其实根本不需要什么参数传递,只需要将链表定义为全局变量直接引用就可以了,能出现这种问题我也是够傻的了…..
还有的就是什么异常访问报错,出现这种情况一般就是你定义的数组的问题了,自己查看一下关于数组的读写看看有没有输入数据的长度大于数组的长度。另外推荐大家学一下动态调试,真的特别舒服,比如我在写删除读者功能的函数时就发现我想删除的能查询到可就是删不掉,用动态调试才发现是因为我在用fscanf输入一个自定义数组tempstr时因为数组长度过小,导致内容溢出到了我的用于存放像删除的读者的姓名的数组中了,导致我虽然查到了,可实际在删除的时候输入的确实另一个读者的姓名。
好了就说到这里了。
以上就是所有的代码了,会有好多不成熟且可笑的bug,就见笑了,若果发现什么bug的话可以联系我的邮箱 1679369498@qq.com