在完成对C语言的学习后,我最近开始了对C++和Java的学习,目前跟着视频学习了一些语法,也跟着敲了一些代码,有了一定的掌握程度。现在将跟着视频做的笔记进行整理。本篇博客是整理C++知识点的第三十六篇博客。
本篇博客用C++实现了机房预约系统,本文是下部分。最后有总结,结束C++学习笔记系列。
本系列博客所有C++代码都在Visual Studio 2022环境下编译运行。程序为64位。
目录
接下来用C++实现一个机房预约系统,由于内容很长,分为三篇博客。本篇博客是第三部分。
- void student::look_my_reverse(void){
- ifstream ifs;
- ifs.open(REVERSE_FILE, ios::in);
- map<int, map
> mm; -
- string date;
- string time;
- string id;
- string name;
- string room;
- string status;
-
- while (ifs >> date && ifs >> time && ifs >> id && ifs >> name && ifs >> room && ifs >> status) {
- map
m; - string date1, date2;
- int pos;
- pos = date.find(":");
- date1 = date.substr(0, pos);
- date2 = date.substr(pos + 1, date.size() - pos - 1);
-
- if (date2 == "1") {
- m.insert(make_pair(date1, "Monday"));
- }
- else if (date2 == "2") {
- m.insert(make_pair(date1, "Tuesday"));
- }
- else if (date2 == "3") {
- m.insert(make_pair(date1, "Wednesday"));
- }
- else if (date2 == "4") {
- m.insert(make_pair(date1, "Thursday"));
- }
- else if (date2 == "5") {
- m.insert(make_pair(date1, "Friday"));
- }
-
- string time1, time2;
- pos = time.find(":");
- time1 = time.substr(0, pos);
- time2 = time.substr(pos + 1, time.size() - pos - 1);
- if (time2 == "1") {
- m.insert(make_pair(time1, "morning"));
- }
- else if (time2 == "2") {
- m.insert(make_pair(time1, "afternoon"));
- }
-
- string id1, id2;
- pos = id.find(":");
- id1 = id.substr(0, pos);
- id2 = id.substr(pos + 1, id.size() - pos - 1);
- if (atoi(id2.c_str()) != this->id) {
- m.clear();
- continue;
- }
- m.insert(make_pair(id1, id2));
-
- string name1, name2;
- pos = name.find(":");
- name1 = name.substr(0, pos);
- name2 = name.substr(pos + 1, name.size() - pos - 1);
- m.insert(make_pair(name1, name2));
-
- string room1, room2;
- pos = room.find(":");
- room1 = room.substr(0, pos);
- room2 = room.substr(pos + 1, room.size() - pos - 1);
- m.insert(make_pair(room1, room2));
-
- string status1, status2;
- pos = status.find(":");
- status1 = status.substr(0, pos);
- status2 = status.substr(pos + 1, status.size() - pos - 1);
- m.insert(make_pair(status1, status2));
-
- mm.insert(make_pair(mm.size() + 1, m));
- }
- if (mm.size() == 0) {
- cout << "No record" << endl;
- return;
- }
-
- for (map<int, map
>::iterator ait = mm.begin(); ait != mm.end(); ++ait) { - cout << "The number is " << ait->first << endl;
- for (map
::iterator bit = ait->second.begin(); bit != ait->second.end(); ++bit) { - cout << bit->first << ":" << bit->second << " ";
- }
- cout << endl;
- }
- ifs.close();
- system("pause");
- system("cls");
- }
这是student类的成员函数,创建了一个map容器mm,键为int类型,值为键和值都是string的map容器。随后遍历文件,对获取的信息进行处理,每次遍历都创建一个键和值是string的map容器m。将处理的信息加入m,每次循环结束后将当前的条数和m加入mm。如果id不是学生当前id,就结束本次循环,清空m。文件遍历完成后输出信息。
- void student::look_all_reverse(void){
- ifstream ifs;
- ifs.open(REVERSE_FILE, ios::in);
- map<int, map
> mm; -
- string date;
- string time;
- string id;
- string name;
- string room;
- string status;
-
- while (ifs >> date && ifs >> time && ifs >> id && ifs >> name && ifs >> room && ifs >> status) {
- map
m; - string date1, date2;
- int pos;
- pos = date.find(":");
- date1 = date.substr(0, pos);
- date2 = date.substr(pos + 1, date.size() - pos - 1);
-
- if (date2 == "1") {
- m.insert(make_pair(date1, "Monday"));
- }
- else if (date2 == "2") {
- m.insert(make_pair(date1, "Tuesday"));
- }
- else if (date2 == "3") {
- m.insert(make_pair(date1, "Wednesday"));
- }
- else if (date2 == "4") {
- m.insert(make_pair(date1, "Thursday"));
- }
- else if (date2 == "5") {
- m.insert(make_pair(date1, "Friday"));
- }
-
- string time1, time2;
- pos = time.find(":");
- time1 = time.substr(0, pos);
- time2 = time.substr(pos + 1, time.size() - pos - 1);
- if (time2 == "1") {
- m.insert(make_pair(time1, "morning"));
- }
- else if (time2 == "2") {
- m.insert(make_pair(time1, "afternoon"));
- }
-
- string id1, id2;
- pos = id.find(":");
- id1 = id.substr(0, pos);
- id2 = id.substr(pos + 1, id.size() - pos - 1);
- m.insert(make_pair(id1, id2));
-
- string name1, name2;
- pos = name.find(":");
- name1 = name.substr(0, pos);
- name2 = name.substr(pos + 1, name.size() - pos - 1);
- m.insert(make_pair(name1, name2));
-
- string room1, room2;
- pos = room.find(":");
- room1 = room.substr(0, pos);
- room2 = room.substr(pos + 1, room.size() - pos - 1);
- m.insert(make_pair(room1, room2));
-
- string status1, status2;
- pos = status.find(":");
- status1 = status.substr(0, pos);
- status2 = status.substr(pos + 1, status.size() - pos - 1);
- m.insert(make_pair(status1, status2));
-
- mm.insert(make_pair(mm.size() + 1, m));
- }
- ifs.close();
-
- for (map<int, map
>::iterator ait = mm.begin(); ait != mm.end(); ++ait) { - cout << "The number is " << ait->first << endl;
- for (map
::iterator bit = ait->second.begin(); bit != ait->second.end(); ++bit) { - cout << bit->first << ":" << bit->second << " ";
- }
- cout << endl;
- }
- ifs.close();
- system("pause");
- system("cls");
- }
这一部分和上一部分基本完全一样,就是不再筛选学号是否为当前学号。
- void student::cancel_reverse(){
- int i = 0;
- map<int, int>kv;
- ifstream ifs;
- ifs.open(REVERSE_FILE, ios::in);
- map<int, map
> mm; -
- string date;
- string time;
- string id;
- string name;
- string room;
- string status;
-
- while (ifs >> date && ifs >> time && ifs >> id && ifs >> name && ifs >> room && ifs >> status) {
- map
m; - string date1, date2;
- int pos;
- pos = date.find(":");
- date1 = date.substr(0, pos);
- date2 = date.substr(pos + 1, date.size() - pos - 1);
-
- if (date2 == "1") {
- m.insert(make_pair(date1, "Monday"));
- }
- else if (date2 == "2") {
- m.insert(make_pair(date1, "Tuesday"));
- }
- else if (date2 == "3") {
- m.insert(make_pair(date1, "Wednesday"));
- }
- else if (date2 == "4") {
- m.insert(make_pair(date1, "Thursday"));
- }
- else if (date2 == "5") {
- m.insert(make_pair(date1, "Friday"));
- }
-
- string time1, time2;
- pos = time.find(":");
- time1 = time.substr(0, pos);
- time2 = time.substr(pos + 1, time.size() - pos - 1);
- if (time2 == "1") {
- m.insert(make_pair(time1, "morning"));
- }
- else if (time2 == "2") {
- m.insert(make_pair(time1, "afternoon"));
- }
-
- string id1, id2;
- pos = id.find(":");
- id1 = id.substr(0, pos);
- id2 = id.substr(pos + 1, id.size() - pos - 1);
- m.insert(make_pair(id1, id2));
-
- string name1, name2;
- pos = name.find(":");
- name1 = name.substr(0, pos);
- name2 = name.substr(pos + 1, name.size() - pos - 1);
- m.insert(make_pair(name1, name2));
-
- string room1, room2;
- pos = room.find(":");
- room1 = room.substr(0, pos);
- room2 = room.substr(pos + 1, room.size() - pos - 1);
- m.insert(make_pair(room1, room2));
-
- string status1, status2;
- pos = status.find(":");
- status1 = status.substr(0, pos);
- status2 = status.substr(pos + 1, status.size() - pos - 1);
- m.insert(make_pair(status1, status2));
-
- mm.insert(make_pair(mm.size() + 1, m));
- if (atoi(id2.c_str()) == this->id && (status2 == "adopted" || status2 == "auditing")) {
- i += 1;
- kv.insert(make_pair(i, mm.size()));
- }
- }
- ifs.close();
-
- for (map<int, int>::iterator iiit = kv.begin(); iiit != kv.end(); ++iiit) {
- cout << "The number is " << iiit->first << endl;
- for (map<int, map
>::iterator ait = mm.begin(); ait != mm.end(); ++ait) { - if (iiit->second == ait->first) {
- for (map
::iterator bit = ait->second.begin(); bit != ait->second.end(); ++bit) { - cout << bit->first << ":" << bit->second << " ";
- }
- }
- }
- cout << endl;
- }
-
- while (true) {
- cout << "Please enter the number to cancel,0 to exit" << endl;
- int choice;
- cin >> choice;
- if (choice == 0) {
- break;
- }else if(choice > 0 && choice <= kv.size()) {
- for (map<int, int>::iterator iiit = kv.begin(); iiit != kv.end(); ++iiit) {
- if (iiit->first == choice) {
- for (map<int, map
>::iterator ait = mm.begin(); ait != mm.end(); ++ait) { - if (iiit->second == ait->first) {
- int i = 0;
- for (map
::iterator bit = ait->second.begin(); bit != ait->second.end(); ++bit) { - if (i == 4) {
- bit->second = "cancelled";
- }
- i += 1;
- }
- }
- }
- }
- }
-
- for (map<int, map
>::iterator ait = mm.begin(); ait != mm.end(); ++ait) { - cout << "The number is " << ait->first << endl;
- for (map
::iterator bit = ait->second.begin(); bit != ait->second.end(); ++bit) { - cout << bit->first << ":" << bit->second << " ";
- }
- cout << endl;
- }
- cout << "Done" << endl;
-
- ofstream ofs;
- ofs.open(REVERSE_FILE, ios::trunc);
- ofs.close();
- ofs.open(REVERSE_FILE, ios::in);
-
- for (map<int, map
>::iterator ait = mm.begin(); ait != mm.end(); ++ait) { - int i = 0;
- int daychoice;
- string tempid;
- string tempname;
- string roomchoice;
- string status;
- int timechoice;
- for (map
::iterator bit = ait->second.begin(); bit != ait->second.end(); ++bit) { - if (i == 0) {
- if (bit->second == "Monday") {
- daychoice = 1;
- }
- else if (bit->second == "Tuesday") {
- daychoice = 2;
- }
- else if (bit->second == "Wednesday") {
- daychoice = 3;
- }
- else if (bit->second == "Thursday") {
- daychoice = 4;
- }
- else if (bit->second == "Friday") {
- daychoice = 5;
- }
- }
- else if (i == 1) {
- tempid = bit->second;
- }
- else if (i == 2) {
- tempname = bit->second;
- }
- else if (i == 3) {
- roomchoice = bit->second;
- }
- else if (i == 4) {
- status = bit->second;
- }
- else if (i == 5) {
- if (bit->second == "morning") {
- timechoice = 1;
- }
- else if(bit->second == "afternoon") {
- timechoice = 2;
- }
- }
- i += 1;
- }
- ofs << "date:" << daychoice << " " << " time:" << timechoice << " " << " id:" << tempid << " ";
- ofs << " name:" << tempname << " " << " room:" << roomchoice << " " << " status:" << status << endl;
- }
- break;
- }
- else {
- cout << "Please enter the right choice" << endl;
- }
- }
- system("pause");
- system("cls");
- }
这是student类的成员函数。创建了一个map容器mm,键为int类型,值为键和值都是string的map容器。还有一个map容器kv,键和值都是int类型。随后遍历文件,对获取的信息进行处理,每次遍历都创建一个键和值是string的map容器m。将处理的信息加入m,每次循环结束后将当前的条数和m加入mm。如果学号是学生当前学号,并且状态是待审核或者审核通过,就将当前mm的大小作为值,满足当前条件的信息数作为键加入kv。
随后大循环遍历kv,小循环遍历mm,只有mm当前的键是kv当前的值时,才会输出信息。就是做到信息对应。
然后用户要选择取消的条目,条目的总数就是kv的元素个数,不能超过这个个数。输入0就代表不取消任何记录,输入错误要求重新输入。输入正确后,选项就代表kv的键,找到这个键在kv中对应的值,然后找到此值在mm中对应的键,然后将状态改为已取消。
然后显示修改后的内容,清空文件原来的内容并重新写入。
个人感觉这一部分当初写得不好,太麻烦,但是后来也没改。后面还有一处极为类似的代码。
- void do_teacher(identity* person)
- {
- cout << "Welcome " << person->name << '!' << endl;
- teacher* tea = (teacher*)person;
- while (true) {
- tea->show_menu();
- int choice;
- cout << "Please enter your choice " << endl;
- cin >> choice;
-
- if (choice == 1) {
- tea->look_reverse();
- }
- else if (choice == 2) {
- tea->audit_reverse();
- }
- else if (choice == 0) {
- delete tea;
- cout << "Have logged out" << endl;
- system("pause");
- system("cls");
- break;
- }
- else {
- cout << "Enter error, please enter 1,2 or 0" << endl;
- system("pause");
- system("cls");
- }
- }
- }
这是reservesystem.cpp中的内容。首先给出提示欢迎用户,然后将多态的指针向下转型,以调用子类的成员函数。随后进入循环,给出菜单并要求用户选择选项,每个选项进入不同的成员函数,输入0就销毁此指针并表示注销,随后退出此函数。输入其他选项就要求用户重新输入。
- void teacher::show_menu()
- {
- cout << "****************************************" << endl;
- cout << "********** 1. look reservation *********" << endl;
- cout << "********** 2. audit reservation ********" << endl;
- cout << "********** 0. log out ******************" << endl;
- cout << "****************************************" << endl;
- }
这是teacher类的成员函数,显示菜单。
- void teacher::look_reverse(void)
- {
- ifstream ifs;
- ifs.open(REVERSE_FILE, ios::in);
- map<int, map
> mm; -
- string date;
- string time;
- string id;
- string name;
- string room;
- string status;
-
- while (ifs >> date && ifs >> time && ifs >> id && ifs >> name && ifs >> room && ifs >> status) {
- map
m; - string date1, date2;
- int pos;
- pos = date.find(":");
- date1 = date.substr(0, pos);
- date2 = date.substr(pos + 1, date.size() - pos - 1);
-
- if (date2 == "1") {
- m.insert(make_pair(date1, "Monday"));
- }
- else if (date2 == "2") {
- m.insert(make_pair(date1, "Tuesday"));
- }
- else if (date2 == "3") {
- m.insert(make_pair(date1, "Wednesday"));
- }
- else if (date2 == "4") {
- m.insert(make_pair(date1, "Thursday"));
- }
- else if (date2 == "5") {
- m.insert(make_pair(date1, "Friday"));
- }
-
- string time1, time2;
- pos = time.find(":");
- time1 = time.substr(0, pos);
- time2 = time.substr(pos + 1, time.size() - pos - 1);
- if (time2 == "1") {
- m.insert(make_pair(time1, "morning"));
- }
- else if (time2 == "2") {
- m.insert(make_pair(time1, "afternoon"));
- }
-
- string id1, id2;
- pos = id.find(":");
- id1 = id.substr(0, pos);
- id2 = id.substr(pos + 1, id.size() - pos - 1);
- m.insert(make_pair(id1, id2));
-
- string name1, name2;
- pos = name.find(":");
- name1 = name.substr(0, pos);
- name2 = name.substr(pos + 1, name.size() - pos - 1);
- m.insert(make_pair(name1, name2));
-
- string room1, room2;
- pos = room.find(":");
- room1 = room.substr(0, pos);
- room2 = room.substr(pos + 1, room.size() - pos - 1);
- m.insert(make_pair(room1, room2));
-
- string status1, status2;
- pos = status.find(":");
- status1 = status.substr(0, pos);
- status2 = status.substr(pos + 1, status.size() - pos - 1);
- m.insert(make_pair(status1, status2));
-
- mm.insert(make_pair(mm.size() + 1, m));
- }
- ifs.close();
-
- for (map<int, map
>::iterator ait = mm.begin(); ait != mm.end(); ++ait) { - cout << "The number is " << ait->first << endl;
- for (map
::iterator bit = ait->second.begin(); bit != ait->second.end(); ++bit) { - cout << bit->first << ":" << bit->second << " ";
- }
- cout << endl;
- }
- ifs.close();
- system("pause");
- system("cls");
- }
这个功能上面实现过了,这里就不再详细解释了。
- void teacher::audit_reverse(void)
- {
- int i = 0;
- map<int, int>kv;
- ifstream ifs;
- ifs.open(REVERSE_FILE, ios::in);
- map<int, map
> mm; -
- string date;
- string time;
- string id;
- string name;
- string room;
- string status;
-
- while (ifs >> date && ifs >> time && ifs >> id && ifs >> name && ifs >> room && ifs >> status) {
- map
m; - string date1, date2;
- int pos;
- pos = date.find(":");
- date1 = date.substr(0, pos);
- date2 = date.substr(pos + 1, date.size() - pos - 1);
-
- if (date2 == "1") {
- m.insert(make_pair(date1, "Monday"));
- }
- else if (date2 == "2") {
- m.insert(make_pair(date1, "Tuesday"));
- }
- else if (date2 == "3") {
- m.insert(make_pair(date1, "Wednesday"));
- }
- else if (date2 == "4") {
- m.insert(make_pair(date1, "Thursday"));
- }
- else if (date2 == "5") {
- m.insert(make_pair(date1, "Friday"));
- }
-
- string time1, time2;
- pos = time.find(":");
- time1 = time.substr(0, pos);
- time2 = time.substr(pos + 1, time.size() - pos - 1);
- if (time2 == "1") {
- m.insert(make_pair(time1, "morning"));
- }
- else if (time2 == "2") {
- m.insert(make_pair(time1, "afternoon"));
- }
-
- string id1, id2;
- pos = id.find(":");
- id1 = id.substr(0, pos);
- id2 = id.substr(pos + 1, id.size() - pos - 1);
- m.insert(make_pair(id1, id2));
-
- string name1, name2;
- pos = name.find(":");
- name1 = name.substr(0, pos);
- name2 = name.substr(pos + 1, name.size() - pos - 1);
- m.insert(make_pair(name1, name2));
-
- string room1, room2;
- pos = room.find(":");
- room1 = room.substr(0, pos);
- room2 = room.substr(pos + 1, room.size() - pos - 1);
- m.insert(make_pair(room1, room2));
-
- string status1, status2;
- pos = status.find(":");
- status1 = status.substr(0, pos);
- status2 = status.substr(pos + 1, status.size() - pos - 1);
- m.insert(make_pair(status1, status2));
-
- mm.insert(make_pair(mm.size() + 1, m));
- if (status2 == "auditing") {
- i += 1;
- kv.insert(make_pair(i, mm.size()));
- }
- }
- ifs.close();
-
- if (kv.size() == 0) {
- cout << "No record to be audited" << endl;
- return;
- }
-
- while (true) {
- for (map<int, int>::iterator iiit = kv.begin(); iiit != kv.end(); ++iiit) {
- cout << "The number is " << iiit->first << endl;
- for (map<int, map
>::iterator ait = mm.begin(); ait != mm.end(); ++ait) { - if (iiit->second == ait->first) {
- for (map
::iterator bit = ait->second.begin(); bit != ait->second.end(); ++bit) { - cout << bit->first << ":" << bit->second << " ";
- }
- }
- }
- cout << endl;
- }
-
- cout << "Please enter the number to audit,0 to exit" << endl;
- int choice;
- cin >> choice;
- if (choice == 0) {
- break;
- }
- else if (choice > 0 && choice <= kv.size()) {
- int audit;
- while (true) {
- cout << "Please enter the audit" << endl;
- cout << "1.yes 2.no" << endl;
- cin >> audit;
-
- if (audit == 1 || audit == 2) {
- break;
- }
- else {
- cout << "Please enter 1 or 2" << endl;
- }
- }
-
- for (map<int, int>::iterator iiit = kv.begin(); iiit != kv.end(); ++iiit) {
- if (iiit->first == choice) {
- for (map<int, map
>::iterator ait = mm.begin(); ait != mm.end(); ++ait) { - if (iiit->second == ait->first) {
- int i = 0;
- for (map
::iterator bit = ait->second.begin(); bit != ait->second.end(); ++bit) { - if (i == 4&&audit == 1) {
- bit->second = "adopted";
- }
- else if(i ==4 && audit == 2) {
- bit->second = "refused";
- }
- i += 1;
- }
- }
- }
- }
- }
-
- for (map<int, map
>::iterator ait = mm.begin(); ait != mm.end(); ++ait) { - cout << "The number is " << ait->first << endl;
- for (map
::iterator bit = ait->second.begin(); bit != ait->second.end(); ++bit) { - cout << bit->first << ":" << bit->second << " ";
- }
- cout << endl;
- }
- cout << "Done" << endl;
-
- ofstream ofs;
- ofs.open(REVERSE_FILE, ios::trunc);
- ofs.close();
- ofs.open(REVERSE_FILE, ios::in);
-
- for (map<int, map
>::iterator ait = mm.begin(); ait != mm.end(); ++ait) { - int i = 0;
- int daychoice;
- string tempid;
- string tempname;
- string roomchoice;
- string status;
- int timechoice;
- for (map
::iterator bit = ait->second.begin(); bit != ait->second.end(); ++bit) { - if (i == 0) {
- if (bit->second == "Monday") {
- daychoice = 1;
- }
- else if (bit->second == "Tuesday") {
- daychoice = 2;
- }
- else if (bit->second == "Wednesday") {
- daychoice = 3;
- }
- else if (bit->second == "Thursday") {
- daychoice = 4;
- }
- else if (bit->second == "Friday") {
- daychoice = 5;
- }
- }
- else if (i == 1) {
- tempid = bit->second;
- }
- else if (i == 2) {
- tempname = bit->second;
- }
- else if (i == 3) {
- roomchoice = bit->second;
- }
- else if (i == 4) {
- status = bit->second;
- }
- else if (i == 5) {
- if (bit->second == "morning") {
- timechoice = 1;
- }
- else if (bit->second == "afternoon") {
- timechoice = 2;
- }
- }
- i += 1;
- }
- ofs << "date:" << daychoice << " " << " time:" << timechoice << " " << " id:" << tempid << " ";
- ofs << " name:" << tempname << " " << " room:" << roomchoice << " " << " status:" << status << endl;
- }
- ofs.close();
- }
- else {
- cout << "Please enter the right choice" << endl;
- }
- kv.clear();
- mm.clear();
- int i = 0;
- ifs.open(REVERSE_FILE, ios::in);
-
- string date;
- string time;
- string id;
- string name;
- string room;
- string status;
-
- while (ifs >> date && ifs >> time && ifs >> id && ifs >> name && ifs >> room && ifs >> status) {
- map
m; - string date1, date2;
- int pos;
- pos = date.find(":");
- date1 = date.substr(0, pos);
- date2 = date.substr(pos + 1, date.size() - pos - 1);
-
- if (date2 == "1") {
- m.insert(make_pair(date1, "Monday"));
- }
- else if (date2 == "2") {
- m.insert(make_pair(date1, "Tuesday"));
- }
- else if (date2 == "3") {
- m.insert(make_pair(date1, "Wednesday"));
- }
- else if (date2 == "4") {
- m.insert(make_pair(date1, "Thursday"));
- }
- else if (date2 == "5") {
- m.insert(make_pair(date1, "Friday"));
- }
-
- string time1, time2;
- pos = time.find(":");
- time1 = time.substr(0, pos);
- time2 = time.substr(pos + 1, time.size() - pos - 1);
- if (time2 == "1") {
- m.insert(make_pair(time1, "morning"));
- }
- else if (time2 == "2") {
- m.insert(make_pair(time1, "afternoon"));
- }
-
- string id1, id2;
- pos = id.find(":");
- id1 = id.substr(0, pos);
- id2 = id.substr(pos + 1, id.size() - pos - 1);
- m.insert(make_pair(id1, id2));
-
- string name1, name2;
- pos = name.find(":");
- name1 = name.substr(0, pos);
- name2 = name.substr(pos + 1, name.size() - pos - 1);
- m.insert(make_pair(name1, name2));
-
- string room1, room2;
- pos = room.find(":");
- room1 = room.substr(0, pos);
- room2 = room.substr(pos + 1, room.size() - pos - 1);
- m.insert(make_pair(room1, room2));
-
- string status1, status2;
- pos = status.find(":");
- status1 = status.substr(0, pos);
- status2 = status.substr(pos + 1, status.size() - pos - 1);
- m.insert(make_pair(status1, status2));
-
- mm.insert(make_pair(mm.size() + 1, m));
- if (status2 == "auditing") {
- i += 1;
- kv.insert(make_pair(i, mm.size()));
- }
- }
- ifs.close();
-
- if (kv.size() == 0) {
- cout << "No record to be audited" << endl;
- system("pause");
- system("cls");
- return;
- }
- }
- system("pause");
- system("cls");
- }
这一部分代码实现和上面的学生取消预约是类似的,这里只说一下不同的地方。同样这一处设计也不行,当初赶工后的结果。
首先,加入kv的计数原则改为状态在审核中的条目。然后这里设计了循环,每次循环的开头显示审核中的信息,并要求用户输入要决定的选项。输入0退出,然后条目的编号同样不能大于kv的元素个数。然后是输入1表示同意输入2表示拒绝,随后修改相关的条目。然后是输出修改后信息,写入文件。最后,由于在每次循环开头输出信息,因此在完成这一系列操作后,要从文件中将信息读取,覆盖原来容器的内容。
那么现在机房预约系统也结束了,虽然像上面提到的一样,两个地方的代码太多,但是整体还可以,这个有一定的难度。
那么C++的所有三十六篇笔记就结束了,从8月4日到现在,用了大约二十天,将前面看视频的笔记整理了一下。在文章划分上,尽量将同一块知识点放在一块。现在对C++有了一定的掌握程度,接下来就该看书进阶了。就目前知识来讲C++确实有一定难度,后面的进阶只会更难。现在我已经线上大二开学,在家上网课,估计会上不到一个月网课。总之,接下来该继续努力了。