#include
#include
#include
#include
#define MAX_BOOKS 10000
#define MAX_USERS 10000
using namespace std;
struct Book {
int book_id;
char title[100];
char author[100];
int available;
int total;
};
struct bb {
int bookid; //所借阅书籍的编号
bb* next; // 指向下一本借阅的书的指针
};
struct User {
int userid;
char name[15];
long long phone;
int bbn; // 借阅书数
bb* booklist; // 借阅的书:指向链表头结点的指针
User* next;
};
User* userslist = NULL;
int sum = 0;
struct Book books[MAX_BOOKS];
int num_books = 0;
int num_users = 0;
int choose();
int mainMenu();
int bookMenu();
void addbook();
void borrowbook();
void returnbook();
void searchbook();
void deletebook();
int book();
void readBook();
void writeBook();
int user();
void writeUser();
void readUser();
int main() {
while (1) {
int choice = mainMenu();
switch (choice) {
case 1:
book();
break;
case 2:
user();
break;
case 3:
exit(0);
break;
default:
printf("无效数字!n");
//system("pause");
break;
}
}
}
int choose()
{
int choice = -1;
printf("输入选择:");
scanf("%d", &choice);
return choice;
}
//主系统
int mainMenu()
{
printf("n****************************n");
printf("* 图书馆系统 *n");
printf("* 1.图书管理系统 *n");
printf("* 2.会员管理系统 *n");
printf("* 3. 退出系统 *n");
printf("****************************n");
return choose();
}
int bookMenu()
{
printf("n**********************************n");
printf("* 图书管理系统 *n");
printf("* 1. 添加图书 *n");
printf("* 2. 借阅图书 *n");
printf("* 3. 归还图书 *n");
printf("* 4. 查询图书 *n");
printf("* 5. 删除图书 *n");
printf("* 6. 保存修改 *n");
printf("* 7. 返回主系统 *n");
printf("* 8. 切换会员管理系统 *n");
printf("* 9. 退出系统 *n");
printf("**********************************n");
return choose();
}
//添加图书
void addBook() {
// 检查是否已存在该书
int book_id, count;
char title[100];
char author[100];
printf("图书id:");
scanf("%d", &book_id);
printf("书名:");
scanf("%s", title);
printf("作者名:");
scanf("%s", author);
printf("添加数量:");
scanf("%d", &count);
if (count + sum > MAX_BOOKS)
{
printf("图书馆存储空间已满,无法添加!");
return;
}
for (int i = 0; i > phone;
User* c = userslist;
while (c != NULL && c->phone != phone)
{
c = c->next; // 寻找要借书的会员
}
if (c == NULL)
{
cout bbn >= 3) {
cout > bookid;
for (int i = 0; i 0)
{
books[i].available--;
printf("借阅成功n");
sum--;
// 创建新的书籍节点
bb* newbook = new bb(); //newBook
newbook->bookid = bookid;
newbook->next = NULL;
if (c->bbn == 0)
{
c->booklist = newbook; // 如果之前未借过书,直接把新书籍节点设为书单的头
}
else
{
bb* cb = c->booklist; //currentBook
while (cb->next != NULL)
{
cb = cb->next; // 找到书单的末尾节点
}
cb->next = newbook; // 将新书籍节点插入到末尾节点之后
cb = cb->next;
cb->next = NULL;
}
c->bbn++;
}
else
{
printf("该书已全部借出n");
}
return;
}
}
printf("未找到该书n");
return;
}
//归还图书
void returnBook()
{
long long phone;
int book_id;
char title[100];
char author[100];
printf("请输入归还者的手机号:");
scanf("%lld", &phone);
User* c = userslist;
while (c != NULL && c->phone != phone)
{
c = c->next; // 寻找要借书的会员
}
if (c == NULL)
{
cout MAX_BOOKS)
{
printf("图书馆存储空间已满,无法添加!");
return;
}
for (int i = 0; i bookid = book_id;
newbook->next = NULL;
if (c->bbn == 0)
{
c->booklist = newbook; // 如果之前未借过书,直接把新书籍节点设为书单的头
服务器托管网 }
else
{
bb* cb = c->booklist; //currentBook
while (cb->next != NULL)
{
cb = cb->next; // 找到书单的末尾节点
}
cb->next = newbook; // 将新书籍节点插入到末尾节点之后
cb = cb->next;
cb->next = NULL;
}
c->bbn++;
return;
}
else
{
printf("此书非待归还状态!n");
return;
}
}
}
printf("未找到该书!");
}
//查找图书
void searchBook() {
char keyword[100];
int found = 0;
printf("输入查找信息(书名/作者): ");
scanf("%s", &keyword);
printf("查找结果:n");
for (int i = 0; i next = NULL;
printf("请输入要添加的会员姓名:");
scanf("%s", name);
printf("请输入要添加会员的手机号:");
cin >> phone;
newUser->phone = phone;
strcpy(newUser->name, name);
newUser->bbn = 0;
newUser->booklist = NULL;
newUser->userid = num_users;
if (userslist == NULL)
{
userslist = newUser; // 如果会员链表为空,直接将新会员节点设为头节点
}
else
{
User* current = userslist;
while (current->next != NULL)
{
current = current->next; // 找到会员链表的末尾节点
}
current->next = newUser; // 将新会员节点插入到末尾节点之后
}
printf("会员添加成功!n");
num_users++;
}
// 查询会员编号、姓名、手机号、已借阅书籍量、具体借阅书籍
void searchUser() {
long long phone;
cout > phone;
User* current = userslist;
while (current != NULL)
{
if (current->phone == phone)
{
cout userid name phone bbn bbn == 0)
{
cout booklist;
cout bookid next;
}
cout next;
}
cout > phone;
User* current = userslist;
User* p = NULL;
// 寻找要删除的会员节点,并记录其前一个节点
while (current != NULL && current->phone != phone)
{
p = current;
current = current->next;
}
// 如果未找到要删除的会员
if (current == NULL)
{
cout next;
}
else
{
p->next = current->next;
}
// 释放要删除的节点的内存
delete current;
cout userid, member->name, member->phone, member->bbn);
bb* p = new bb;
p = member->booklist;
while (p != NULL)
{
fprintf(服务器托管网fp, "%s ", p->bookid);
p = p->next;
}
fprintf(fp, "n");
member = member->next;
}
fclose(fp);
printf("保存信息成功!n");
return;
}
void readUser() {
FILE* fp = fopen("User.txt", "r");
User* member = NULL;
User* p = NULL;
bb* book = NULL;
char line[1000];
while (fgets(line, sizeof(line), fp) != NULL)
{
member = new User();
int bytesRead = sscanf(line, "%d %s %lld %d", &member->userid, member->name, &member->phone, &member->bbn);
//if (bytesRead != 4) {
// cout bbn; ++i)
{
int bookid;
book = new bb();
book->bookid = NULL;
book->next = NULL;
if (member->booklist == NULL)
{
member->booklist = book;
}
else
{
bb* temp = member->booklist;
while (temp->next != NULL)
{
temp = temp->next;
}
temp->next = book;
}
}
if (p != NULL)
{
p->next = member;
num_users++;
}
else
{
userslist = member;
}
p = member;
}
fclose(fp);
cout
服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net
相关推荐: 一款比Typora更简洁优雅的Markdown编辑器神器(完全开源免费)
前言 自从Typora收费以后经常有朋友会问有没有一个好用、简洁、免费的Markdown编辑器推荐的,今天大姚给大家分享一款比Typora更简洁优雅的、完全开源免费(MIT License)Markdown编辑器神器:MarkText。 MarkText简介 …