我用system函数换成白底蓝字了
#define _CRT_SECURE_NO_WARNINGS
#define BOOK_NAME 32
#define LIBRARY_SIZE 16
#define ID_SIZE 12
#define KEY_SIZE 12
#define STUDENTS_NUMBER 16
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
typedef struct book {
char book_name[BOOK_NAME];
int book_quantity;
struct book()
{
int i;
for (i = 0; i < BOOK_NAME; i++) {
book_name[i] = '\0';
}
book_quantity = 0;
}
}Book;
typedef struct library {
Book Books[LIBRARY_SIZE];
void check_books()
{
char null_str[BOOK_NAME] = { '\0' };
int i;
printf("展示馆内图书:\n");
for (i = 0; i < LIBRARY_SIZE; i++) {
if (strcmp(Books[i].book_name, null_str) != 0) {
printf("%s 剩余%d本\n",Books[i].book_name,Books[i].book_quantity);
}
}
}
}Library;
typedef struct student {
char name[8];
char major;
int current_number;
int max_number;
char Id_number[ID_SIZE];
char Key[KEY_SIZE];
Book Borrow[2];
struct student()
{
int i;
for (i = 0; i < ID_SIZE; i++) {
Id_number[i] = '\0';
}
for (i = 0; i < KEY_SIZE; i++) {
Key[i] = '\0';
}
}
void manage_students()
{
current_number = 0;
if (major == 'A') {
max_number = 2;
}
else if (major == 'B') {
max_number = 1;
}
}
}Student;
typedef struct students {
Student Students[STUDENTS_NUMBER];
}StudentsData;
void Initial_Students(StudentsData &STU) 此处曾出现“表达式的左端必须是可修改的值”
{
int i = 0;
strcpy(STU.Students[0].Id_number, "2019112330");
strcpy(STU.Students[0].Key, "2330");
STU.Students[0].major = 'A';
STU.Students[0].manage_students();
strcpy(STU.Students[1].Id_number, "2019112331");
strcpy(STU.Students[1].Key, "2331");
STU.Students[1].major = 'A';
STU.Students[1].manage_students();
strcpy(STU.Students[2].Id_number, "2019112332");
strcpy(STU.Students[2].Key, "2332");
STU.Students[2].major = 'A';
STU.Students[2].manage_students();
strcpy(STU.Students[3].Id_number, "2019112333");
strcpy(STU.Students[3].Key, "2333");
STU.Students[3].major = 'A';
STU.Students[3].manage_students();
strcpy(STU.Students[4].Id_number, "2019112334");
strcpy(STU.Students[4].Key, "2334");
STU.Students[4].major = 'A';
STU.Students[4].manage_students();
strcpy(STU.Students[5].Id_number, "2019112335");
strcpy(STU.Students[5].Key, "2335");
STU.Students[5].major = 'A';
STU.Students[5].manage_students();
}
void Initial_Library(Library &L)
{
strcpy(L.Books[0].book_name, "C语言程序设计");
L.Books[0].book_quantity = 1;
strcpy(L.Books[1].book_name, "马克思主义原理");
L.Books[1].book_quantity = 1;
strcpy(L.Books[2].book_name, "高等数学");
L.Books[2].book_quantity = 1;
strcpy(L.Books[3].book_name, "普通地质学");
L.Books[3].book_quantity = 1;
strcpy(L.Books[4].book_name, "大学化学");
L.Books[4].book_quantity = 1;
}
int login_check(StudentsData& STU, char id[], char k[])
{
int i, flag = -1;
for (i = 0; i < STUDENTS_NUMBER; i++) {
if (strcmp(STU.Students[i].Id_number, id) == 0) {
if (strcmp(STU.Students[i].Key, k) == 0) {
flag = i;
break;
}
}
}
return flag;
}
int Login(StudentsData &STU)
{
int log;
char temp_id[ID_SIZE] = { '\0' };
char temp_key[KEY_SIZE] = { '\0' };
start_login:
printf("----图书管理系统----\n");
printf("------登录界面------\n");
printf("用户: ");
scanf("%s", temp_id);
printf("密码: ");
scanf("%s", temp_key);
log = login_check(STU, temp_id, temp_key);
if (log == -1) {
printf("用户名或密码有错,请重新输入\n");
system("pause");
system("cls");
goto start_login;
}
return log;
}
int Display_Student(StudentsData &STU, int flag)
{
int remain;
remain = STU.Students[flag].max_number - STU.Students[flag].current_number;
printf("用户%s当前已借%d本,还可借%d本\n", STU.Students[flag].Id_number, STU.Students[flag].current_number, remain);
return remain;
}
void Borrow_Book(Library& L, StudentsData& STU, int stu)
{
int i, bk = -1, retry;
char temp[BOOK_NAME] = { '\0' };
do {
L.check_books();
system("pause"); system("cls");
printf("请输入需要借阅的书: ");
scanf("%s", temp);
for (i = 0; i < LIBRARY_SIZE; i++) {
if (strcmp(temp, L.Books[i].book_name) == 0) {
bk = i;
break;
}
}
if (bk != -1) {
if (L.Books[bk].book_quantity == 0) {
printf("此书已被借完\n是否重新选择?是...1否...0\n");
scanf("%d", &retry);
system("pause"); system("cls");
continue;
}
else if (L.Books[bk].book_quantity > 0) {
strcpy(STU.Students[stu].Borrow[0].book_name, L.Books[bk].book_name);
STU.Students[stu].current_number++;
if (STU.Students[stu].current_number < STU.Students[stu].max_number) {
L.Books[bk].book_quantity--;
printf("借阅一本%s\n",L.Books[bk].book_name);
printf("是否继续借阅?是...1否...0\n");
scanf("%d", &retry);
system("pause"); system("cls");
continue;
}
else if (STU.Students[stu].current_number == STU.Students[stu].max_number) {
L.Books[bk].book_quantity--;
printf("借阅一本%s\n", L.Books[bk].book_name);
printf("借书数量达到上限\n");
system("pause"); system("cls");
retry = 0;
}
}
}
} while (retry == 1);
printf("退出借书功能\n");
}
int main()
{
system("color 71");
int sl, log, check, restart;
Library L;
Initial_Library(L);
StudentsData STU;
Initial_Students(STU);
do {
restart = 0;
log = Login(STU);
do {
start:
system("cls");
printf("功能选择\n查询当前借阅状态...1\n借阅图书...2\n退出登录...0\n");
scanf("%d", &sl);
switch (sl)
{
case 0:restart = 1; system("pause"); system("cls"); break;
case 1:Display_Student(STU, log); system("pause"); system("cls"); break;
case 2:system("cls");
if (STU.Students[log].current_number >= STU.Students[log].max_number) {
printf("借书数量达到上限 不可继续借阅\n");
system("pause"); system("cls");
break;
}
else {
Borrow_Book(L, STU, log);
system("pause"); system("cls");
break;
}
default:goto start;
break;
}
} while (restart == 0);
} while (restart == 1);
}