代码有参考CSDN上某位前辈的,但是我忘记是哪一个来着了…如果有人发现侵权,请联系我删除。
直接上代码了,里面有注释。
头文件及替换
#include
#include
#include
#include
#include
#define S sizeof(struct BOOK)
#define D sizeof(struct READER)
#define J sizeof(struct BORROW)
图书信息、读者信息、借阅信息的结构体
struct BOOK //图书信息,不可把数组写满,否则取用文件中内容时出现错误
{
char number[10]; //库存编号号
char name[26]; //书名
char author[20]; //作者名
char type[10]; //图书类型
char publish[18]; //图书出版社
float price; //图书定价
int _amount; //图书当前在库数量
int amount; //图书数量
int total; //图书被借次数
int x;
struct BOOK *next;
};
typedef struct BOOK Book; //类型定义符typedef将之后可以用Book代替结构体BOOK
typedef Book *book; //用指针*book代替Book
struct READER //读者信息
{
char readernumber[12]; //读者编号
char readername[12]; //名字
char readersex[4]; //性别
char password[12]; //密码
char tele[12]; //联系电话
int s; //性别标记
int readertotal; //已借阅图书数
int y;
struct READER *next;
};
typedef struct READER Reader;
typedef Reader *reader;
struct BORROW //借阅信息
{
char borrowamount[12]; //借阅者编号
char borrowname[12]; //借阅读者姓名
char borrowsex[4]; //性别
char borrowtele[12]; //借阅者电话
char booknumber[10]; //库存编号号
char bookname[26]; //书名
char bookauthor[20]; //作者名
char booktype[10]; //图书类型
char bookpublish[18]; //图书出版社
int z;
struct BORROW *next;
};
typedef struct BORROW Borrow;
typedef Borrow *borrow;
文件
book booklist();
reader readerlist();
borrow borrowlist();
book booklist() //将文件中的内容读出到链表中,返回值为表头地址
{
FILE *fs; //初始化FILE,定义一个指向FILE结构体的指针,借此通过文件指针变量获取文件操作过程中FILE结构体中某些成员信息
int n = 0;
book bookhead = NULL;
book bookpc = NULL;
book bookpa, bookpb;
fs = fopen("repository.txt", "at+"); //读写打开文本文件repository,允许读与在文件末追加数据
if (fs == NULL) //如果返回的指针为空,表示不能打开repository文件
{
printf("无法打开repository文件\n");
}
while (!feof(fs)) //判断文件位置标志是否移动到文件末尾,feof检测文件结束符,如果文件结束返回非0值,否则返回0
{
n++;
bookpa = (book)malloc(S); //调用malloc函数分配结构体BOOK所占用内存空间,并将返回值强制转换为该类型指针
fread(bookpa, S, 1, fs); //调用数据块读写函数fread,表示一个指针bookpa,用于存放数据首地址;N表示数据块字节数;1表示要读写一个数据块;fp表示文件指针
if (n == 1) //
{
bookhead = bookpa; //头指针指向bookpa
bookpb = bookpa; //bookpb指向bookpa
}
else //创建链表
{
bookpc = bookpb; //bookpc指向bookpb
bookpb->next = bookpa; //bookpb指向下一位
bookpb = bookpa; //bookpb指向bookpa
}
}
if (bookpc != NULL)bookpc->next = NULL; //链表结束,最后一个指针指向空
else bookhead = NULL; //链表为空
fclose(fs); //关闭文件
return bookhead; //返回头指针
}
reader readerlist() //将文件中的内容读出到链表中,返回值为表头地址
{
FILE *fd; //初始化FILE,定义一个指向FILE结构体的指针,借此通过文件指针变量获取文件操作过程中FILE结构体中某些成员信息
int n = 0;
reader readerhead = NULL;
reader readerpc = NULL;
reader readerpa, readerpb;
fd = fopen("reader.txt", "at+"); //读写打开文本文件reader,允许读与在文件末追加数据
if (fd == NULL) //如果返回的指针为空,表示不能打开reader文件
{
printf("无法打开reader文件\n");
}
while (!feof(fd)) //判断文件位置标志是否移动到文件末尾,feof检测文件结束符,如果文件结束返回非0值,否则返回0
{
n++;
readerpa = (reader)malloc(D); //调用malloc函数分配结构体BOOK所占用内存空间,并将返回值强制转换为该类型指针
fread(readerpa, D, 1, fd); //调用数据块读写函数fread,表示一个指针readerpa,用于存放数据首地址;N表示数据块字节数;1表示要读写一个数据块;fp表示文件指针
if (n == 1) //
{
readerhead = readerpa; //头指针指向readerpa
readerpb = readerpa; //readerpb指向readerpa
}
else //创建链表
{
readerpc = readerpb; //readerpc指向readerpb
readerpb->next = readerpa; //readerpb指向下一位
readerpb = readerpa; //readerpb指向readerpa
}
}
if (readerpc != NULL)readerpc->next = NULL; //链表结束,最后一个指针指向空
else readerhead = NULL; //链表为空
fclose(fd); //关闭文件
return readerhead; //返回头指针
}
borrow borrowlist() //将文件中的内容读出到链表中,返回值为表头地址
{
FILE *fj; //初始化FILE,定义一个指向FILE结构体的指针,借此通过文件指针变量获取文件操作过程中FILE结构体中某些成员信息
int n = 0;
borrow borrowhead = NULL;
borrow borrowpc = NULL;
borrow borrowpa, borrowpb;
fj = fopen("borrow.txt", "at+"); //读写打开文本文件borrow,允许读与在文件末追加数据
if (fj == NULL) //如果返回的指针为空,表示不能打开borrow文件
{
printf("无法打开borrow文件\n");
}
while (!feof(fj)) //判断文件位置标志是否移动到文件末尾,feof检测文件结束符,如果文件结束返回非0值,否则返回0
{
n++;
borrowpa = (borrow)malloc(J); //调用malloc函数分配结构体BOOK所占用内存空间,并将返回值强制转换为该类型指针
fread(borrowpa, J, 1, fj); //调用数据块读写函数fread,表示一个指针readerpa,用于存放数据首地址;N表示数据块字节数;1表示要读写一个数据块;fp表示文件指针
if (n == 1) //
{
borrowhead = borrowpa; //头指针指向borrowpa
borrowpb = borrowpa; //borrowpb指向borrowpa
}
else //创建链表
{
borrowpc = borrowpb; //borrowpc指向borrowpb
borrowpb->next = borrowpa; //borrowpb指向下一位
borrowpb = borrowpa; //borrowpb指向borrowpa
}
}
if (borrowpc != NULL)borrowpc->next = NULL; //链表结束,最后一个指针指向空
else borrowhead = NULL; //链表为空
fclose(fj); //关闭文件
return borrowhead; //返回头指针
}
声明
//第一模块:控制台界面模块()
void HideCursor(); //隐藏光标
void Toxy(int x, int y); //将光标移动到X,Y坐标处
void Color(short x); //设置颜色
void Menu(); //菜单
void FindBook(); //查询图书界面
void BookCatalog(); //图书总览
void ReaderMenu(); //借阅与归还
void AdministratorMenu(); //管理员界面
void Over(); //退出软件
//第二模块:图书查询模块()
void FindBookName(); //根据书名查询图书
void FindBookAuthor(); //根据作者姓名查询图书
void FindBookNumber(); //根据图书库存编号查询图书
void FindBookPublish(); //根据出版社查询图书
void FindBookType(); //根据图书类型查询图书
void FuzzySearch(); //模糊查询图书
void FuzzyCatalog(); //图书总览-库存先后
void BookNameCatalog(); //图书总览-书名
void BookAuthorCatalog(); //图书总览-作者
void BookNumberCatalog(); //图书总览-库存编号
void BookTypeCatalog(); //图书总览-书籍类型
void BookTotalCatalog(); //图书总览-借阅量
//第三模块:读者模块()
void ReaderRegister(); //读者注册
void BorrowBooks(); //借阅图书
void ReturnBooks(); //归还图书
//第四模块:管理员模块()
void EnterRepository(); //图书入库
void ChangeRepository(); //修改图书库存信息
void DeleteRepository(); //删除图书库存信息
void ReorderRepository(); //存书信息排序
void ReaderInformation(); //读者信息界面
void ReaderInformationCatalog(); //读者信息总览
void ChangeReaderInformation(); //修改读者信息
void DeleteReaderInformation(); //删除读者信息
void BorrowInformationCatalog(); //借阅总览
第一部分
void HideCursor() //隐藏光标
{
CONSOLE_CURSOR_INFO cursor_info = { 1,0 }; //CONSOLE_CURSOR_INFO这个结构包含的是控制台光标的信息,1,0为光标厚度和可见度,如若没下面一句,光标照样会出来
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info); //SetConsoleCursorInfo是用来设置指定的控制台光标的大小和可见性,GetStdHandle(STD_OUTPUT_HANDLE)返回标准的输出的句柄,并赋值给对象cursor_info
} //GetStdHandle和SetConsoleTextAttribute在头文件windows.h中
void Toxy(int x, int y) //将光标移动到X,Y坐标处
{
COORD pos = { x , y }; //COORD是Windows API中定义的一种结构,表示一个字符在控制台屏幕上的坐标。
HANDLE Out = GetStdHandle(STD_OUTPUT_HANDLE); //并新建句柄Out,实例化句柄Out
SetConsoleCursorPosition(Out, pos); //SetConsoleCursorPosition是一个计算机函数,如果用户定义了 COORD pos,
} //那么pos其实是一个结构体变量,其中X和Y是它的成员,通过修改pos.X和pos.Y的值就可以实现光标的位置控制。
void Color(short x) //设置颜色
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), x); //SetConsoleTextAttribute()函数是一个API设置字体颜色和背景色的函数
}
void Menu() //菜单
{
do
{
system("cls"); //清屏
HideCursor(); //隐藏光标
Color(15); //设置菜单颜色为亮白色
char t;
Toxy(50, 5); //将光标移动到(50,5)坐标处
printf("lime图书查询管理系统");
Toxy(48, 8);
printf("| 1.图书查询 |");
Toxy(48, 10);
printf("| 2.图书总览 |");
Toxy(48, 12);
printf("| 3.读者注册 |");
Toxy(48, 14);
printf("| 4.借阅与归还 |");
Toxy(48, 16);
printf("| 5.管理员界面 |");
Toxy(48, 18);
printf("| 0.退出软件 |");
t = getch(); //不回显函数
switch (t)
{
case '1':FindBook(); break;
case '2':BookCatalog(); break;
case '3':ReaderRegister(); break;
case '4':ReaderMenu(); break;
case '5':AdministratorMenu(); break;
case '0':Over(); break;
default:break;
}
} while (1);
}
void Over() //退出软件
{
char t;
system("cls");
Color(12);
Toxy(48, 11);
printf("-----------------------");
Toxy(48, 12);
printf("| 您确定要退出吗? |");
Toxy(48, 14);
printf("| 1.确定 2.取消 |");
Toxy(48, 15);
printf("-----------------------");
while (1)
{
t = getch();
switch (t)
{
case '1':
system("cls");
Color(12);
Toxy(48, 10);
printf("正在安全退出....");
Sleep(1000); //暂停1秒
system("cls");
Color(11);
Toxy(48, 10);
printf("已安全退出软件");
Toxy(48, 12);
printf("谢谢使用!");
Toxy(48, 14);
printf("by-by^_^");
Sleep(1000); //暂停1秒
exit(0); break; //终止程序
case '2':
Menu(); break; //调用函数,进入菜单
default:break;
}
}
}
void FindBook() //查询图书界面
{
do
{
system("cls"); //清屏
Color(14);
char t;
Toxy(56, 6);
printf(" 图书查询");
Toxy(48, 8);
printf("| 1.书名 查询 |");
Toxy(48, 10);
printf("| 2.作者 查询 |");
Toxy(48, 12);
printf("| 3.库存编号查询 |");
Toxy(48, 14);
printf("| 4.出版社查询 |");
Toxy(48, 16);
printf("| 5.图书类别查询 |");
Toxy(48, 18);
printf("| 6.模糊 查询 |");
Toxy(50, 20);
printf("按0返回主菜单");
t = getch();
switch (t)
{
case '1':FindBookName(); break;
case '2':FindBookAuthor(); break;
case '3':FindBookNumber(); break;
case '4':FindBookPublish(); break;
case '5':FindBookType(); break;
case '6':FuzzySearch(); break;
case '0':Menu(); break;
default:break;
}
} while (1);
}
void BookCatalog() //图书总览
{
do
{
system("cls"); //清屏
Color(13);
char t;
Toxy(58, 6);
printf("图书总览");
Toxy(48, 8);
printf("| 1.库存先后排序 |");
Toxy(48, 10);
printf("| 2.按书名排序 |");
Toxy(48, 12);
printf("| 3.按作者排序 |");
Toxy(48, 14);
printf("| 4.按库存编号排序 |");
Toxy(48, 16);
printf("| 5.按图书类别排序 |");
Toxy(48, 18);
printf("| 6.按借阅量排序 |");
Toxy(50, 20);
printf("按0返回主菜单");
t = getch();
switch (t)
{
case '1':FuzzyCatalog(); break;
case '2':BookNameCatalog(); break;
case '3':BookAuthorCatalog(); break;
case '4':BookNumberCatalog(); break;
case '5':BookTypeCatalog(); break;
case '6':BookTotalCatalog(); break;
case '0':Menu(); break;
default:break;
}
} while (1);
}
void ReaderMenu() //借阅与归还
{
do
{
system("cls"); //清屏
HideCursor(); //隐藏光标
Color(15); //设置菜单颜色为亮白色
char t;
Toxy(50, 5); //将光标移动到(50,5)坐标处
printf("lime图书管理系统");
Toxy(48, 8);
printf("| 1.借阅图书 |");
Toxy(48, 10);
printf("| 2.归还图书 |");
Toxy(48, 12);
printf("| 0.返回主菜单 |");
t = getch(); //不回显函数
switch (t)
{
case '1':BorrowBooks(); break;
case '2':ReturnBooks(); break;
case '0':Menu(); break;
default:break;
}
} while (1);
}
void AdministratorMenu() //管理员界面
{
do
{
system("cls"); //清屏
HideCursor(); //隐藏光标
Color(15); //设置菜单颜色为亮白色
char t;
Toxy(50, 5); //将光标移动到(50,5)坐标处
printf("lime图书管理系统");
Toxy(48, 8);
printf("| 1.图书入库 |");
Toxy(48, 10);
printf("| 2.图书借阅信息总览 |");
Toxy(48, 12);
printf("| 3.管理读者信息 |");
Toxy(48, 14);
printf("| 4.修改存书信息 |");
Toxy(48, 16);
printf("| 5.删除存书信息 |");
Toxy(48, 18);
printf("| 6.存书信息排序 |");
Toxy(48, 20);
printf("| 0.返回主菜单 |");
t = getch(); //不回显函数
switch (t)
{
case '1':EnterRepository(); break;
case '2':BorrowInformationCatalog(); break;
case '3':ReaderInformation(); break;
case '4':ChangeRepository(); break;
case '5':DeleteRepository(); break;
case '6':ReorderRepository(); break;
case '0':Menu(); break;
default:break;
}
} while (1);
}
void ReaderInformation() //读者信息界面
{
do
{
system("cls"); //清屏
HideCursor(); //隐藏光标
Color(15); //设置菜单颜色为亮白色
char t;
Toxy(50, 5); //将光标移动到(50,5)坐标处
printf("lime图书管理系统");
Toxy(48, 8);
printf("| 1.修改读者信息 |");
Toxy(48, 10);
printf("| 2.删除读者信息 |");
Toxy(48, 12);
printf("| 3.读者信息总览 |");
Toxy(48, 14);
printf("| 0.返回管理员菜单 |");
t = getch(); //不回显函数
switch (t)
{
case '1':ChangeReaderInformation(); break;
case '2':DeleteReaderInformation(); break;
case '3':ReaderInformationCatalog(); break;
case '0':AdministratorMenu(); break;
default:break;
}
} while (1);
}
第二模块
void FindBookName() //根据书名查询图书
{
system("cls");
Color(14);
book bookhead, bookp;
int i = 10;
bookhead = booklist();
char name[25];
Toxy(48, 8);
printf("请输入您要查询图书的书名:");
gets(name);
Toxy(48, 9);
printf("正在查询....");
Sleep(500);
bookp = bookhead;
Toxy(2, 5);
printf("************************************************图书总览************************************************************");
Toxy(2, 7);
printf("--------------------------------------------------------------------------------------------------------------------");
Toxy(2, 8);
printf("|库存编号|书名 |作者名 |图书类别|出版单位 |图书定价|在库数量| 总数量| 借阅量|");
Toxy(2, 9);
printf("--------------------------------------------------------------------------------------------------------------------");
while (bookp != NULL)
{
if (bookp != NULL && strcmp(bookp->name, name) == 0)
{
Toxy(2, i);
printf("|%8s|%24s|%18s|%8s|%16s|%8.2f|%8d|%8d|%8d|", bookp->number, bookp->name, bookp->author, bookp->type, bookp->publish, bookp->price, bookp->_amount, bookp->amount, bookp->total);
i++;
Toxy(2, i);
printf("--------------------------------------------------------------------------------------------------------------------");
i++;
}
bookp = bookp->next;
}
Toxy(45, i);
printf("按任意键返回!");
getch();
FindBook();
}
void FindBookAuthor() //根据作者姓名查询图书
{
system("cls");
Color(14);
book bookhead, bookp;
int i = 10;
bookhead = booklist();
char author[19];
Toxy(48, 8);
printf("请输入您要查询图书的作者名:");
gets(author);
Toxy(48, 9);
printf("正在查询....");
Sleep(500);
bookp = bookhead;
Toxy(2, 5);
printf("************************************************图书总览************************************************************");
Toxy(2, 7);
printf("--------------------------------------------------------------------------------------------------------------------");
Toxy(2, 8);
printf("|库存编号|书名 |作者名 |图书类别|出版单位 |图书定价|在库数量| 总数量| 借阅量|");
Toxy(2, 9);
printf("--------------------------------------------------------------------------------------------------------------------");
while (bookp != NULL)
{
if (strcmp(bookp->author, author) == 0)
{
Toxy(2, i);
printf("|%8s|%24s|%18s|%8s|%16s|%8.2f|%8d|%8d|%8d|", bookp->number, bookp->name, bookp->author, bookp->type, bookp->publish, bookp->price, bookp->_amount, bookp->amount, bookp->total);
i++;
Toxy(2, i);
printf("--------------------------------------------------------------------------------------------------------------------");
i++;
}
bookp = bookp->next;
}
Toxy(45, i);
printf("按任意键返回!");
getch();
FindBook();
}
void FindBookNumber() //根据图书库存编号查询图书
{
system("cls");
Color(14);
book bookhead, bookp;
int i = 10;
bookhead = booklist();
char number[9];
Toxy(48, 8);
printf("请输入您要查询八位图书库存编号:");
gets(number);
Toxy(48, 9);
printf("正在查询....");
Sleep(500);
bookp = bookhead;
Toxy(2, 5);
printf("************************************************图书总览************************************************************");
Toxy(2, 7);
printf("--------------------------------------------------------------------------------------------------------------------");
Toxy(2, 8);
printf("|库存编号|书名 |作者名 |图书类别|出版单位 |图书定价|在库数量| 总数量| 借阅量|");
Toxy(2, 9);
printf("--------------------------------------------------------------------------------------------------------------------");
while (bookp != NULL)
{
if (bookp != NULL && strcmp(bookp->number, number) == 0)
{
Toxy(2, i);
printf("|%8s|%24s|%18s|%8s|%16s|%8.2f|%8d|%8d|%8d|", bookp->number, bookp->name, bookp->author, bookp->type, bookp->publish, bookp->price, bookp->_amount, bookp->amount, bookp->total);
i++;
Toxy(2, i);
printf("--------------------------------------------------------------------------------------------------------------------");
i++;
}
bookp = bookp->next;
}
Toxy(45, i);
printf("按任意键返回!");
getch();
FindBook();
}
void FindBookPublish() //根据出版社查询图书
{
system("cls");
Color(14);
book bookhead, bookp;
int i = 10;
bookhead = booklist();
char publish[17];
Toxy(48, 8);
printf("请输入您要查询图书的出版社:");
gets(publish);
Toxy(48, 9);
printf("正在查询....");
Sleep(500);
bookp = bookhead;
Toxy(2, 5);
printf("************************************************图书总览************************************************************");
Toxy(2, 7);
printf("--------------------------------------------------------------------------------------------------------------------");
Toxy(2, 8);
printf("|库存编号|书名 |作者名 |图书类别|出版单位 |图书定价|在库数量| 总数量| 借阅量|");
Toxy(2, 9);
printf("--------------------------------------------------------------------------------------------------------------------");
while (bookp != NULL)
{
if (bookp != NULL && strcmp(bookp->publish, publish) == 0)
{
Toxy(2, i);
printf("|%8s|%24s|%18s|%8s|%16s|%8.2f|%8d|%8d|%8d|", bookp->number, bookp->name, bookp->author, bookp->type, bookp->publish, bookp->price, bookp->_amount, bookp->amount, bookp->total);
i++;
Toxy(2, i);
printf("--------------------------------------------------------------------------------------------------------------------");
i++;
}
bookp = bookp->next;
}
Toxy(45, i);
printf("按任意键返回!");
getch();
FindBook();
}
void FindBookType() //根据图书类型查询图书
{
system("cls");
Color(14);
book bookhead, bookp;
int i = 10;
bookhead = booklist();
char type[9]; //图书类型;
Toxy(48, 8);
printf("请输入您要查询图书的类型:");
gets(type);
Toxy(48, 9);
printf("正在查询....");
Sleep(500);
bookp = bookhead;
Toxy(2, 5);
printf("************************************************图书总览************************************************************");
Toxy(2, 7);
printf("--------------------------------------------------------------------------------------------------------------------");
Toxy(2, 8);
printf("|库存编号|书名 |作者名 |图书类别|出版单位 |图书定价|在库数量| 总数量| 借阅量|");
Toxy(2, 9);
printf("--------------------------------------------------------------------------------------------------------------------");
while (bookp != NULL)
{
if (bookp != NULL && strcmp(bookp->type, type) == 0)
{
Toxy(2, i);
printf("|%8s|%24s|%18s|%8s|%16s|%8.2f|%8d|%8d|%8d|", bookp->number, bookp->name, bookp->author, bookp->type, bookp->publish, bookp->price, bookp->_amount, bookp->amount, bookp->total);
i++;
Toxy(2, i);
printf("--------------------------------------------------------------------------------------------------------------------");
i++;
}
bookp = bookp->next;
}
Toxy(45, i);
printf("按任意键返回!");
getch();
FindBook();
}
void FuzzySearch() //模糊查询图书
{
system("cls");
Color(14);
book bookhead, bookp;
int i = 10;
bookhead = booklist();
char information[25];
Toxy(48, 8);
printf("请输入您要查询图书的信息:");
gets(information);
Toxy(48, 9);
printf("正在查询....");
Sleep(500);
bookp = bookhead;
Toxy(2, 5);
printf("************************************************图书总览************************************************************");
Toxy(2, 7);
printf("--------------------------------------------------------------------------------------------------------------------");
Toxy(2, 8);
printf("|库存编号|书名 |作者名 |图书类别|出版单位 |图书定价|在库数量| 总数量| 借阅量|");
Toxy(2, 9);
printf("--------------------------------------------------------------------------------------------------------------------");
while (bookp != NULL)
{
if (bookp != NULL && (strcmp(bookp->name, information) == 0 || strcmp(bookp->author, information) == 0 || strcmp(bookp->number, information) == 0 || strcmp(bookp->publish, information) == 0) || strcmp(bookp->type, information) == 0)
{
Toxy(2, i);
printf("|%8s|%24s|%18s|%8s|%16s|%8.2f|%8d|%8d|%8d|", bookp->number, bookp->name, bookp->author, bookp->type, bookp->publish, bookp->price, bookp->_amount, bookp->amount, bookp->total);
i++;
Toxy(2, i);
printf("--------------------------------------------------------------------------------------------------------------------");
i++;
}
bookp = bookp->next;
}
Toxy(45, i);
printf("按任意键返回!");
getch();
FindBook();
}
void FuzzyCatalog() //图书总览-乱序
{
system("cls");
Color(14);
book bookhead, bookp;
int i = 10;
int book_amount = 0, bookamount = 0;
bookhead = booklist();
Toxy(2, 5);
printf("************************************************图书总览************************************************************");
Toxy(2, 7);
printf("--------------------------------------------------------------------------------------------------------------------");
Toxy(2, 8);
printf("|库存编号|书名 |作者名 |图书类别|出版单位 |图书定价|在库数量| 总数量| 借阅量|");
Toxy(2, 9);
printf("--------------------------------------------------------------------------------------------------------------------");
bookp = bookhead;
if (bookhead == NULL)
{
Toxy(2, 10);
printf("书库暂时没有书哦~赶快去添加几本吧^_^(按任意键返回)\n");
getch();
BookCatalog();
}
while (bookp != NULL)
{
Toxy(2, i);
printf("|%8s|%24s|%18s|%8s|%16s|%8.2f|%8d|%8d|%8d|", bookp->number, bookp->name, bookp->author, bookp->type, bookp->publish, bookp->price, bookp->_amount, bookp->amount, bookp->total);
i++;
Toxy(2, i);
printf("--------------------------------------------------------------------------------------------------------------------");
i++;
book_amount += bookp->_amount;//计算图书总量
bookamount += bookp->amount;//计算图书总量
bookp = bookp->next;
}
Toxy(2, i);
printf(" 当前库存图书总量为:%d,书库图书总量为:%d\n", book_amount, bookamount);
i++;
Toxy(2, i);
printf("按任意键返回\n");
getch();//不回显函数
BookCatalog();
}
void BookNameCatalog() //图书总览-书名
{
system("cls");
Color(14);
book bookhead, bookp, a[10000], temp;
int i, j,t;
bookhead = booklist();
Toxy(2, 5);
printf("************************************************图书总览************************************************************");
Toxy(2, 7);
printf("--------------------------------------------------------------------------------------------------------------------");
Toxy(2, 8);
printf("|库存编号|书名 |作者名 |图书类别|出版单位 |图书定价|在库数量| 总数量| 借阅量|");
Toxy(2, 9);
printf("--------------------------------------------------------------------------------------------------------------------");
bookp = bookhead;
for (i = 0; bookp != NULL; bookp = bookp->next, i++) a[i] = bookp;
t = i;
for (i = 0;iname, a[j]->name) > 0)
{
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
j = 0; i = 10;
while (jnumber, a[j]->name, a[j]->author, a[j]->type, a[j]->publish, a[j]->price, a[j]->_amount, a[j]->amount, a[j]->total);
i++;
Toxy(2, i);
printf("--------------------------------------------------------------------------------------------------------------------");
i++;
j++;
}
Toxy(2, i);
i++;
Toxy(2, i);
printf("按任意键返回\n");
getch();
BookCatalog();
}
void BookAuthorCatalog() //图书总览-作者
{
system("cls");
Color(14);
book bookhead, bookp, a[10000], temp;
int i, j,t;
bookhead = booklist();
Toxy(2, 5);
printf("************************************************图书总览************************************************************");
Toxy(2, 7);
printf("--------------------------------------------------------------------------------------------------------------------");
Toxy(2, 8);
printf("|库存编号|书名 |作者名 |图书类别|出版单位 |图书定价|在库数量| 总数量| 借阅量|");
Toxy(2, 9);
printf("--------------------------------------------------------------------------------------------------------------------");
bookp = bookhead;
if (bookhead == NULL)
{
Toxy(2, 10);
printf("书库暂时没有书哦~赶快去添加几本吧^_^(按任意键返回)\n");
getch();
BookCatalog();
}
for (i = 0; bookp != NULL; bookp = bookp->next, i++) a[i] = bookp;
t = i;
for (i = 0;iauthor, a[j]->author) > 0)
{
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
j = 0; i = 10;
while (jnumber, a[j]->name, a[j]->author, a[j]->type, a[j]->publish, a[j]->price, a[j]->_amount, a[j]->amount, a[j]->total);
i++;
Toxy(2, i);
printf("--------------------------------------------------------------------------------------------------------------------");
i++;
j++;
}
Toxy(2, i);
i++;
Toxy(2, i);
printf("按任意键返回\n");
getch();
BookCatalog();
}
void BookNumberCatalog() //图书总览-库存编号
{
system("cls");
Color(14);
book bookhead, bookp, a[10000], temp;
int i, j,t;
bookhead = booklist();
Toxy(2, 5);
printf("************************************************图书总览************************************************************");
Toxy(2, 7);
printf("--------------------------------------------------------------------------------------------------------------------");
Toxy(2, 8);
printf("|库存编号|书名 |作者名 |图书类别|出版单位 |图书定价|在库数量| 总数量| 借阅量|");
Toxy(2, 9);
printf("--------------------------------------------------------------------------------------------------------------------");
bookp = bookhead;
if (bookhead == NULL)
{
Toxy(2, 10);
printf("书库暂时没有书哦~赶快去添加几本吧^_^(按任意键返回)\n");
getch();
BookCatalog();
}
for (i = 0; bookp != NULL; bookp = bookp->next, i++) a[i] = bookp;
t = i;
for (i = 0; inumber, a[j]->number) > 0)
{
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
j = 0; i = 10;
while (jnumber, a[j]->name, a[j]->author, a[j]->type, a[j]->publish, a[j]->price, a[j]->_amount, a[j]->amount, a[j]->total);
i++;
Toxy(2, i);
printf("--------------------------------------------------------------------------------------------------------------------");
i++;
j++;
}
Toxy(2, i);
i++;
Toxy(2, i);
printf("按任意键返回\n");
getch();
BookCatalog();
}
void BookTypeCatalog() //图书总览-类别
{
system("cls");
Color(14);
book bookhead, bookp, a[10000], temp;
int i, j,t;
bookhead = booklist();
Toxy(2, 5);
printf("************************************************图书总览************************************************************");
Toxy(2, 7);
printf("--------------------------------------------------------------------------------------------------------------------");
Toxy(2, 8);
printf("|库存编号|书名 |作者名 |图书类别|出版单位 |图书定价|在库数量| 总数量| 借阅量|");
Toxy(2, 9);
printf("--------------------------------------------------------------------------------------------------------------------");
bookp = bookhead;
if (bookhead == NULL)
{
Toxy(2, 10);
printf("书库暂时没有书哦~赶快去添加几本吧^_^(按任意键返回)\n");
getch();
BookCatalog();
}
for (i = 0; bookp != NULL; bookp = bookp->next, i++) a[i] = bookp;
t = i;
for (i = 0;itype, a[j]->type) > 0)
{
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
j = 0; i = 10;
while (jnumber, a[j]->name, a[j]->author, a[j]->type, a[j]->publish, a[j]->price, a[j]->_amount, a[j]->amount, a[j]->total);
i++;
Toxy(2, i);
printf("--------------------------------------------------------------------------------------------------------------------");
i++;
j++;
}
Toxy(2, i);
i++;
Toxy(2, i);
printf("按任意键返回\n");
getch();
BookCatalog();
}
void BookTotalCatalog() //图书总览-借阅量
{
system("cls");
Color(14);
book bookhead, bookp, a[10000], temp;
int i, j, t;
bookhead = booklist();
Toxy(2, 5);
printf("************************************************图书总览************************************************************");
Toxy(2, 7);
printf("--------------------------------------------------------------------------------------------------------------------");
Toxy(2, 8);
printf("|库存编号|书名 |作者名 |图书类别|出版单位 |图书定价|在库数量| 总数量| 借阅量|");
Toxy(2, 9);
printf("--------------------------------------------------------------------------------------------------------------------");
bookp = bookhead;
if (bookhead == NULL)
{
Toxy(2, 10);
printf("书库暂时没有书哦~赶快去添加几本吧^_^(按任意键返回)\n");
getch();
BookCatalog();
}
for (i = 0; bookp != NULL; bookp = bookp->next, i++) a[i] = bookp;
t = i;
for (i = 0; i < t; i++)
{
j = i + 1;
for (; j < t; j++)
if (a[i]->total> a[j]->total)
{
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
j = 0; i = 10;
while (j < t)
{
Toxy(2, i);
printf("|%8s|%24s|%18s|%8s|%16s|%8.2f|%8d|%8d|%8d|", a[j]->number, a[j]->name, a[j]->author, a[j]->type, a[j]->publish, a[j]->price, a[j]->_amount, a[j]->amount, a[j]->total);
i++;
Toxy(2, i);
printf("--------------------------------------------------------------------------------------------------------------------");
i++;
j++;
}
Toxy(2, i);
i++;
Toxy(2, i);
printf("按任意键返回\n");
getch();
BookCatalog();
}
第三板块
void ReaderRegister() //读者注册
{
system("cls");
Color(10);
reader readerp;
readerp = (reader)malloc(D); //申请空间
//输入注册信息
Toxy(48, 8);
printf("请输入学号(10字符):");
scanf("%s", readerp->readernumber); getchar();
Toxy(48, 10);
printf("请输入姓名(不超过10字符):");
scanf("%s", readerp->readername); getchar();
Toxy(48, 12);
printf("请输入密码(不超过10字符):");
scanf("%s", readerp->password); getchar();
Toxy(48, 14);
printf("请输入手机号(11位字符):");
scanf("%s", readerp->tele); getchar();
if ((strlen(readerp->readernumber) == 10) && (strlen(readerp->readername) < 10) && (strlen(readerp->password) < 10) && (strlen(readerp->tele) == 11))
{
char t;
system("cls");
Color(12);
Toxy(46, 8);
printf("-------------------------------");
Toxy(46, 9);
printf("| |");
Toxy(46, 10);
printf("| 请选择你的性别 |");
Toxy(46, 12);
printf("| 1.男 2.女 |");
Toxy(46, 13);
printf("| |");
Toxy(46, 14);
printf("-------------------------------");
while (1)
{
t = getch();
if (t == '1')
{
strcpy((*readerp).readersex, "男 ");
readerp->s = 1;
readerp->readertotal = 0;
break;
}
else if (t == '2')
{
strcpy((*readerp).readersex, "女 ");
readerp->s = 2;
readerp->readertotal = 0;
break;
}
}
FILE *fd; //文件指针
fd = fopen("reader.txt", "at"); //以追加的方式打开名字为reader的文本文件
if (fd == NULL)
{
printf("无法打开reader文件");
}
if (fwrite(readerp, D, 1, fd) != 1) //将readerp所指向的一段大小为D的内容存入fd所指向的文件中
{
printf("写入错误");
}
fclose(fd); //关闭文件
system("cls");
Toxy(48, 14);
printf("正在保存....");
Sleep(500); //暂停0.5秒
system("cls");
Color(9);
Toxy(46, 8);
printf("-----------------------------");
Toxy(46, 9);
printf("| |");
Toxy(46, 10);
printf("| 注册成功!是否借阅图书? |");
Toxy(46, 12);
printf("| 1.是 2.否 |");
Toxy(46, 13);
printf("| |");
Toxy(46, 14);
printf("-----------------------------");
while (1) //利用死循环可有效防止其他按键干扰
{
t = getch();
if (t == '1')
{
ReaderMenu();
}
else if (t == '2')
{
Menu();
}
}
}
else
{
char t;
system("cls");
Color(12);
Toxy(46, 8);
printf("-------------------------------");
Toxy(46, 9);
printf("| |");
Toxy(46, 10);
printf("| 信息填写错误,是否重新输入 |");
Toxy(46, 12);
printf("| 1.是 2.否 |");
Toxy(46, 13);
printf("| |");
Toxy(46, 14);
printf("-------------------------------");
while (1)
{
t = getch();
if (t == '1')
{
ReaderRegister();
}
else if (t == '2')
{
Menu();
}
}
}
}
void BorrowBooks() //借阅图书
{
system("cls"); //清屏
HideCursor(); //隐藏光标
Color(9); //设置登陆界面颜色为绿色
char name[11], password[11];
char t;
reader readerhead, readerp;
FILE *fd, *fs, *fj; //文件指针
readerhead = readerlist();
readerp = readerhead;
Toxy(48, 8);
printf("请输入你的姓名:");
scanf("%s", &name); getchar();
Toxy(48, 10);
printf("请输入密码:");
scanf("%s", &password); getchar();
if (readerp == NULL)
{
system("cls");
Color(12);
Toxy(46, 8);
printf("----------------------------");
Toxy(46, 9);
printf("| |");
Toxy(46, 10);
printf("| 尚未注册,是否注册 |");
Toxy(46, 12);
printf("| 1.是 2.否 |");
Toxy(46, 13);
printf("| |");
Toxy(46, 14);
printf("-----------------------------");
while (1) //利用死循环可有效防止其他按键干扰
{
t = getch();
if (t == '1')
{
ReaderRegister();
}
else if (t == '2')
{
ReaderMenu();
}
}
}
while (readerp != NULL)
{
if (readerp != NULL && strcmp(readerp->readername, name) == 0)
{
if (readerp != NULL && strcmp(readerp->password, password) == 0)
{
system("cls");
Color(9);
Toxy(48, 10);
printf("登陆成功!!!");
Sleep(1000);
break;
}
else
{
system("cls");
Color(12);
Toxy(46, 8);
printf("----------------------------");
Toxy(46, 9);
printf("| |");
Toxy(46, 10);
printf("| 密码错误,是否重新登陆 |");
Toxy(46, 12);
printf("| 1.是 2.否 |");
Toxy(46, 13);
printf("| |");
Toxy(46, 14);
printf("-----------------------------");
while (1) //利用死循环可有效防止其他按键干扰
{
t = getch();
if (t == '1')
{
BorrowBooks();
}
else if (t == '2')
{
ReaderMenu();
}
}
}
}
else
{
system("cls");
Color(12);
Toxy(46, 8);
printf("----------------------------");
Toxy(46, 9);
printf("| |");
Toxy(46, 10);
printf("| 姓名错误,是否重新登陆 |");
Toxy(46, 12);
printf("| 1.是 2.否 |");
Toxy(46, 13);
printf("| |");
Toxy(46, 14);
printf("-----------------------------");
while (1) //利用死循环可有效防止其他按键干扰
{
t = getch();
if (t == '1')
{
BorrowBooks();
}
else if (t == '2')
{
ReaderMenu();
}
}
}
readerp = readerp->next;
}
//以上为登陆界面
do
{
system("cls");
Color(14);
book bookhead, bookp;
int i = 10, j = 0, n;
char ch, information[25];
bookhead = booklist();
Toxy(48, 8);
printf("请输入您要借阅图书的信息:");
gets(information);
Toxy(48, 9);
printf("正在查询....");
Sleep(500);
bookp = bookhead;
Toxy(2, 5);
printf("************************************************图书总览************************************************************");
Toxy(2, 7);
printf("--------------------------------------------------------------------------------------------------------------------");
Toxy(2, 8);
printf("|库存编号|书名 |作者名 |图书类别|出版单位 |图书定价|在库数量| 总数量| 借阅量|");
Toxy(2, 9);
printf("--------------------------------------------------------------------------------------------------------------------");
while (bookp != NULL)
{
if (bookp != NULL && (strcmp(bookp->name, information) == 0 || strcmp(bookp->author, information) == 0 || strcmp(bookp->number, information) == 0 || strcmp(bookp->publish, information) == 0) || strcmp(bookp->type, information) == 0)
{
Toxy(0, i);
j++;
printf("%d|%8s|%24s|%18s|%8s|%16s|%8.2f|%8d|%8d|%8d|", j, bookp->number, bookp->name, bookp->author, bookp->type, bookp->publish, bookp->price, bookp->_amount, bookp->amount, bookp->total);
bookp->x = j; //给符合查询标准的结点标号
i++;
}
bookp = bookp->next;
}
if (j == 0) //如果j=0,即没有进入前面的搜索循环,也就是没有找到相应的信息
{
Color(12);
Toxy(2, i);
printf("--------------------------------------------------------------------------------------------------------------------");
i++;
Toxy(2, i);
printf("没有找到相应的信息!(按0返回,按1重新搜索)");
while (1) //死循环是为了防止除0和1的其他按键干扰
{
ch = getch();
if (ch == '0')
{
ReaderMenu(); break;
}
else if (ch == '1')
{
break;
}
}
if (ch == '1') //如果输入的ch等于1,则结束本次循环
continue;
}
while (1)
{
Color(14);
Toxy(2, i);
printf("--------------------------------------------------------------------------------------------------------------------");
i++;
Toxy(2, i);
printf("请输入您要借阅的图书所在行数:");
scanf("%d", &n); getchar();
if (n > j || n == 0)
{
Color(12);
Toxy(2, ++i);
printf("输入错误,请重新输入!");
Sleep(500);
}
else
{
break;
}
}
bookp = bookhead; //让p重新指向表头
while (bookp != NULL && bookp->x != n) //遍历链表查询符合条件的结点
{
bookp = bookp->next;
}
if (bookp->_amount == 0)
{
system("cls");
Color(14);
Toxy(48, 10);
printf("暂无该书在库,请借阅其他图书!(按任意键返回)");
Sleep(500);
ReaderMenu();
}
system("cls");
Color(12);
Toxy(48, 8);
printf("-------------------------");
Toxy(48, 9);
printf("| |");
Toxy(48, 10);
printf("| 是否确认借阅? |");
Toxy(48, 12);
printf("| 1.是 2.否 |");
Toxy(48, 13);
printf("| |");
Toxy(48, 14);
printf("-------------------------");
while (1) //利用死循环防止其他按键干扰
{
t = getch();
if (t == '1')
{
break;
}
else if (t == '2')
{
ReaderMenu();
}
}
bookp->_amount = bookp->_amount - 1;
bookp->total = bookp->total + 1;
system("cls");
Toxy(48, 10);
printf("正在借阅,请稍后....");
if (readerp->readertotal > 20)
{
system("cls");
Color(12);
Toxy(48, 10);
printf("借阅失败,已超出最大借阅图书数,正在返回....");
Sleep(500);
break;
}
borrow borrowp;
borrowp = (borrow)malloc(J);
strcpy((*borrowp).borrowamount, readerp->readernumber);
strcpy((*borrowp).borrowname, readerp->readername);
strcpy((*borrowp).borrowsex, readerp->readersex);
strcpy((*borrowp).borrowtele, readerp->tele);
strcpy((*borrowp).booknumber, bookp->number);
strcpy((*borrowp).bookname, bookp->name);
strcpy((*borrowp).bookauthor, bookp->author);
strcpy((*borrowp).booktype, bookp->type);
strcpy((*borrowp).bookpublish, bookp->publish);
fj = fopen("borrow.txt", "at"); //以追加的方式打开名字为repository的文本文件
if (fj == NULL)
{
printf("无法打开borrow文件");
}
if (fwrite(borrowp, J, 1, fj) != 1) //将p所指向的一段大小为J的内容存入fj所指向的文件中
{
printf("写入错误");
}
fclose(fj); //关闭文件
bookp = bookhead; //让p重新指向表头
while (bookp != NULL)
{
bookp->x = 0;
bookp = bookp->next;
}
fs = fopen("repository.txt", "wt"); //以只写的方式打开名为repository的文本文件,打开的同时清空文件中的内容
if (fs == NULL)
{
printf("无法打开repository文件");
}
if (fwrite(bookhead, S, 1, fs) != 1) //将head写入fp所指向的文件中
{
printf("写入错误!");
}
fclose(fs); //关闭文件
if (bookhead != NULL) //如果head不为空
{
bookp = bookhead->next; //让p指向第二个结点
fs = fopen("repository.txt", "at"); //以追加的方式打开文件
if (fs == NULL)
{
printf("无法打开repository文件");
}
while (bookp != NULL)
{
if (fwrite(bookp, S, 1, fs) != 1)//将p写入fp所指向的文件中
{
printf("写入错误!");
}
bookp = bookp->next;
}
fclose(fs); //关闭文件
}
readerp->readertotal = readerp->readertotal + 1;
fd = fopen("reader.txt", "wt"); //以只写的方式打开名为reader的文本文件,打开的同时清空文件中的内容
if (fd == NULL)
{
printf("无法打开reader文件");
}
if (fwrite(readerhead, D, 1, fd) != 1) //将head写入fp所指向的文件中
{
printf("写入错误!");
}
fclose(fd); //关闭文件
if (readerhead != NULL) //如果head不为空
{
readerp = readerhead->next; //让p指向第二个结点
fd = fopen("reader.txt", "at"); //以追加的方式打开文件
if (fd == NULL)
{
printf("无法打开reader文件");
}
while (readerp != NULL)
{
if (fwrite(readerp, D, 1, fd) != 1)//将p写入fp所指向的文件中
{
printf("写入错误!");
}
readerp = readerp->next;
}
fclose(fd); //关闭文件
}
Sleep(500); //暂停0.5秒
system("cls");
Color(9);
Toxy(46, 10);
printf("借阅成功!即将自动返回菜单....");
Sleep(500);
break;
} while (1);
}
void ReturnBooks() //归还图书
{
system("cls");
HideCursor();
Color(9);
char name[11], password[11];
char r;
FILE *fd, *fs, *fj; //文件指针
reader readerhead, readerp;
readerhead = readerlist();
readerp = readerhead;
Toxy(48, 8);
printf("请输入你的姓名:");
scanf("%s", &name); getchar();
Toxy(48, 10);
printf("请输入密码:");
scanf("%s", &password); getchar();
while (readerp != NULL)
{
if (readerp != NULL && strcmp(readerp->readername, name) == 0)
{
if (readerp != NULL && strcmp(readerp->password, password) == 0)
{
system("cls");
Color(9);
Toxy(48, 10);
printf("登陆成功!!!");
Sleep(1000);
break;
}
else
{
system("cls");
Color(12);
Toxy(46, 8);
printf("----------------------------");
Toxy(46, 9);
printf("| |");
Toxy(46, 10);
printf("| 密码错误,是否重新登陆 |");
Toxy(46, 12);
printf("| 1.是 2.否 |");
Toxy(46, 13);
printf("| |");
Toxy(46, 14);
printf("-----------------------------");
while (1) //利用死循环可有效防止其他按键干扰
{
r = getch();
if (r == '1')
{
BorrowBooks();
}
else if (r == '2')
{
ReaderMenu();
}
}
}
}
else
{
system("cls");
Color(12);
Toxy(46, 8);
printf("----------------------------");
Toxy(46, 9);
printf("| |");
Toxy(46, 10);
printf("| 姓名错误,是否重新登陆 |");
Toxy(46, 12);
printf("| 1.是 2.否 |");
Toxy(46, 13);
printf("| |");
Toxy(46, 14);
printf("-----------------------------");
while (1) //利用死循环可有效防止其他按键干扰
{
r = getch();
if (r == '1')
{
BorrowBooks();
}
else if (r == '2')
{
ReaderMenu();
}
}
}
readerp = readerp->next;
}
//以上为登陆界面
do
{
system("cls");
Color(14);
borrow borrowhead, borrowpa;
borrow borrowpb = NULL;
book bookp, bookhead;
int i = 10, j = 0, t = 0, n;
borrowhead = borrowlist();
Toxy(2, 5);
printf("**********************************************借阅信息总览***********************************************************");
Toxy(2, 7);
printf("---------------------------------------------------------------------------------------------------------------------");
Toxy(2, 8);
printf("借阅者编号|借阅者姓名|性别| 电话号码|库存编号| 书名| 作者名|图书类型| 出版社");
Toxy(2, 9);
printf("---------------------------------------------------------------------------------------------------------------------");
borrowpa = borrowhead;
while (borrowpa != NULL)
{
if (strcmp(borrowpa->borrowamount, readerp->readernumber) == 0)
{
j++;
Toxy(0, i);
printf("%d:%10s|%10s|%4s|%11s|%8s|%24s|%18s|%8s|%16s\n", j, borrowpa->borrowamount, borrowpa->borrowname, borrowpa->borrowsex, borrowpa->borrowtele, borrowpa->booknumber, borrowpa->bookname, borrowpa->bookauthor, borrowpa->booktype, borrowpa->bookpublish);
i++;
Toxy(2, i);
printf("----------------------------------------------------------------------------------------------------------------------");
i++;
t++;
borrowpa->z = j;
}
borrowpa = borrowpa->next;
}
if (t == 0)
{
Toxy(2, 10);
printf("你暂时没有借阅图书哦^_^(按任意键返回)\n");
getch();
ReaderMenu();
}
else
{
Toxy(2, i);
printf("你已借出图书:%d本!!!", t);
}
i++;
Toxy(2, i);
printf("----------------------------------------------------------------------------------------------------------------------");
while (1)
{
i++;
Toxy(2, i);
printf("请输入您要归还的图书所在行数:");
scanf("%d", &n); getchar();
if (n > j || n == 0)
{
Color(12);
Toxy(2, ++i);
printf("-------------------------------------------------------------------------------------------------------------------");
Toxy(2, ++i);
printf("输入错误,请重新输入!");
Sleep(500);
}
else
{
break;
}
}
borrowpa = borrowhead; //让p重新指向表头
while (borrowpa != NULL && borrowpa->z != n) //遍历链表查询符合条件的结点
{
borrowpb = borrowpa;
borrowpa = borrowpa->next;
}
bookhead = booklist();
bookp = bookhead;
while (bookp != NULL)
{
if (strcmp(bookp->number, borrowpa->booknumber) == 0)
{
bookp->_amount = bookp->_amount + 1;
}
bookp = bookp->next;
}
if (borrowpa != NULL)
{
if (borrowpb == NULL)
{
borrowhead = borrowhead->next;
}
else
{
borrowpb->next = borrowpa->next;
}
}
free(borrowpa);
Color(12);
Toxy(46, 8);
printf("-------------------------");
Toxy(46, 9);
printf("| |");
Toxy(46, 10);
printf("| 是否确认归还? |");
Toxy(46, 12);
printf("| 1.是 2.否 |");
Toxy(46, 13);
printf("| |");
Toxy(46, 14);
printf("-------------------------");
while (1)
{
t = getch();
if (t == '1')
{
break;
}
else if (t == '2')
{
ReaderMenu();
}
}
system("cls");
Color(9);
Toxy(46, 10);
printf("正在归还,请稍后....");
borrowpa = borrowhead; //让p重新指向表头
while (borrowpa != NULL)
{
borrowpa->z = 0;
borrowpa = borrowpa->next;
}
fj = fopen("borrow.txt", "wt"); //以只写的方式打开名为borrow的文本文件,打开的同时清空文件中的内容
if (borrowhead != NULL)
{
if (fj == NULL)
{
printf("无法打开borrow文件");
}
if (fwrite(borrowhead, J, 1, fj) != 1) //将head写入fp所指向的文件中
{
printf("写入错误!");
}
}
fclose(fj); //关闭文件
if (borrowhead != NULL) //如果head不为空
{
borrowpa = borrowhead->next; //让p指向第二个结点
fj = fopen("borrow.txt", "at"); //以追加的方式打开文件
if (fj == NULL)
{
printf("无法打开borrow文件");
}
while (borrowpa != NULL)
{
if (fwrite(borrowpa, J, 1, fj) != 1)//将p写入fp所指向的文件中
{
printf("写入错误!");
}
borrowpa = borrowpa->next;
}
fclose(fj); //关闭文件
}
fs = fopen("repository.txt", "wt"); //以只写的方式打开名为repository的文本文件,打开的同时清空文件中的内容
if (fs == NULL)
{
printf("无法打开repository文件");
}
if (fwrite(bookhead, S, 1, fs) != 1) //将head写入fp所指向的文件中
{
printf("写入错误!");
}
fclose(fs); //关闭文件
if (bookhead != NULL) //如果head不为空
{
bookp = bookhead->next; //让p指向第二个结点
fs = fopen("repository.txt", "at"); //以追加的方式打开文件
if (fs == NULL)
{
printf("无法打开repository文件");
}
while (bookp != NULL)
{
if (fwrite(bookp, S, 1, fs) != 1)//将p写入fp所指向的文件中
{
printf("写入错误!");
}
bookp = bookp->next;
}
fclose(fs); //关闭文件
}
readerp->readertotal = readerp->readertotal - 1;
fd = fopen("reader.txt", "wt"); //以只写的方式打开名为reader的文本文件,打开的同时清空文件中的内容
if (fd == NULL)
{
printf("无法打开reader文件");
}
if (fwrite(readerhead, D, 1, fd) != 1) //将head写入fp所指向的文件中
{
printf("写入错误!");
}
fclose(fd); //关闭文件
if (readerhead != NULL) //如果head不为空
{
readerp = readerhead->next; //让p指向第二个结点
fd = fopen("reader.txt", "at"); //以追加的方式打开文件
if (fd == NULL)
{
printf("无法打开reader文件");
}
while (readerp != NULL)
{
if (fwrite(readerp, D, 1, fd) != 1)//将p写入fp所指向的文件中
{
printf("写入错误!");
}
readerp = readerp->next;
}
fclose(fd); //关闭文件
}
Sleep(500); //暂停0.5秒
system("cls");
Toxy(46, 10);
printf("借阅成功!即将自动返回菜单....");
Sleep(500);
break;
} while (1);
}
第四板块
void EnterRepository() //图书入库
{
do
{
system("cls");
Color(10);
char t;
book bookp;
bookp = (book)malloc(S); //申请空间
//输入图书信息
Toxy(48, 8);
printf("请输入图书库存编号(8位库存编号):");
scanf("%s", bookp->number); getchar();
Toxy(48, 10);
printf("请输入书名(不超过24个字符):");
scanf("%s", bookp->name); getchar();
Toxy(48, 12);
printf("请输入作者名(不超过18个字符):");
scanf("%s", bookp->author); getchar();
Toxy(48, 14);
printf("请输入图书类别(不超过8个字符):");
scanf("%s", bookp->type); getchar();
Toxy(48, 16);
printf("请输入图书出版单位(不超过16个字符):");
scanf("%s", bookp->publish); getchar();
Toxy(48, 18);
printf("请输入图书价格(可保留两位小数):");
scanf("%f", &bookp->price); getchar();
Toxy(48, 20);
printf("请输入在库数量:");
scanf("%d", &bookp->_amount); getchar();
Toxy(48, 22);
printf("请输入图书总数量:");
scanf("%d", &bookp->amount);
if (strlen(bookp->number) != 8 || strlen(bookp->name) > 24 || strlen(bookp->author) > 18 || strlen(bookp->type) > 8 || strlen(bookp->publish) > 16 || bookp->_amount > bookp->amount)
{
system("cls");
Color(12);
Toxy(46, 8);
printf("---------------------------------");
Toxy(46, 9);
printf("| |");
Toxy(46, 10);
printf("| 信息填写错误!是否重新填写? |");
Toxy(46, 12);
printf("| 1.是 2.否 |");
Toxy(46, 13);
printf("| |");
Toxy(46, 14);
printf("---------------------------------");
while (1) //利用死循环可有效防止其他按键干扰
{
t = getch();
if (t == '1')
{
EnterRepository();
}
else if (t == '2')
{
AdministratorMenu();
}
}
}
bookp->total = 0;
FILE *fs; //文件指针
fs = fopen("repository.txt", "at"); //以追加的方式打开名字为repository的文本文件
if (fs == NULL)
{
printf("无法打开repository文件");
}
if (fwrite(bookp, S, 1, fs) != 1) //将p所指向的一段大小为N的内容存入fp所指向的文件中
{
printf("写入错误");
}
fclose(fs); //关闭文件
Toxy(48, 24);
printf("正在保存....");
Sleep(500); //暂停0.5秒
system("cls");
Color(9);
Toxy(46, 8);
printf("-------------------------");
Toxy(46, 9);
printf("| |");
Toxy(46, 10);
printf("| 保存成功!是否继续? |");
Toxy(46, 12);
printf("| 1.是 2.否 |");
Toxy(46, 13);
printf("| |");
Toxy(46, 14);
printf("-------------------------");
while (1) //利用死循环可有效防止其他按键干扰
{
t = getch();
if (t == '1')
{
break;
}
else if (t == '2')
{
AdministratorMenu();
}
}
} while (1);
}
void ChangeRepository() //修改图书库存信息
{
do
{
system("cls");
Color(10);
book bookhead, bookp;
int i = 10, j = 0, n;
char ch, t;
FILE *fs; //文件指针
char _name[31];
bookhead = booklist();
Toxy(48, 10);
printf("请输入你要修改的图书的书名:");
scanf("%s", _name);
bookp = bookhead;
system("cls");
Color(14);
Toxy(2, 5);
printf("************************************************图书总览************************************************************");
Toxy(2, 7);
printf("--------------------------------------------------------------------------------------------------------------------");
Toxy(2, 8);
printf("|库存编号|书名 |作者名 |图书类别|出版单位 |图书定价|在库数量| 总数量| 借阅量|");
Toxy(2, 9);
printf("--------------------------------------------------------------------------------------------------------------------");
while (bookp != NULL)
{
if (bookp != NULL && strcmp(bookp->name, _name) == 0)
{
Toxy(0, i);
j++;
printf("%d|%8s|%24s|%18s|%8s|%16s|%8.2f|%8d|%8d|%8d|", j, bookp->number, bookp->name, bookp->author, bookp->type, bookp->publish, bookp->price, bookp->_amount, bookp->amount, bookp->total);
bookp->x = j; //给符合查询标准的结点标号
i++;
}
bookp = bookp->next;
}
if (j == 0) //如果j=0,即没有进入前面的搜索循环,也就是没有找到相应的信息
{
Color(12);
Toxy(2, i);
printf("--------------------------------------------------------------------------------------------------------------------");
i++;
Toxy(2, i);
printf("没有找到相应的信息!(按0返回,按1重新搜索)");
while (1) //死循环是为了防止除0和1的其他按键干扰
{
ch = getch();
if (ch == '0')
{
AdministratorMenu(); break;
}
else if (ch == '1')
{
break;
}
}
if (ch == '1') //如果输入的ch等于1,则结束本次循环
continue;
}
while (1)
{
Color(12);
Toxy(2, i);
printf("--------------------------------------------------------------------------------------------------------------------");
i++;
Toxy(2, i);
printf("请输入您要修改的图书所在行数:");
scanf("%d", &n); getchar();
if (n > j || n == 0)
{
Toxy(2, ++i);
printf("输入错误,请重新输入!");
Sleep(500);
}
else
{
break;
}
}
bookp = bookhead; //让p重新指向表头
while (bookp != NULL && bookp->x != n) //遍历链表查询符合条件的结点
{
bookp = bookp->next;
}
if (bookp) //如果p不为空
{
//输入要修改的信息
system("cls"); //清屏
HideCursor(); //隐藏光标
Color(15); //设置菜单颜色为亮白色
char t;
Toxy(54, 5); //将光标移动到(50,5)坐标处
printf("lime图书查询管理系统");
Toxy(48, 8);
printf("| 1.修改图书库存编号 |");
Toxy(48, 10);
printf("| 2.修改图书名称 |");
Toxy(48, 12);
printf("| 3.修改作者名字 |");
Toxy(48, 14);
printf("| 4.修改图书类别 |");
Toxy(48, 16);
printf("| 5.修改图书出版单位 |");
Toxy(48, 18);
printf("| 6.修改图书价格 |");
Toxy(48, 20);
printf("| 7.修改图书数量 |");
Toxy(48, 22);
printf("| 0.返回菜单 |");
t = getch(); //不回显函数
switch (t)
{
case '1':
{
system("cls"); //清屏
HideCursor(); //隐藏光标
Color(10); //设置颜色为亮白色
Toxy(48, 12);
printf("请输入图书库存编号(8位库存编号):");
scanf("%s", bookp->number); getchar();
if (strlen(bookp->number) != 8)
{
system("cls");
Color(12);
Toxy(46, 14);
printf("信息填写错误!请重新修改");
ChangeRepository();
}
};
break;
case '2':
{
system("cls"); //清屏
HideCursor(); //隐藏光标
Color(10); //设置颜色为亮白色
Toxy(48, 12);
printf("请输入书名(不超过24个字符):");
scanf("%s", bookp->name); getchar();
if (strlen(bookp->name) > 24)
{
system("cls");
Color(12);
Toxy(46, 14);
printf("信息填写错误!请重新修改");
ChangeRepository();
}
};
break;
case '3':
{
system("cls"); //清屏
HideCursor(); //隐藏光标
Color(10); //设置颜色为亮白色
Toxy(48, 12);
printf("请输入作者名(不超过18个字符):");
scanf("%s", bookp->author); getchar();
if (strlen(bookp->author) > 18)
{
system("cls");
Color(12);
Toxy(46, 14);
printf("信息填写错误!请重新修改");
ChangeRepository();
}
};
break;
case '4':
{
system("cls"); //清屏
HideCursor(); //隐藏光标
Color(10); //设置颜色为亮白色
Toxy(48, 12);
printf("请输入图书类别(不超过8个字符):");
scanf("%s", bookp->type); getchar();
if (strlen(bookp->type) > 8)
{
system("cls");
Color(12);
Toxy(46, 14);
printf("信息填写错误!请重新修改");
ChangeRepository();
}
};
break;
case '5':
{
system("cls"); //清屏
HideCursor(); //隐藏光标
Color(10); //设置颜色为亮白色
Toxy(48, 12);
printf("请输入图书出版单位(不超过16个字符):");
scanf("%s", bookp->publish); getchar();
if (strlen(bookp->publish) > 16)
{
system("cls");
Color(12);
Toxy(46, 14);
printf("信息填写错误!请重新修改");
ChangeRepository();
}
};
break;
case '6':
{
system("cls"); //清屏
HideCursor(); //隐藏光标
Color(10); //设置颜色为亮白色
Toxy(48, 12);
printf("请输入图书价格(可保留两位小数):");
scanf("%f", &bookp->price); getchar();
};
break;
case '7':
{
system("cls"); //清屏
HideCursor(); //隐藏光标
Color(10); //设置颜色为亮白色
Toxy(48, 12);
printf("请输入在库数量:");
scanf("%d", &bookp->_amount); getchar();
Toxy(48, 14);
printf("请输入图书总数量:");
scanf("%d", &bookp->amount);
if (strlen(bookp->publish) > 16 || bookp->_amount > bookp->amount)
{
system("cls");
Color(12);
Toxy(46, 10);
printf("信息填写错误!请重新修改");
ChangeRepository();
}
};
break;
case '0':AdministratorMenu(); break;
default:AdministratorMenu(); break;
}
}
system("cls");
Color(12);
Toxy(48, 8);
printf("-------------------------");
Toxy(48, 9);
printf("| |");
Toxy(48, 10);
printf("| 是否确认修改? |");
Toxy(48, 12);
printf("| 1.是 2.否 |");
Toxy(48, 13);
printf("| |");
Toxy(48, 14);
printf("-------------------------");
while (1) //利用死循环防止其他按键干扰
{
t = getch();
if (t == '1')
{
break;
}
else if (t == '2')
{
AdministratorMenu();
}
}
system("cls");
Toxy(48, 10);
printf("正在修改,请稍后....");
bookp = bookhead; //让p重新指向表头
while (bookp != NULL)
{
bookp->x = 0;
bookp = bookp->next;
}
fs = fopen("repository.txt", "wt"); //以只写的方式打开名为repository的文本文件,打开的同时清空文件中的内容
if (fs == NULL)
{
printf("无法打开repository文件");
}
if (fwrite(bookhead, S, 1, fs) != 1) //将head写入fp所指向的文件中
{
printf("写入错误!");
}
fclose(fs); //关闭文件
if (bookhead != NULL) //如果head不为空
{
bookp = bookhead->next; //让p指向第二个结点
fs = fopen("repository.txt", "at"); //以追加的方式打开文件
if (fs == NULL)
{
printf("无法打开repository文件");
}
while (bookp != NULL)
{
if (fwrite(bookp, S, 1, fs) != 1)//将p写入fp所指向的文件中
{
printf("写入错误!");
}
bookp = bookp->next;
}
fclose(fs); //关闭文件
}
Sleep(500); //暂停0.5秒
system("cls");
Toxy(46, 10);
printf("修改成功!即将自动返回主菜单....");
Sleep(500);
break;
} while (1);
}
void DeleteRepository() //删除图书库存信息
{
do
{
system("cls");
Color(10);
FILE *fs, *rfs;
book bookhead, bookpa;
book bookpb = NULL;
int n, h = 0, i = 10;
char name[10];
char t, c, ch;
bookhead = booklist(); //调用函数,返回表头地址
Toxy(48, 9);
printf("请输入你要删除的图书的书名:");
scanf("%s", name);
bookpa = bookhead;
Color(14);
Toxy(2, 5);
printf("************************************************图书总览************************************************************");
Toxy(2, 7);
printf("--------------------------------------------------------------------------------------------------------------------");
Toxy(2, 8);
printf("|库存编号|书名 |作者名 |图书类别|出版单位 |图书定价|在库数量| 总数量| 借阅量|");
Toxy(2, 9);
printf("--------------------------------------------------------------------------------------------------------------------");
while (bookpa != NULL)
{
if (bookpa != NULL && strcmp(bookpa->name, name) == 0)
{
Toxy(0, i);
h++;
printf("%d:|%8s|%24s|%18s|%8s|%16s|%8.2f|%8d|%8d|%8d|", h, bookpa->number, bookpa->name, bookpa->author, bookpa->type, bookpa->publish, bookpa->price, bookpa->_amount, bookpa->amount, bookpa->total);
i++;
Toxy(2, i);
printf("--------------------------------------------------------------------------------------------------------------------");
bookpa->x = h;
i++;
}
bookpa = bookpa->next;
}
if (h == 0) //如果j=0,即没有进入前面的搜索循环,也就是没有找到相应的信息
{
Color(12);
Toxy(2, i);
printf("--------------------------------------------------------------------------------------------------------------------");
i++;
Toxy(2, i);
printf("没有找到相应的信息!(按0返回,按1重新搜索)");
while (1) //死循环是为了防止除0和1的其他按键干扰
{
ch = getch();
if (ch == '0')
{
AdministratorMenu(); break;
}
else if (ch == '1')
{
break;
}
}
if (ch == '1') //如果输入的ch等于1,则结束本次循环
continue;
}
while (1)
{
Toxy(2, i);
printf("请输入您要删除的图书所在行数:");
scanf("%d", &n); getchar();
if (n > h || n == 0)
{
Color(12);
Toxy(2, ++i);
printf("-------------------------------------------------------------------------------------------------------------------");
Toxy(2, ++i);
printf("输入错误,请重新输入!");
Sleep(500);
}
else
{
break;
}
}
bookpa = bookhead; //让p重新指向表头
while (bookpa != NULL && bookpa->x != n) //遍历链表查询符合条件的结点
{
bookpb = bookpa;
bookpa = bookpa->next;
}
if (bookpa != NULL)
{
if (bookpb == NULL)
{
bookhead = bookhead->next;
}
else
{
bookpb->next = bookpa->next;
}
}
free(bookpa);
Color(12);
Toxy(46, 8);
printf("-------------------------");
Toxy(46, 9);
printf("| |");
Toxy(46, 10);
printf("| 是否确认删除? |");
Toxy(46, 12);
printf("| 1.是 2.否 |");
Toxy(46, 13);
printf("| |");
Toxy(46, 14);
printf("-------------------------");
while (1)
{
t = getch();
if (t == '1')
{
break;
}
else if (t == '2')
{
AdministratorMenu();
}
}
system("cls");
Toxy(46, 10);
printf("正在删除,请稍后....");
bookpa = bookhead; //让p重新指向表头
while (bookpa != NULL)
{
bookpa->x = 0;
bookpa = bookpa->next;
}
fs = fopen("repository.txt", "wt"); //以只写的方式打开名为repository的文本文件,打开的同时清空文件中的内容
if (bookhead != NULL)
{
if (fs == NULL)
{
printf("无法打开repository文件");
}
if (fwrite(bookhead, S, 1, fs) != 1) //将head写入fp所指向的文件中
{
printf("写入错误!");
}
}
fclose(fs); //关闭文件
if (bookhead != NULL) //如果head不为空
{
bookpa = bookhead->next; //让p指向第二个结点
fs = fopen("repository.txt", "at"); //以追加的方式打开文件
if (fs == NULL)
{
printf("无法打开repository文件");
}
while (bookpa != NULL)
{
if (fwrite(bookpa, S, 1, fs) != 1)//将p写入fp所指向的文件中
{
printf("写入错误!");
}
bookpa = bookpa->next;
}
fclose(fs); //关闭文件
}
Sleep(500);
system("cls");
Color(12);
Toxy(46, 8);
printf("-------------------------");
Toxy(46, 9);
printf("| |");
Toxy(46, 10);
printf("| 删除成功,是否继续? |");
Toxy(46, 12);
printf("| 1.是 2.否 |");
Toxy(46, 13);
printf("| |");
Toxy(46, 14);
printf("-------------------------");
while (1)
{
c = getch();
if (c == '1')
{
break;
}
else if (c == '2')
{
AdministratorMenu();
}
}
} while (1);
}
void ReorderRepository() //存书信息排序
{
do
{
system("cls");
Color(14);
book bookhead, bookpa;
int i = 10;
int h = 0, n, j;
char t;
FILE *fs;
book bookpb = NULL, bookpc = NULL;
bookhead = booklist();
Toxy(2, 5);
printf("************************************************图书总览************************************************************");
Toxy(2, 7);
printf("--------------------------------------------------------------------------------------------------------------------");
Toxy(2, 8);
printf("|库存编号|书名 |作者名 |图书类别|出版单位 |图书定价|在库数量| 总数量| 借阅量|");
Toxy(2, 9);
printf("--------------------------------------------------------------------------------------------------------------------");
bookpa = bookhead;
if (bookhead == NULL)
{
Toxy(2, 10);
printf("书库暂时没有书哦~赶快去添加几本吧^_^(按任意键返回)\n");
getch();
AdministratorMenu();
}
while (bookpa != NULL)
{
h++;
Toxy(0, i);
printf("%d:|%8s|%24s|%18s|%8s|%16s|%8.2f|%8d|%8d|%8d|", h, bookpa->number, bookpa->name, bookpa->author, bookpa->type, bookpa->publish, bookpa->price, bookpa->_amount, bookpa->amount, bookpa->total);
i++;
Toxy(2, i);
printf("--------------------------------------------------------------------------------------------------------------------");
i++;
bookpa = bookpa->next;
}
while (1)
{
if (h == 1)
{
Toxy(2, i);
printf("暂时不需要修改图书次序哦~赶快去添加几本吧^_^(按任意键返回)\n");
getch();
AdministratorMenu();
}
Toxy(2, i);
printf("请输入您要修改的图书所在行数(输入0返回):");
scanf("%d", &n);
i++;
if (n < 0)
{
system("cls");
Color(12);
Toxy(2, i);
printf("输入错误,请重新输入.....");
ReorderRepository();
}
if (n == 0)
{
AdministratorMenu();
}
break;
}
bookpa = bookhead;
Toxy(2, i);
printf("上移请按1,下移请按2,返回请按0:");
i++;
t = getch(); //不回显函数
switch (t)
{
case '1':
{
if (n == 1)
{
system("cls");
Color(12);
Toxy(48, 10);
printf("移动错误,移动距离超出允许距离......");
Sleep(1000);
ReorderRepository();
}
else if (n == 2)
{
bookhead = bookpa->next;
bookpb = bookhead->next;
bookhead->next = bookpa;
bookpa->next = bookpb;
}
else
{
for (j = 0; j < (n - 2); j++)
{
bookpb = bookpa;
bookpa = bookpb->next;
bookpc = bookpa->next;
}
bookpa->next = bookpc->next;
bookpc->next = bookpa;
bookpb->next = bookpc;
}
fs = fopen("repository.txt", "wt");
if (fs == NULL)
{
printf("无法打开repository文件");
}
if (fwrite(bookhead, S, 1, fs) != 1)
{
printf("写入错误!");
}
fclose(fs);
if (bookhead != NULL)
{
bookpa = bookhead->next;
fs = fopen("repository.txt", "at");
if (fs == NULL)
{
printf("无法打开repository文件");
}
while (bookpa != NULL)
{
if (fwrite(bookpa, S, 1, fs) != 1)
{
printf("写入错误!");
}
bookpa = bookpa->next;
}
fclose(fs);
}
system("cls");
Color(12);
Toxy(46, 8);
printf("-------------------------");
Toxy(46, 9);
printf("| |");
Toxy(46, 10);
printf("| 修改成功,是否继续? |");
Toxy(46, 12);
printf("| 1.是 2.否 |");
Toxy(46, 13);
printf("| |");
Toxy(46, 14);
printf("-------------------------");
char c;
while (1)
{
c = getch();
if (c == '1')
{
ReorderRepository();
}
else if (c == '2')
{
AdministratorMenu();
}
}
}; break;
case '2':
{
if (n == h)
{
system("cls");
Color(12);
Toxy(48, 10);
printf("移动错误,移动距离超出允许距离......");
Sleep(1000);
ReorderRepository();
}
else if (n == 1)
{
bookpb = bookhead->next;
bookhead = bookpb;
bookpa->next = bookpb->next;
bookhead->next = bookpa;
}
else
{
for (j = 0; j < (n - 1); j++)
{
bookpb = bookpa;
bookpa = bookpb->next;
bookpc = bookpa->next;
}
bookpa->next = bookpc->next;
bookpc->next = bookpa;
bookpb->next = bookpc;
}
fs = fopen("repository.txt", "wt");
if (fs == NULL)
{
printf("无法打开repository文件");
}
if (fwrite(bookhead, S, 1, fs) != 1)
{
printf("写入错误!");
}
fclose(fs);
if (bookhead != NULL)
{
bookpa = bookhead->next;
fs = fopen("repository.txt", "at");
if (fs == NULL)
{
printf("无法打开repository文件");
}
while (bookpa != NULL)
{
if (fwrite(bookpa, S, 1, fs) != 1)
{
printf("写入错误!");
}
bookpa = bookpa->next;
}
fclose(fs);
}
system("cls");
Color(12);
Toxy(46, 8);
printf("-------------------------");
Toxy(46, 9);
printf("| |");
Toxy(46, 10);
printf("| 修改成功,是否继续? |");
Toxy(46, 12);
printf("| 1.是 2.否 |");
Toxy(46, 13);
printf("| |");
Toxy(46, 14);
printf("-------------------------");
char c;
while (1)
{
c = getch();
if (c == '1')
{
ReorderRepository();
}
else if (c == '2')
{
AdministratorMenu();
}
}
}; break;
case '0':AdministratorMenu(); break;
default:break;
}
} while (1);
}
void ChangeReaderInformation() //修改读者信息
{
do
{
system("cls");
Color(10);
reader readerhead, readerp;
int i = 10, h = 0, n;
char ch, t;
FILE *fd; //文件指针
char _name[11];
readerhead = readerlist();
Toxy(48, 10);
printf("请输入你要修改的读者的姓名:");
scanf("%s", _name);
Color(14);
Toxy(2, 5);
printf("*********************************************读者信息总览********************************************************");
Toxy(2, 7);
printf("-----------------------------------------------------------------------------------------------------------------");
Toxy(2, 8);
printf("| 编号| 姓名| 性别| 联系电话| 密码| 已借阅图书数|");
Toxy(2, 9);
printf("-----------------------------------------------------------------------------------------------------------------");
readerp = readerhead;
while (readerp != NULL)
{
if (readerp != NULL && strcmp(readerp->readername, _name) == 0)
{
h++;
Toxy(0, i);
printf("%d:|%18s|%16s|%12s|%20s|%18s|%20d|\n", h, readerp->readernumber, readerp->readername, readerp->readersex, readerp->tele, readerp->password, readerp->readertotal);
i++;
Toxy(2, i);
printf("-----------------------------------------------------------------------------------------------------------------");
readerp->y = h;
i++;
}
readerp = readerp->next;
}
if (h == 0) //如果 h=0,即没有进入前面的搜索循环,也就是没有找到相应的信息
{
Color(12);
Toxy(2, i);
printf("-------------------------------------------------------------------------------------------------------------------");
i++;
Toxy(2, i);
printf("没有找到相应的信息!(按0返回,按1重新搜索)");
while (1) //死循环是为了防止除0和1的其他按键干扰
{
ch = getch();
if (ch == '0')
{
ReaderInformation(); break;
}
else if (ch == '1')
{
break;
}
}
if (ch == '1') //如果输入的ch等于1,则结束本次循环
continue;
}
while (1)
{
Color(12);
Toxy(2, i);
printf("-------------------------------------------------------------------------------------------------------------------");
i++;
Toxy(2, i);
printf("请输入您要修改的读者信息所在行数:");
scanf("%d", &n); getchar();
if (n > h || n == 0)
{
Toxy(2, ++i);
printf("输入错误,请重新输入!");
Sleep(500);
}
else
{
break;
}
}
readerp = readerhead; //让p重新指向表头
while (readerp != NULL && readerp->y != n) //遍历链表查询符合条件的结点
{
readerp = readerp->next;
}
if (readerp) //如果p不为空
{
//输入要修改的信息
system("cls"); //清屏
HideCursor(); //隐藏光标
Color(15); //设置菜单颜色为亮白色
char t;
Toxy(54, 5); //将光标移动到(50,5)坐标处
printf("lime图书查询管理系统");
Toxy(48, 8);
printf("| 1.修改读者学号 |");
Toxy(48, 10);
printf("| 2.修改读者姓名 |");
Toxy(48, 12);
printf("| 3.修改读者性别 |");
Toxy(48, 14);
printf("| 4.修改读者密码 |");
Toxy(48, 16);
printf("| 5.修改读者联系方式 |");
Toxy(48, 18);
printf("| 6.修改读者已借图书数 |");
Toxy(48, 20);
printf("| 0.返回菜单 |");
t = getch(); //不回显函数
switch (t)
{
case '1':
{
system("cls"); //清屏
HideCursor(); //隐藏光标
Color(10); //设置颜色为亮白色
Toxy(48, 12);
printf("请输入学号(10字符):");
scanf("%s", readerp->readername); getchar();
if (strlen(readerp->readername) != 10)
{
system("cls");
Color(12);
Toxy(46, 14);
printf("信息填写错误!请重新修改");
ChangeReaderInformation();
}
};
break;
case '2':
{
system("cls"); //清屏
HideCursor(); //隐藏光标
Color(10); //设置颜色为亮白色
Toxy(48, 12);
printf("请输入姓名(不超过10字符):");
scanf("%s", readerp->readername); getchar();
if (strlen(readerp->readername) > 10)
{
system("cls");
Color(12);
Toxy(46, 14);
printf("信息填写错误!请重新修改");
ChangeReaderInformation();
}
};
break;
case '3':
{
system("cls"); //清屏
HideCursor(); //隐藏光标
Color(9); //设置颜色为亮白色
Toxy(46, 8);
printf("-------------------------------");
Toxy(46, 9);
printf("| |");
Toxy(46, 10);
printf("| 请选择你的性别 |");
Toxy(46, 12);
printf("| 1.男 2.女 |");
Toxy(46, 13);
printf("| |");
Toxy(46, 14);
printf("-------------------------------");
while (1)
{
t = getch();
if (t == '1')
{
strcpy((*readerp).readersex, "男 ");
readerp->s = 1;
break;
}
else if (t == '2')
{
strcpy((*readerp).readersex, "女 ");
readerp->s = 2;
break;
}
}
};
break;
case '4':
{
system("cls"); //清屏
HideCursor(); //隐藏光标
Color(10); //设置颜色为亮白色
Toxy(48, 12);
printf("请输入密码(不超过10字符):");
scanf("%s", readerp->password); getchar();
if (strlen(readerp->password) > 10)
{
system("cls");
Color(12);
Toxy(46, 14);
printf("信息填写错误!请重新修改");
ChangeReaderInformation();
}
};
break;
case '5':
{
system("cls"); //清屏
HideCursor(); //隐藏光标
Color(10); //设置颜色为亮白色
Toxy(48, 12);
printf("请输入手机号(11位字符):");
scanf("%s", readerp->tele); getchar();
if (strlen(readerp->tele) == 11)
{
system("cls");
Color(12);
Toxy(46, 14);
printf("信息填写错误!请重新修改");
ChangeReaderInformation();
}
};
break;
case '6':
{
system("cls");
HideCursor();
Color(10);
Toxy(48, 12);
printf("请输入已借阅图书数:");
scanf("%d", &readerp->readertotal); getchar();
};
break;
case '0':ChangeReaderInformation(); break;
default:ChangeReaderInformation(); break;
}
}
system("cls");
Color(12);
Toxy(48, 8);
printf("-------------------------");
Toxy(48, 9);
printf("| |");
Toxy(48, 10);
printf("| 是否确认修改? |");
Toxy(48, 12);
printf("| 1.是 2.否 |");
Toxy(48, 13);
printf("| |");
Toxy(48, 14);
printf("-------------------------");
while (1) //利用死循环防止其他按键干扰
{
t = getch();
if (t == '1')
{
break;
}
else if (t == '2')
{
ReaderInformation();
}
}
system("cls");
Toxy(48, 10);
printf("正在修改,请稍后....");
readerp = readerhead; //让p重新指向表头
while (readerp != NULL)
{
readerp->y = 0;
readerp = readerp->next;
}
fd = fopen("reader.txt", "wt"); //以只写的方式打开名为reader的文本文件,打开的同时清空文件中的内容
if (fd == NULL)
{
printf("无法打开reader文件");
}
if (fwrite(readerhead, D, 1, fd) != 1) //将head写入fp所指向的文件中
{
printf("写入错误!");
}
fclose(fd); //关闭文件
if (readerhead != NULL) //如果head不为空
{
readerp = readerhead->next; //让p指向第二个结点
fd = fopen("reader.txt", "at"); //以追加的方式打开文件
if (fd == NULL)
{
printf("无法打开reader文件");
}
while (readerp != NULL)
{
if (fwrite(readerp, D, 1, fd) != 1)//将p写入fp所指向的文件中
{
printf("写入错误!");
}
readerp = readerp->next;
}
fclose(fd); //关闭文件
}
Sleep(500); //暂停0.5秒
system("cls");
Toxy(46, 10);
printf("修改成功!即将自动返回主菜单....");
Sleep(500);
break;
} while (1);
}
void DeleteReaderInformation() //删除读者信息
{
do
{
system("cls");
Color(14);
FILE *fd;
reader readerhead, readerpa;
reader readerpb = NULL;
int h = 0, n, i = 10;
char name[10];
char t, c, ch;
Toxy(48, 9);
printf("请输入你要删除的读者的姓名:");
scanf("%s", name);
readerhead = readerlist(); //调用函数,返回表头地址
Toxy(2, 5);
printf("*********************************************读者信息总览********************************************************");
Toxy(2, 7);
printf("-----------------------------------------------------------------------------------------------------------------");
Toxy(2, 8);
printf("| 编号| 姓名| 性别| 联系电话| 密码| 已借阅图书数|");
Toxy(2, 9);
printf("-----------------------------------------------------------------------------------------------------------------");
readerpa = readerhead;
while (readerpa != NULL)
{
if (readerpa != NULL && strcmp(readerpa->readername, name) == 0)
{
h++;
Toxy(0, i);
printf("%d:|%18s|%16s|%12s|%20s|%18s|%20d|\n", h, readerpa->readernumber, readerpa->readername, readerpa->readersex, readerpa->tele, readerpa->password, readerpa->readertotal);
i++;
Toxy(2, i);
printf("-----------------------------------------------------------------------------------------------------------------");
readerpa->y = h;
i++;
}
readerpa = readerpa->next;
}
if (h == 0) //如果j=0,即没有进入前面的搜索循环,也就是没有找到相应的信息
{
Color(12);
Toxy(2, i);
printf("-----------------------------------------------------------------------------------------------------------------");
i++;
Toxy(2, i);
printf("没有找到相应的信息!(按0返回,按1重新搜索)");
while (1) //死循环是为了防止除0和1的其他按键干扰
{
ch = getch();
if (ch == '0')
{
ReaderInformation(); break;
}
else if (ch == '1')
{
break;
}
}
if (ch == '1') //如果输入的ch等于1,则结束本次循环
continue;
}
while (1)
{
Toxy(2, i);
printf("请输入您要删除的图书所在行数:");
scanf("%d", &n); getchar();
if (n > h || n == 0)
{
Toxy(2, ++i);
printf("-----------------------------------------------------------------------------------------------------------------");
Toxy(2, ++i);
printf("输入错误,请重新输入!");
Sleep(500);
}
else
{
break;
}
}
system("cls");
Color(12);
Toxy(46, 8);
printf("-------------------------");
Toxy(46, 9);
printf("| |");
Toxy(46, 10);
printf("| 是否确认删除? |");
Toxy(46, 12);
printf("| 1.是 2.否 |");
Toxy(46, 13);
printf("| |");
Toxy(46, 14);
printf("-------------------------");
while (1)
{
t = getch();
if (t == '1')
{
break;
}
else if (t == '2')
{
ReaderInformation();
}
}
readerpa = readerhead;
while (readerpa != NULL && readerpa->y != n)
{
readerpb = readerpa;
readerpa = readerpa->next;
}
if (readerpa != NULL)
{
if (readerpb == NULL)
{
readerhead = readerhead->next;
}
else
{
readerpb->next = readerpa->next;
}
}
free(readerpa);
system("cls");
Color(9);
Toxy(46, 10);
printf("正在删除,请稍后....");
readerpa = readerhead; //让p重新指向表头
while (readerpa != NULL)
{
readerpa->y = 0;
readerpa = readerpa->next;
}
fd = fopen("reader.txt", "wt");
if (readerhead != NULL)
{
if (fd == NULL)
{
printf("无法打开reader文件");
}
if (fwrite(readerhead, D, 1, fd) != 1)
{
printf("写入错误!");
}
}
fclose(fd);
if (readerhead != NULL)
{
readerpa = readerhead->next;
fd = fopen("reader.txt", "at");
if (fd == NULL)
{
printf("无法打开reader文件");
}
while (readerpa != NULL)
{
if (fwrite(readerpa, D, 1, fd) != 1)
{
printf("写入错误!");
}
readerpa = readerpa->next;
}
fclose(fd);
}
Sleep(500);
system("cls");
Color(12);
Toxy(46, 8);
printf("-------------------------");
Toxy(46, 9);
printf("| |");
Toxy(46, 10);
printf("| 删除成功,是否继续? |");
Toxy(46, 12);
printf("| 1.是 2.否 |");
Toxy(46, 13);
printf("| |");
Toxy(46, 14);
printf("-------------------------");
while (1)
{
c = getch();
if (c == '1')
{
break;
}
else if (c == '2')
{
ReaderInformation();
}
}
} while (1);
}
void ReaderInformationCatalog() //读者信息总览
{
system("cls");
Color(14);
reader readerhead, readerp;
int i = 10, h = 0;
char readername[11];
int sum_nan = 0, sum_nv = 0;
readerhead = readerlist();
Toxy(2, 5);
printf("*********************************************读者信息总览********************************************************");
Toxy(2, 7);
printf("-----------------------------------------------------------------------------------------------------------------");
Toxy(2, 8);
printf("| 编号| 姓名| 性别| 联系电话| 密码| 已借阅图书数|");
Toxy(2, 9);
printf("-----------------------------------------------------------------------------------------------------------------");
readerp = readerhead;
if (readerhead == NULL)
{
Toxy(2, 10);
printf("暂时没有读者注册哦^_^(按任意键返回)\n");
getch();
ReaderInformation();
}
while (readerp != NULL)
{
Toxy(2, i);
printf("|%20s|%16s|%12s|%20s|%18s|%20d|\n", readerp->readernumber, readerp->readername, readerp->readersex, readerp->tele, readerp->password, readerp->readertotal);
i++;
Toxy(2, i);
printf("-----------------------------------------------------------------------------------------------------------------");
i++;
if (readerp->s == 1)
{
sum_nan++;
}
else
{
sum_nv++;
}
if (readerp->readertotal > h || readerp->readertotal == h)
{
h = readerp->readertotal;
strcpy(readername, readerp->readername);
}
readerp = readerp->next;
}
Toxy(2, i);
printf("当前注册读者中男性读者人数:%d,女性读者人数:%d", sum_nan, sum_nv);
i++;
Toxy(2, i);
printf("-----------------------------------------------------------------------------------------------------------------");
i++;
Toxy(2, i);
printf("当前注册读者中借阅图书最多的人是:%s", readername);
i++;
Toxy(2, i);
printf("按任意键返回\n");
getch();//不回显函数
}
void BorrowInformationCatalog() //借阅总览
{
system("cls");
Color(14);
borrow borrowhead, borrowp;
int i = 10;
int t = 0;
borrowhead = borrowlist();
Toxy(2, 5);
printf("**********************************************借阅信息总览***********************************************************");
Toxy(2, 7);
printf("---------------------------------------------------------------------------------------------------------------------");
Toxy(2, 8);
printf("借阅者编号|借阅者姓名|性别| 电话号码|库存编号| 书名| 作者名|图书类型| 出版社");
Toxy(2, 9);
printf("---------------------------------------------------------------------------------------------------------------------");
borrowp = borrowhead;
if (borrowhead == NULL)
{
Toxy(2, 10);
printf("暂时没有读者借阅图书哦^_^(按任意键返回)\n");
getch();
AdministratorMenu();
}
while (borrowp != NULL)
{
Toxy(2, i);
printf("%10s|%10s|%4s|%11s|%8s|%24s|%18s|%8s|%16s\n", borrowp->borrowamount, borrowp->borrowname, borrowp->borrowsex, borrowp->borrowtele, borrowp->booknumber, borrowp->bookname, borrowp->bookauthor, borrowp->booktype, borrowp->bookpublish);
i++;
Toxy(2, i);
printf("----------------------------------------------------------------------------------------------------------------------");
i++;
t++;
borrowp = borrowp->next;
}
Toxy(2, i);
printf("已借出图书:%d本!!!", t);
i++;
Toxy(2, i);
printf("按任意键返回\n");
getch();//不回显函数
}
主函数
//主函数
int main() //主函数,调用菜单
{
Menu(); //菜单
return 0;
}