前言
2020年初,大一的c语言设计实训,当时选题选的是使用链表保存,后来再设计的过程中,发现只是一次性产物,非常的不银性,就使用链表加上文件的方式去存储数据。
我醉欲眠卿且去,明朝有意抱琴来。 直接复制代码
一、系统功能
二、运行截图
直接复制代码
主界面(1):
主界面(2) 用户注册: 用户登录:: 用户界面: 管理员登录: 管理用户:
我们还是看具体代码实现吧,功能太多了不想贴图了。
三、具体实现
1.数据结构
代码如下(图书):
typedef struct book
{
char title[100];
char isbn[100];
char author[100];
char publisher[100];
int cnt;
struct book* next;
}Book;
代码如下(用户所借书籍):
struct node
{
int borrow_amount, max_amount;
Book borrow_book[10];
};
代码如下(用户):
typedef struct user
{
char user_name[30];
char password[30];
char ID[30];
int admin;
struct node user_book;
struct user* next;
}User;
定义功能函数:
void welcome_page();
void producer_infor();
void manual();
void main_menu();
void user_register();
void user_login();
void admin_login();
void creat_user_list(char*, char*, char*);
void creat_book_list(char*, char*, char*, char*, int);
void user_initi(User*);
void load();
void save();
void user_menu(User*);
void user_change(User*);
int delete_user(User*);
void borrow_book(User*);
void return_book(User*);
void history(User*);
void admin_initi();
User* serch_username(char*);
void admin_menu(User*);
void query_user();
void admin_user();
void all_history();
User* serch_user();
void set_admin(User*);
void add_book();
void delete_book();
void browse_book();
void toxy(int x, int y)
{
COORD pos = { x , y };
HANDLE Out = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(Out, pos);
}
扩展区:
void toxy(int x, int y)
{
COORD pos = { x , y };
HANDLE Out = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(Out, pos);
}
void color(short x)
{
if (x >= 0 && x <= 15)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), x);
}
else
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), x);
}
}
void HideCursor()
{
CONSOLE_CURSOR_INFO cursor_info = { 1, 0 };
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
}
2.所有代码(可在vs2019下直接运行)
#define _CRT_SECURE_NO_WARNINGS
#pragma warning(disable : 4996)
#include"windows.h"
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<time.h>
typedef struct book
{
char title[100];
char isbn[100];
char author[100];
char publisher[100];
int cnt;
struct book* next;
}Book;
Book* book_head;
int book_amount;
struct node
{
int borrow_amount, max_amount;
Book borrow_book[10];
};
typedef struct user
{
char user_name[30];
char password[30];
char ID[30];
int admin;
struct node user_book;
struct user* next;
}User;
User* user_head;
User* shanzhu;
int user_amount;
void welcome_page();
void producer_infor();
void manual();
void main_menu();
void user_register();
void user_login();
void admin_login();
void creat_user_list(char*, char*, char*);
void creat_book_list(char*, char*, char*, char*, int);
void user_initi(User*);
void load();
void save();
void user_menu(User*);
void user_change(User*);
int delete_user(User*);
void borrow_book(User*);
void return_book(User*);
void history(User*);
void admin_initi();
User* serch_username(char*);
void admin_menu(User*);
void query_user();
void admin_user();
void all_history();
User* serch_user();
void set_admin(User*);
void add_book();
void delete_book();
void browse_book();
void toxy(int x, int y)
{
COORD pos = { x , y };
HANDLE Out = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(Out, pos);
}
void color(short x)
{
if (x >= 0 && x <= 15)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), x);
}
else
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), x);
}
}
void HideCursor()
{
CONSOLE_CURSOR_INFO cursor_info = { 1, 0 };
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
}
int main()
{
welcome_page();
printf("退出系统成功,祝您生活愉快!\n");
system("pause"); system("cls");
return 0;
}
void welcome_page()
{
HideCursor();
load();
while (1)
{
system("color 0F");
toxy(48, 5);
printf(" 山竹图书信息管理系统");
toxy(48, 8);
printf("| 1.进入系统 |");
toxy(48, 10);
printf("| |");
toxy(48, 12);
printf("| 2.关于版本 |");
toxy(48, 14);
printf("| |");
toxy(48, 16);
printf("| 3.关于使用 |");
toxy(48, 18);
printf("| |");
toxy(48, 20);
printf("| 0.退出软件 |");
char t; t = getch(); system("cls");
switch (t)
{
case '1': main_menu(); break;
case '2': producer_infor(); break;
case '3': manual(); break;
case '0': return;
default:
color(10);
toxy(48, 8);
printf("错误的指令,请重新输入!\n");
toxy(48, 9);
system("pause"); system("cls"); break;
}
}
}
void producer_infor()
{
system("color 0F");
toxy(40, 8);
printf("********************************************************\n");
toxy(40, 9);
printf("| |\n");
toxy(40, 10);
printf("| 初始 版本为1.0,只有简单增加书籍等功能。 |\n");
toxy(40, 11);
printf("| 1.2版本:基本完成图书管理功能 。 |\n");
toxy(40, 12);
printf("| 1.5版本:实现了图书借阅还书等功能。 |\n");
toxy(40, 13);
printf("| 1.7版本:增加安全功能,追加登录系统。 |\n");
toxy(40, 14);
printf("| 1.9版本:增加小游戏功能,修改借书bug。 |\n");
toxy(40, 15);
printf("| 2.0版本 优化了许多界面。此版本为 |\n");
toxy(40, 16);
printf("| |\n");
if (3 > 2)
{
toxy(40, 17);
printf("| 此版本为5.0plus版本 |\n");
}
toxy(40, 18);
printf("*********************************************************\n");
system("pause"); system("cls");
}
void manual()
{
system("color 0F");
HideCursor();
toxy(40, 8);
printf("********************************************************\n");
toxy(40, 10);
printf("| |\n");
toxy(40, 12);
printf("| 初始管理员账号为shanzhu(山竹) |\n");
toxy(40, 14);
printf("| 管理员密码:wc123456 |\n");
toxy(40, 16);
printf("| 由于所学尚浅 则使用时需按步骤来 |\n");
toxy(40, 18);
printf("| 按对应数字键 实现功能 |\n");
toxy(40, 20);
printf("| 众所周知 |\n");
toxy(40, 22);
printf("| 山竹 不是一种水果 是台风 |\n");
toxy(40, 24);
printf("| |\n");
toxy(40, 26);
printf("*********************************************************\n");
system("pause"); system("cls");
}
void main_menu()
{
HideCursor();
while (1)
{
system("color 0F");
toxy(48, 5);
printf(" 山竹图书信息管理系统");
toxy(48, 8);
printf("| 1.用户注册 |");
toxy(48, 10);
printf("| |");
toxy(48, 12);
printf("| 2.用户登录 |");
toxy(48, 14);
printf("| |");
toxy(48, 16);
printf("| 3.管理登录 |");
toxy(48, 18);
printf("| |");
toxy(48, 20);
printf("| 0.返回上页 |");
char t; t = getch(); system("cls");
switch (t)
{
case '1': user_register(); break;
case '2': user_login(); break;
case '3': admin_login(); break;
case '0': return;
default: printf("错误的指令,请重新输入!\n"); system("pause"); system("cls"); break;
}
}
}
void user_register()
{
HideCursor();
char name[30];
toxy(40, 8);
system("color 02");
printf("请输入您需要注册的用户名(不超过25个字母):\n");
toxy(40, 9);
scanf("%s", name);
User* account = NULL;
if (account = serch_username(name), account != NULL)
{
toxy(40, 10);
printf("该用户名已存在,请重新输入!\n");
toxy(40, 11);
system("pause"); system("cls"); return;
}
toxy(40, 10);
printf("请输入您的账号密码(不超过25个字母):\n");
char password[30];
toxy(40, 11);
scanf("%s", password);
toxy(40, 12);
printf("请输入您的有效证件号码(不超过25个数字):\n");
char ID[30];
toxy(40, 13);
scanf("%s", ID);
creat_user_list(name, password, ID);
toxy(40, 14);
printf("恭喜您注册成功!\n");
++user_amount;
toxy(40, 15);
system("pause"); system("cls");
}
void user_login()
{
system("color 02");
char name[30];
toxy(40, 8);
printf("请输入您的用户名(不超过25个字母):\n");
toxy(40, 9);
scanf("%s", name);
User* account;
if (account = serch_username(name), account == NULL)
{
toxy(40, 10);
printf("该用户名不存在,请注册或重新登陆账号!\n");
toxy(40, 11);
system("pause"); system("cls"); return;
}
toxy(40, 10);
printf("请输入您的账号密码(不超过25个字母):\n");
toxy(40, 11);
scanf("%s", name);
if (strcmp(account->password, name))
{
toxy(40, 8);
printf("密码错误,请确认后重新登陆!\n");
toxy(40, 9);
system("pause"); system("cls"); return;
}
toxy(40, 12);
printf("恭喜您登录成功,即将跳转用户界面...\n");
toxy(40, 13);
system("pause"); system("cls");
user_menu(account);
}
void admin_login()
{
char name[30];
system("color 02");
toxy(40, 8);
printf("尊敬的管理员:\n");
toxy(40, 9);
printf("请输入您的管理账号(不超过25个字母):\n");
toxy(40, 10);
scanf("%s", name);
User* account;
if (account = serch_username(name), account == NULL)
{
toxy(40, 9);
printf("该账号不存在,请重新输入!\n");
toxy(40, 10);
system("pause"); system("cls"); return;
}
if (!account->admin)
{
toxy(40, 9);
printf("该账号暂无管理权限,请联系相关管理人员!\n");
toxy(40, 10);
system("pause"); system("cls"); return;
}
toxy(40, 11);
printf("请输入该管理账号的密码(不超过25个字母):\n");
toxy(40, 12);
scanf("%s", name);
if (strcmp(account->password, name))
{
toxy(40, 13);
printf("密码错误,请确认后重新登陆!\n");
toxy(40, 14);
system("pause"); system("cls"); return;
}
toxy(40, 13);
printf("恭喜您登录成功,即将跳转管理界面...\n");
toxy(40, 14);
system("pause"); system("cls");
admin_menu(account);
}
void creat_user_list(char* name, char* password, char* ID)
{
User* np = (User*)malloc(sizeof(User));
np = user_head;
while (np->next) np = np->next;
User* tp = (User*)malloc(sizeof(User));
strcpy(tp->user_name, name);
strcpy(tp->password, password);
strcpy(tp->ID, ID);
tp->admin = 0;
tp->next = NULL;
user_initi(tp);
np->next = tp;
save();
}
void creat_book_list(char* title, char* isbn, char* author, char* publisher, int cnt)
{
Book* np = (Book*)malloc(sizeof(Book));
np = book_head;
while (np->next) np = np->next;
Book* tb = (Book*)malloc(sizeof(Book));
strcpy(tb->title, title);
strcpy(tb->isbn, isbn);
strcpy(tb->author, author);
strcpy(tb->publisher, publisher);
tb->cnt = cnt;
tb->next = NULL;
np->next = tb;
save();
}
void user_initi(User* account)
{
account->user_book.borrow_amount = 0;
account->user_book.max_amount = 10;
memset(account->user_book.borrow_book, 0, sizeof(account->user_book.borrow_book));
}
void load()
{
book_head = (Book*)malloc(sizeof(Book));
book_head->next = NULL;
book_amount = 0;
FILE* fp2;
fp2 = fopen("book.bin", "rb");
if (fp2 == NULL)
{
fp2 = fopen("book.bin", "wb");
if (fp2 == NULL)
{
printf("图书存储失败!\n"); exit(0);
}
fclose(fp2);
}
else
{
Book* bp = (Book*)malloc(sizeof(Book));
bp = book_head;
Book* tp = (Book*)malloc(sizeof(Book));
while (fread(tp, sizeof(Book), 1, fp2))
{
bp->next = tp;
++book_amount;
tp = tp->next;
tp = (Book*)malloc(sizeof(Book));
bp = bp->next;
}
fclose(fp2);
}
user_head = (User*)malloc(sizeof(User));
user_head->next = NULL;
user_amount = 0;
FILE* fp1;
fp1 = fopen("user.bin", "rb");
if (fp1 == NULL)
{
admin_initi(); return;
}
User* np = (User*)malloc(sizeof(User));
np = user_head;
User* temp = (User*)malloc(sizeof(User));
while (fread(temp, sizeof(User), 1, fp1))
{
np->next = temp;
++user_amount;
temp = temp->next;
temp = (User*)malloc(sizeof(User));
np = np->next;
}
shanzhu = user_head->next;
fclose(fp1);
}
void save()
{
FILE* fp = fopen("user.bin", "wb");
User* temp = user_head->next;
while (temp)
{
fwrite(temp, sizeof(User), 1, fp);
temp = temp->next;
}
fclose(fp);
fp = fopen("book.bin", "wb");
Book* tb = book_head->next;
while (tb)
{
fwrite(tb, sizeof(Book), 1, fp);
tb = tb->next;
}
fclose(fp);
}
void user_menu(User* account)
{
system("color 0F");
char t=0;
while (1)
{
HideCursor();
toxy(51, 5);
printf("用户:%s欢迎您!\n", account->user_name);
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();
system("cls");
switch (t)
{
case '1': borrow_book(account); break;
case '2': return_book(account); break;
case '3': browse_book(); system("pause"); system("cls"); break;
case '4': user_change(account); break;
case '5': if (delete_user(account))
{
system("color 02");
toxy(40, 8);
printf("该账号已被删除,请重新登陆!\n");
toxy(40, 9);
system("pause"); system("cls");
return;
}
else break;
toxy(40, 8);
case '0': printf("账号登出成功!\n"); toxy(40, 9); system("pause"); system("cls"); return;
default:toxy(40, 8); printf("错误的指令,请重新输入!\n"); toxy(40, 9); system("pause"); system("cls"); break;
}
}
}
void user_change(User* account)
{
system("color 02");
toxy(40, 8);
printf("待修改用户:%s\t 您现在可以更改您的个人信息!\n", account->user_name);
toxy(40, 9);
printf("请重新输入您的密码(不超过25个字母):\n");
char password[30];
toxy(40, 10);
scanf("%s", password);
strcpy(account->password, password);
toxy(40, 11);
printf("用户%s\t账号密码已修改!\n", account->user_name);
toxy(40, 12);
printf("请重新输入您的有效证件号码(不超过25个字母):\n");
char ID[30];
toxy(40, 13);
scanf("%s", ID);
strcpy(account->ID, ID);
toxy(40, 14);
printf("用户%s\t有效证件号码已修改!\n", account->user_name);
save();
toxy(40, 15);
printf("用户%s\t个人信息修改成功,正在返回上一界面...\n", account->user_name);
toxy(40, 16);
system("pause"); system("cls");
}
int delete_user(User* account)
{
printf("********************************************\n");
if (!strcmp(account->user_name, shanzhu->user_name))
{
system("color 02");
toxy(40, 8);
printf("用户%s拥有最高权限,不可被删除!!!正在返回上一层...\n", shanzhu->user_name);
toxy(40, 9);
system("pause"); system("cls"); return 0;
}
toxy(40, 8);
printf("是否需要删除账号%s?\n", account->user_name);
toxy(40, 9);
printf("请输入相应数字以继续操作!\n");
toxy(40, 10);
printf("1、是\t0、否\n");
int op; scanf("%d", &op);
if (op == 1)
{
if (account->user_book.borrow_amount)
{
toxy(40, 11);
printf("删除失败!该用户有%d本图书未归还!请先归还所借阅图书!\n", account->user_book.borrow_amount);
}
else
{
User* tp = (User*)malloc(sizeof(User));
tp = user_head;
User* np = (User*)malloc(sizeof(User));
np = user_head->next;
while (np)
{
if (!strcmp(np->user_name, account->user_name))
{
tp->next = np->next;
free(np); --user_amount;
save();
toxy(40, 11);
printf("账号已删除成功!\n");
toxy(40, 12);
system("pause"); system("cls");
return 1;
}
tp = np;
np = np->next;
}
}
}
else if (!op) { toxy(40, 8); printf("已取消本次操作!\n"); }
else {
toxy(40, 10); printf("输入选项错误,请重新输入!正在返回上一层...\n");
}
toxy(40, 11);
system("pause"); system("cls"); return 0;
}
void borrow_book(User* account)
{
system("color 02");
toxy(40, 8);
printf("用户%s:请输入您的有效身份证件号码(不超过25位)以继续!\n", account->user_name);
char ID[30]; scanf("%s", ID); system("cls");
if (strcmp(account->ID, ID))
{
toxy(40, 9);
printf("身份证件号码与账号不匹配,请检查后重新输入!\n");
toxy(40, 10);
system("pause"); system("cls"); return;
}
while (1)
{
int ans = account->user_book.borrow_amount, Max = account->user_book.max_amount;
if (ans == Max)
{
toxy(40, 9);
printf("用户%s:借阅图书数量 %d 本,已达上限 %d 本,请先归还部分图书!\n", account->user_name, ans, Max);
system("pause"); system("cls"); return;
}
browse_book();
toxy(40, 9);
printf("请输入您需要借阅的书籍序号(输入 -1 退出删除操作):\n");
int cnt; scanf("%d", &cnt);
if (cnt == -1)
{
toxy(40, 10);
printf("已成功退出借阅系统!\n"); toxy(40, 11); system("pause"); system("cls");
return;
}
else if (cnt > book_amount || cnt <= 0)
{
toxy(40, 10);
printf("请正确输入上图中已有的图书序号!\n");
}
else
{
{
Book* tb = (Book*)malloc(sizeof(Book));
tb = book_head->next;
for (int i = 1; i < cnt; ++i)
tb = tb->next;
account->user_book.borrow_book[ans] = *tb;
++account->user_book.borrow_amount;
save();
toxy(40, 10);
printf("用户%s:借阅图书《%s》成功!\n", account->user_name, tb->title);
}
}
toxy(40, 11);
system("pause"); system("cls");
}
}
void return_book(User* account)
{
system("color 02");
while (1)
{
history(account);
if (!account->user_book.borrow_amount)
{
toxy(40, 8);
system("pause"); system("cls"); return;
}
toxy(40, 8);
printf("请输入您需要归还的书籍序号(输入-1以退出还书系统)!\n");
int cnt = 0; toxy(40, 19); scanf("%d", &cnt); system("cls");
if (cnt == -1)
{
toxy(40, 9);
printf("正在退出还阅系统,请稍后...\n");
toxy(40, 10);
system("pause"); system("cls"); return;
}
if (cnt > account->user_book.borrow_amount || cnt < 0)
{
toxy(40, 9);
printf("请正确输入上述书籍序号!\n");
}
else
{
int i = 0;
for (--cnt; i < cnt; ++i);
char title[100];
strcpy(title, account->user_book.borrow_book[i].title);
printf("*************************************************\n");
for (; i < account->user_book.borrow_amount; ++i)
{
account->user_book.borrow_book[i] = account->user_book.borrow_book[i + 1];
}
--account->user_book.borrow_amount;
save();
toxy(40, 9);
printf("书籍《%s》归还成功!\n", title);
}
toxy(40, 10);
system("pause"); system("cls");
}
}
void history(User* account)
{
int n = account->user_book.borrow_amount;
printf("*************************************************************\n");
printf("用户%s:\n", account->user_name);
if (!n)
{
printf("暂无书籍在借阅记录!\n"); return;
}
printf("借阅书籍序号:\n");
for (int i = 0; i < n; ++i)
{
struct node t = account->user_book;
double cost = 0.0;
printf("%d:\n", i + 1);
printf(" 书名:《%s》\n", t.borrow_book[i].title);
}
}
void admin_initi()
{
FILE* fp = fopen("user.bin", "wb");
if (fp == NULL)
{
printf("管理员权限初始化失败!\n"); exit(0);
}
shanzhu = (User*)malloc(sizeof(User));
strcpy(shanzhu->user_name, "shanzhu");
strcpy(shanzhu->password, "wc123456");
strcpy(shanzhu->ID, "71620");
shanzhu->admin = 1;
shanzhu->next = NULL;
user_initi(shanzhu);
user_head->next = shanzhu;
user_amount = 1;
save();
fclose(fp);
}
User* serch_username(char* name)
{
User* np = user_head->next;
while (np)
{
if (!strcmp(np->user_name, name)) return np;
np = np->next;
}
return NULL;
}
void admin_menu(User* account)
{
while (1)
{
char t;
system("color 0F");
HideCursor();
toxy(51, 5);
printf("管理员:%s欢迎您!\n", account->user_name);
toxy(48, 8);
printf("| 1.增加图书 |");
toxy(48, 10);
printf("| 2.删除图书 |");
toxy(48, 12);
printf("| 3.图书浏览 |");
toxy(48, 14);
printf("| 4.管理用户 |");
toxy(48, 16);
printf("| 0.退出软件 |");
t = getch(); system("cls");
switch (t)
{
case '1': add_book(); break;
case '2': delete_book(); break;
case '3': browse_book(); system("pause"); system("cls"); break;
case '4': admin_user(); break;
case '0': printf("退出管理账号成功!\n"); system("pause"); system("cls"); return;
default: printf("错误的指令,请重新输入!\n"); system("pause"); system("cls"); break;
}
}
}
void query_user()
{
int cnt = 1;
User* np = (User*)malloc(sizeof(User));
system("color 02");
np = user_head->next;
toxy(32, 8);
printf("序号 用户名\t\t密码\t\t证件号码\t\t是否管理员\n");
while (np)
{
toxy(32, 10);
printf("%d、 %-20s %-20s %-20s", cnt, np->user_name, np->password, np->ID);
if (np->admin) printf(" 是\n");
else printf(" 否\n");
np = np->next;
++cnt;
}
}
void admin_user()
{
while (1)
{
char t;
system("color 0F");
HideCursor();
toxy(48, 8);
printf("| 1.查看用户 |");
toxy(48, 10);
printf("| 2.修改用户 |");
toxy(48, 12);
printf("| 3.查看归还 |");
toxy(48, 14);
printf("| 4.管理用户 |");
toxy(48, 16);
printf("| 0.返回上级 |");
User* np = (User*)malloc(sizeof(User));
t = getch(); system("cls");
switch (t)
{
case '1': query_user(); system("pause"); system("cls"); break;
case '2': if (np = serch_user(), np != NULL) user_change(np);
else
{
system("pause"); system("cls");
}
break;
case '3': all_history(); break;
case '4': if (np = serch_user(), np != NULL) set_admin(np);
else
{
system("pause"); system("cls");
}
break;
case '5':if (np = serch_user(), np != NULL)
{
int admin = np->admin;
if (delete_user(np) && admin)
printf("该账号已被删除,请重新登陆!\n");
system("pause"); system("cls");
return;
}
else
{
system("pause"); system("cls");
}
break;
case '0': printf("退出用户管理界面成功!\n"); system("pause"); system("cls"); return;
default: printf("错误的指令,请重新输入!\n"); system("pause"); system("cls"); break;
}
}
}
void all_history()
{
while (1)
{
printf("###########################################################\n");
printf("欢迎使用用户图书借阅归还查询系统!\n");
User* account = (User*)malloc(sizeof(User));
account = serch_user();
if (account)
{
history(account);
printf("查阅成功!正在返回上一层...\n");
system("pause"); system("cls"); return;
}
system("pause"); system("cls");
}
}
User* serch_user()
{
query_user();
printf("请输入待操作的用户序号:\n");
int cnt; scanf("%d", &cnt); system("cls");
if (cnt > user_amount || cnt <= 0)
printf("请正确输入上图中待操作的用户序号!\n");
else
{
User* tb = (User*)malloc(sizeof(User));
tb = user_head->next;
for (int i = 1; i < cnt; ++i)
tb = tb->next;
return tb;
}
return NULL;
}
void set_admin(User* account)
{
printf("*******************************************************************\n");
if (!strcmp(account->user_name, shanzhu->user_name))
{
printf("用户%s拥有最高管理权限,不可被修改!!!正在返回上一层...\n", shanzhu->user_name);
system("pause"); system("cls"); return;
}
printf("是否确认将用户%s设置为管理员?\n", account->user_name);
printf("请输入相应数字以继续操作!\n");
printf("1、设置为管理员\t0、取消管理员权限\n");
int op; scanf("%d", &op);
if (op == 1)
{
account->admin = op;
printf("用户%s\t管理员权限设置成功!\n", account->user_name);
}
else if (op == 0)
{
account->admin = op;
printf("用户%s\t管理员权限已被取消!\n", account->user_name);
}
else
{
printf("设置管理员权限失败,请按要求输入!\n");
}
printf("*******************************************************************\n");
save();
system("pause"); system("cls");
}
void add_book()
{
char title[100], isbn[100], author[100], publisher[100];
int cnt;
printf("请输入需要添加的书籍名称:\n");
scanf("%s", title);
printf("请输入需要添加的书籍书号:\n");
scanf("%s", isbn);
printf("请输入需要添加的书籍作者:\n");
scanf("%s", author);
printf("请输入需要添加的书出版社:\n");
scanf("%s", publisher);
printf("请输入需要添加的书籍数量:\n");
scanf("%d", &cnt);
++book_amount;
creat_book_list(title, isbn, author, publisher, cnt);
printf("添加书籍《%s》成功!\n", title);
system("pause"); system("cls");
}
void delete_book()
{
while (1)
{
browse_book();
printf("请输入待删除的书籍序号(输入 -1 退出删除操作):\n");
int cnt; scanf("%d", &cnt);
if (cnt == -1)
{
printf("已成功退出删除系统!\n"); system("pause"); system("cls");
return;
}
else if (cnt > book_amount || cnt <= 0)
{
printf("请正确输入上图中待删除的图书序号!\n");
}
else
{
Book* tb = (Book*)malloc(sizeof(Book));
Book* np = (Book*)malloc(sizeof(Book));
np = book_head;
tb = book_head->next;
for (int i = 1; i < cnt; ++i)
{
np = tb;
tb = tb->next;
}
np->next = tb->next;
free(tb); --book_amount;
save();
printf("该图书已从馆内删除成功!\n");
}
system("pause"); system("cls");
}
}
void browse_book()
{
int cnt = 1;
if (!book_amount)
{
printf("馆内暂无图书资料,请联系管理员添加书籍!\n");
return;
}
Book* tb = (Book*)malloc(sizeof(Book));
tb = book_head->next;
printf("馆内图书详情如下:\n");
printf("序号\t书名\t书号\t作者\t出版社\t总库存量\n");
while (tb)
{
printf("%-4d、《%s》 %-20s %-20s %-20s %d\n", cnt, tb->title, tb->isbn,
tb->author, tb->publisher, tb->cnt);
tb = tb->next; ++cnt;
}
}
为了美观下了不少功夫,毕竟实训嘛,要做的有趣一点。
总结
第一个大作业(实训): 要去认真做一些有趣的东西,而不是为了完成任务,毕竟这才是人生的意义嘛。
|