今天再次上传一下我最近新开发的代码。
cpp
#include <bits/stdc++.h>
using namespace std;
char x;
int book_count = 0, jieyue_count = 0;
struct Books {
char program[3];
string name;
int in_school_year;
char where_fangwei, where_xingzhuang, where_build, where_book_count[4];
int where_lie, where_hang, where_floor, many = 0;
int out_book = 0;
} a[9999999];
struct Jieyue {
char program[11][3];
string book_name[11];
int in_school_year[11];
char where_fangwei[11], where_xingzhuang[11], where_build[11], where_book_count[11][4];
int where_lie[11], where_hang[11], where_floor[11];
string name;
int book_number = 0;
} people[500500];
inline void plus_book() {
printf("请输入您要添加的书籍数量:\n");
int plus = 0;
cin >> plus;
for(; plus --; ) {
printf("请输入书籍信息(例如:LS 2022J 3NZ 5 4 001 西安故事 2):\n");
++book_count;
cin >> a[book_count].program[1] >> a[book_count].program[2] >> a[book_count].in_school_year >> a[book_count].where_build >> a[book_count].where_floor >> a[book_count].where_fangwei >> a[book_count].where_xingzhuang >> a[book_count].where_hang >> a[book_count].where_lie >> a[book_count].where_book_count[1] >> a[book_count].where_book_count[2] >> a[book_count].where_book_count[3];
scanf(" ");
cin >> a[book_count].name >> a[book_count].many;
printf("输入信息成功\n这本书在:");
if(a[book_count].where_build == 'J') {
cout << "旧楼";
}else {
cout << "新楼";
}
cout << a[book_count].where_floor << "层";
if(a[book_count].where_fangwei == 'N') {
cout << "北区";
} else if(a[book_count].where_fangwei == 'S') {
cout << "南区";
} else if(a[book_count].where_fangwei == 'W') {
cout << "西区";
} else if(a[book_count].where_fangwei == 'E') {
cout << "东区";
} else {
cout << "中区";
}
if(a[book_count].where_xingzhuang == 'Z') {
cout << "直型书柜";
} else {
cout << "环形书柜";
}
cout << a[book_count].where_hang << "行" << a[book_count].where_hang << "列 第" << a[book_count].where_book_count[1] << a[book_count].where_book_count[2] << a[book_count].where_book_count[3] << "本书";
cout << " 这本书一共有" << a[book_count].many << "本\n";
}
return;
}
inline void find_book() {
printf("请输入查找书籍名称:\n");
string find_name;
scanf("\n");
cin >> find_name;
bool can_find = false;
for (int i = 1; i <= book_count; i++) {
if (a[i].name == find_name) {
if(a[i].where_build == 'J') {
cout << "旧楼";
}else {
cout << "新楼";
}
cout << a[i].where_floor << "层";
if(a[i].where_fangwei == 'N') {
cout << "北区";
} else if(a[i].where_fangwei == 'S') {
cout << "南区";
} else if(a[i].where_fangwei == 'W') {
cout << "西区";
} else if(a[i].where_fangwei == 'E') {
cout << "东区";
} else {
cout << "中区";
}
if(a[i].where_xingzhuang == 'Z') {
cout << "直型书柜";
} else {
cout << "环形书柜";
}
cout << a[i].where_hang << "行" << a[i].where_hang << "列 第" << a[i].where_book_count[1] << a[i].where_book_count[2] << a[i].where_book_count[3] << "本书";
cout << " 这本书目前一共有" << a[i].many << "本\n";
can_find = true;
}
}
if (!can_find) {
cout << "对不起,目前暂无您要查找的书籍。\n";
}
return;
}
inline void take_out() {
printf("请输入您的名字(禁止重复):\n");
string name;
cin >> name;
int name_num = 0;
bool has_take_out = false;
for(int i = 1; i <= jieyue_count; i ++) {
if(people[i].name == name) {
has_take_out = true;
name_num = i;
break;
}
}
if(!has_take_out) {
printf("正在为您办理借阅开。\n");
jieyue_count++;
people[jieyue_count].name = name;
printf("借阅开已为您办理好了,欢迎您借阅图书!\n");
}
printf("\n请输入借阅本数:\n");
int book_much = 0;
cin >> book_much;
printf("\n请依次输入您要借阅的书籍名称:\n");
for (int i = 1; i <= book_much; i++) {
string find_name;
scanf("\n");
cin >> find_name;
bool can_find = false;
for (int j = 1; j <= book_count; j++) {
if (a[j].name == find_name && (a[j].out_book <= a[j].many && a[j].many >= 0)) {
if(!has_take_out) {
people[jieyue_count].book_number++;
cout << a[j].program[1] << a[j].program[2] << a[j].in_school_year << a[j].where_build << a[j].where_floor << a[j].where_fangwei << a[j].where_xingzhuang << a[j].where_hang << a[j].where_lie << a[j].where_book_count[1] << a[j].where_book_count[2] << a[j].where_book_count[3] << a[j].name << "\n";
people[jieyue_count].program[people[jieyue_count].book_number][1] = a[j].program[1];
people[jieyue_count].program[people[jieyue_count].book_number][2] = a[j].program[2];
people[jieyue_count].in_school_year[people[jieyue_count].book_number] = a[j].in_school_year;
people[jieyue_count].where_build[people[jieyue_count].book_number] = a[j].where_build;
people[jieyue_count].where_fangwei[people[jieyue_count].book_number] = a[j].where_fangwei;
people[jieyue_count].where_xingzhuang[people[jieyue_count].book_number] = a[j].where_xingzhuang;
people[jieyue_count].where_book_count[people[jieyue_count].book_number][1] = a[j].where_book_count[1];
people[jieyue_count].where_book_count[people[jieyue_count].book_number][2] = a[j].where_book_count[2];
people[jieyue_count].where_book_count[people[jieyue_count].book_number][3] = a[j].where_book_count[3];
people[jieyue_count].where_floor[people[jieyue_count].book_number] = a[j].where_floor;
people[jieyue_count].where_lie[people[jieyue_count].book_number] = a[j].where_lie;
people[jieyue_count].where_hang[people[jieyue_count].book_number] = a[j].where_hang;
}
else {
people[name_num].book_number++;
cout << a[j].program[1] << a[j].program[2] << a[j].in_school_year << a[j].where_build << a[j].where_floor << a[j].where_fangwei << a[j].where_xingzhuang << a[j].where_hang << a[j].where_lie << a[j].where_book_count[1] << a[j].where_book_count[2] << a[j].where_book_count[3] << a[j].name << "\n";
people[name_num].program[people[name_num].book_number][1] = a[j].program[1];
people[name_num].program[people[name_num].book_number][2] = a[j].program[2];
people[name_num].in_school_year[people[name_num].book_number] = a[j].in_school_year;
people[name_num].where_build[people[name_num].book_number] = a[j].where_build;
people[name_num].where_fangwei[people[name_num].book_number] = a[j].where_fangwei;
people[name_num].where_xingzhuang[people[name_num].book_number] = a[j].where_xingzhuang;
people[name_num].where_book_count[people[name_num].book_number][1] = a[j].where_book_count[1];
people[name_num].where_book_count[people[name_num].book_number][2] = a[j].where_book_count[2];
people[name_num].where_book_count[people[name_num].book_number][3] = a[j].where_book_count[3];
people[name_num].where_floor[people[name_num].book_number] = a[j].where_floor;
people[name_num].where_lie[people[name_num].book_number] = a[j].where_lie;
people[name_num].where_hang[people[name_num].book_number] = a[j].where_hang;
}
can_find = true;
a[j].out_book++;
a[j].many--;
break;
}
}
if (!can_find) {
cout << "对不起,您要借阅的书籍暂无。\n";
}
else if (people[jieyue_count].book_number == 10) {
cout << "您的借阅最大书籍数限制已到。\n";
}
else {
cout << "您要借阅的书籍已经被设为"借阅"模式!\n";
cout << "如果您还没有拿到这本书,请去:";
if(a[i].where_build == 'J') {
cout << "旧楼";
}else {
cout << "新楼";
}
cout << a[i].where_floor << "层";
if(a[i].where_fangwei == 'N') {
cout << "北区";
} else if(a[i].where_fangwei == 'S') {
cout << "南区";
} else if(a[i].where_fangwei == 'W') {
cout << "西区";
} else if(a[i].where_fangwei == 'E') {
cout << "东区";
} else {
cout << "中区";
}
if(a[i].where_xingzhuang == 'Z') {
cout << "直型书柜";
} else {
cout << "环形书柜";
}
cout << a[i].where_hang << "行" << a[i].where_hang << "列 第" << a[i].where_book_count[1] << a[i].where_book_count[2] << a[i].where_book_count[3] << "本书";
cout << "拿取,感谢您的配合。\n";
}
}
return;
}
inline void turn_back(){
printf("请输入您的名字:\n");
string name;
cin >> name;
int name_num = 0;
bool has_take_out = false;
for(int i = 1; i <= jieyue_count; i ++) {
if(people[i].name == name) {
has_take_out = true;
name_num = i;
break;
}
}
if(!has_take_out) {
printf("抱歉,您没有借阅图书!\n");
return;
}
printf("\n请输入还回本数:\n");
int book_much = 0;
cin >> book_much;
printf("\n请依次输入您要还回的书籍名称:\n");
for (int i = 1; i <= book_much; i++) {
string find_name;
scanf("\n");
cin >> find_name;
bool can_find = false;
int where = 0;
for (int j = 1; j <= book_count; j++) {
if (a[j].name == find_name && (a[j].out_book >= 1)) {
people[name_num].book_number--;
where = j;
cout << a[j].program[1] << a[j].program[2] << a[j].in_school_year << a[j].where_build << a[j].where_floor << a[j].where_fangwei << a[j].where_xingzhuang << a[j].where_hang << a[j].where_lie << a[j].where_book_count[1] << a[j].where_book_count[2] << a[j].where_book_count[3] << a[j].name << "\n";
people[name_num].program[people[name_num].book_number][1] = 0;
people[name_num].program[people[name_num].book_number][2] = 0;
people[name_num].in_school_year[people[name_num].book_number] = 0;
people[name_num].where_build[people[name_num].book_number] = 0;
people[name_num].where_fangwei[people[name_num].book_number] = 0;
people[name_num].where_xingzhuang[people[name_num].book_number] = 0;
people[name_num].where_book_count[people[name_num].book_number][1] = 0;
people[name_num].where_book_count[people[name_num].book_number][2] = 0;
people[name_num].where_book_count[people[name_num].book_number][3] = 0;
people[name_num].where_floor[people[name_num].book_number] = 0;
people[name_num].where_lie[people[name_num].book_number] = 0;
people[name_num].where_hang[people[name_num].book_number] = 0;
can_find = true;
a[j].out_book--;
a[j].many++;
break;
}
}
if (!can_find) {
cout << "对不起,您似乎没有借阅这本书。\n";
} else if(has_take_out){
cout << "您要还回的书籍已经被设为"馆藏"模式!\n";
cout << "如果您还没有归还这本书,请去:";
if(a[where].where_build == 'J') {
cout << "旧楼";
}else {
cout << "新楼";
}
cout << a[where].where_floor << "层";
if(a[where].where_fangwei == 'N') {
cout << "北区";
} else if(a[where].where_fangwei == 'S') {
cout << "南区";
} else if(a[where].where_fangwei == 'W') {
cout << "西区";
} else if(a[where].where_fangwei == 'E') {
cout << "东区";
} else {
cout << "中区";
}
if(a[where].where_xingzhuang == 'Z') {
cout << "直型书柜";
} else {
cout << "环形书柜";
}
cout << a[where].where_hang << "行" << a[where].where_hang << "列 第" << a[where].where_book_count[1] << a[where].where_book_count[2] << a[where].where_book_count[3]<< "本书";
cout << "归还,感谢您的配合。\n";
if(people[name_num].book_number == 0) {
cout << "您目前已还回所有书籍,欢迎您再来!\n";
}
} else {
cout << "您要还回的书籍已经被设为"馆藏"模式!\n";
cout << "如果您还没有归还这本书,请去:";
if(a[where].where_build == 'J') {
cout << "旧楼";
}else {
cout << "新楼";
}
cout << a[where].where_floor << "层";
if(a[where].where_fangwei == 'N') {
cout << "北区";
} else if(a[where].where_fangwei == 'S') {
cout << "南区";
} else if(a[where].where_fangwei == 'W') {
cout << "西区";
} else if(a[where].where_fangwei == 'E') {
cout << "东区";
} else {
cout << "中区";
}
if(a[where].where_xingzhuang == 'Z') {
cout << "直型书柜";
} else {
cout << "环形书柜";
}
cout << a[where].where_hang << "行" << a[where].where_hang << "列 第" << a[where].where_book_count[1] << a[where].where_book_count[2] << a[where].where_book_count[3]<< "本书";
cout << "归还,感谢您的配合。\n";
}
}
return;
}
inline void delete_book() {
printf("请输入要删除的书籍信息(例如:LS 2022J 3NZ 5 4 001 西安故事):\n");
char program[3];
string name;
int in_school_year;
char where_fangwei, where_xingzhuang, where_build, where_book_count[4];
int where_lie, where_hang, where_floor;
cin >> program[1] >> program[2] >> in_school_year >> where_build >> where_floor >> where_fangwei >> where_xingzhuang >> where_hang >> where_lie;
scanf(" ");
cin >> where_book_count[1] >> where_book_count[2] >> where_book_count[3];
scanf(" ");
cin >> name;
bool find_delete = false;
int where_delete = 0;
for(int i = 1; i <= book_count; i ++) {
if(a[i].program[1] == program[1] && a[i].program[2] == program[2] && a[i].in_school_year == in_school_year && a[i].where_build == where_build && a[i].where_floor == where_floor && a[i].where_fangwei == where_fangwei && a[i].where_lie == where_lie && a[i].where_hang == where_hang && a[i].where_xingzhuang == where_xingzhuang && a[i].name == name) {
find_delete = true;
where_delete = i;
break;
}
}
if(find_delete) {
printf("您确定要删除位于");
if(a[find_delete].where_build == 'J') {
cout << "旧楼";
}else {
cout << "新楼";
}
cout << a[find_delete].where_floor << "层";
if(a[find_delete].where_fangwei == 'N') {
cout << "北区";
} else if(a[find_delete].where_fangwei == 'S') {
cout << "南区";
} else if(a[find_delete].where_fangwei == 'W') {
cout << "西区";
} else if(a[find_delete].where_fangwei == 'E') {
cout << "东区";
} else {
cout << "中区";
}
if(a[find_delete].where_xingzhuang == 'Z') {
cout << "直型书柜";
} else {
cout << "环形书柜";
}
cout << a[find_delete].where_hang << "行" << a[find_delete].where_hang << "列 第" << a[find_delete].where_book_count[1] << a[find_delete].where_book_count[2] << a[find_delete].where_book_count[3] << "本书";
cout << "的这本书籍吗?(输入1(删除)或0(不删除))\n";
int YN = 0;
cin >> YN;
if(YN == 1) {
for(int i = where_delete + 1; i <= book_count; i ++) {
a[i - 1] = a[i];
}
book_count --;
printf("已删除!\n");
} else {
printf("已取消删除操作!\n");
}
} else {
printf("抱歉,暂无您要删除的书籍。\n");
}
return;
}
inline void hello_window(){
printf("\t\t 欢迎来到XXXX图书管理系统 \t\t\n");
printf("\t Welcome to XXXX Books Management System\t\t\n");
printf("\t\t XXX 监制 XXXX制作组 制作\t\t\n");
printf("\t Version/版本:XXXX \t\t\n");
printf("\t\t Tips:请勿乱操作"删除图书"功能,否则将会进行惩罚。 \t\t\n");
printf("\t\t XXX制作组成员:XXX");
printf("\n");
printf("\t\t\t 录入图书请按1 \t\t\n");
printf("\t\t\t 查找图书请按2 \t\t\n");
printf("\t\t\t 借阅图书请按3 \t\t\n");
printf("\t\t\t 还回图书请按4 \t\t\n");
printf("\t\t\t 删除图书请按5 \t\t\n");
printf("\t\t\t *_* 欢迎使用 \t\t\n");
printf("\n");
cin >> x;
if (x == '1') {
plus_book();
}
else if (x == '2') {
find_book();
}
else if (x == '3') {
take_out();
}
else if (x == '4') {
turn_back();
}
else if (x == '5') {
delete_book();
}
hello_window();
}
int main(){
hello_window();
}
若使用了我代码的部分,请提前向我说明,感谢各位的支持