cppHomework/Manager.cpp

908 lines
19 KiB
C++
Raw Normal View History

2023-09-02 07:36:45 +00:00
#include "Manager.h"
#include"Exceptions.h"
#pragma warning(disable:4996)
Manager::Manager() {
centeredPrint("##########################################");
centeredPrint("## ѧ<><D1A7><EFBFBD>ɼ<EFBFBD><C9BC><EFBFBD><EFBFBD><EFBFBD>ϵͳ ##");
centeredPrint("##########################################");
cout << endl;
centeredPrint("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>...");
ifstream numsin("nums.bin", ios::in, ios::binary);
if (!numsin.good()) {
ExamNum = 0;
StudentNum = 0;
numsin.close();
return;
}
numsin.read((char*)&StudentNum, sizeof(int));
numsin.read((char*)&ExamNum, sizeof(int));
numsin.close();
ifstream studentsin("students.bin", ios::in, ios::binary);
Student tmpstu;
for (int i = 0; i < StudentNum; i++) {
studentsin.read((char*)&tmpstu, sizeof(Student));
Students.push_back(tmpstu);
}
studentsin.close();
ifstream examsin("examsaves.bin", ios::in, ios::binary);
Examsave tmpexam;
for (int i = 0; i < ExamNum; i++) {
examsin.read((char*)&tmpexam, sizeof(Examsave));
auto sp1 = make_shared<Exam>(&tmpexam);
Exams.push_back(sp1);
}
examsin.close();
cout << endl;
centeredPrint("<EFBFBD><EFBFBD>ӭʹ<EFBFBD><EFBFBD>!");
}
Manager::~Manager() {
centeredPrint("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>...");
ofstream examsout("examsaves.bin", ios::out, ios::binary);
for (auto i = Exams.begin(); i < Exams.end(); i++) {
(*i)->saveAll(examsout);
}
ExamNum = Exams.size();
examsout.close();
ofstream studentsout("students.bin", ios::out, ios::binary);
for (auto i = Students.begin(); i < Students.end(); i++) {
studentsout.write((char*)&(*i), sizeof(Student));
}
StudentNum = Students.size();
studentsout.close();
ofstream numsout("nums.bin", ios::out, ios::binary);
numsout.write((char*)&StudentNum, sizeof(int));
numsout.write((char*)&ExamNum, sizeof(int));
numsout.close();
centeredPrint("<EFBFBD>ѱ<EFBFBD><EFBFBD>");
}
void Manager::mainLoop() {
while (1) {
try {
switch (status) {
case 0:
welcomePage();
break;
case 1:
stuPage();
break;
case 11:
stuDspPage();
break;
case 12:
stuAddPage();
break;
case 13:
stuSearchPage();
break;
case 14:
stuEdtRmvPage();
break;
case 15:
stuExportPage();
break;
case 16:
stuImportPage();
break;
case 2:
examPage();
break;
case 21:
examAddPage();
break;
case 22:
examChoosePage();
break;
case 23:
examSubPage();
break;
case 231:
examViewPage();
break;
case 232:
examExportPage();
break;
case 233:
examAddRowPage();
break;
case 234:
examDelRowPage();
break;
case 235:
examNamePage();
break;
case 236:
examImportPage();
break;
case 237:
examRmvPage();
break;
case 3:
stuPfmPage();
break;
}
system("cls");
if (status == -1)
break;
}
catch (const InputError& e) {
system("cls");
cerr << e.what() << endl;
cin.clear();
cin.ignore(1024,'\n');
goBack();
}
catch (const FileError& e) {
system("cls");
cerr << e.what() << endl;
goBack();
}
catch (const IndexError& e) {
system("cls");
cerr << e.what() << endl;
goBack();
}
}
}
void Manager::goBack() {
status /= 10;
}
void Manager::centeredPrint(const string& content) {
HANDLE hOutput = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO bInfo;
GetConsoleScreenBufferInfo(hOutput, &bInfo);
int dwSizeX = bInfo.dwSize.X, dwSizeY = bInfo.dwSize.Y;
int cursorX = bInfo.dwCursorPosition.X, cursorY = bInfo.dwCursorPosition.Y;
int len = content.length();
COORD pos;
pos.X = (dwSizeX - len) / 2;
pos.Y = cursorY;
SetConsoleCursorPosition(hOutput, pos);
cout << content << endl;
}
Student* Manager::searchByNo(long long int studentNo) {
for (auto i = Students.begin(); i < Students.end(); i++) {
if (i->stuNoEqual(studentNo)) {
return &(*i);
}
}
return nullptr;
}
//status 0
void Manager::welcomePage() {
char choice = '0';
cout << "<EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD>" << endl;
cout << "<EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD>" << endl;
cout << "1: ѧ<><D1A7><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD>" << endl;
cout << "2: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ" << endl;
cout << "3: ѧ<><D1A7><EFBFBD>ɼ<EFBFBD><C9BC><EFBFBD>ѯ" << endl;
cout << "q: <20>˳<EFBFBD>" << endl;
cin >> choice;
switch (choice) {
case '1':
status = 1;
break;
case '2':
status = 2;
break;
case '3':
status = 3;
break;
case 'q':
case 'Q':
status = -1;
break;
}
}
//status 1
void Manager::stuPage() {
char choice = '0';
cout << "<EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><><D1A7>" << endl;
cout << "<EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD>" << endl;
cout << "1: ȫ<><C8AB>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD>Ϣ" << endl;
cout << "2: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><D1A7>" << endl;
cout << "3: ѧ<><D1A7><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD>" << endl;
cout << "4: <20>༭/ɾ<><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><D1A7>" << endl;
cout << "5: <20><>ȫ<EFBFBD><C8AB>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>CSV" << endl;
cout << "6: <20><>CSV<53><56><EFBFBD><EFBFBD>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD>Ϣ" << endl;
cout << "b: <20><><EFBFBD><EFBFBD>" << endl;
cin >> choice;
switch (choice) {
case '1':
status = 11;
break;
case '2':
status = 12;
break;
case '3':
status = 13;
break;
case '4':
status = 14;
break;
case '5':
status = 15;
break;
case '6':
status = 16;
break;
case 'b':
case 'B':
goBack();
}
}
//status 11
void Manager::stuDspPage() {
cout << "<EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><><D1A7>-<2D><>Ϣ<EFBFBD>" << endl;
cout << setw(6) << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
Student::dspHeader();
cout << endl;
int count = 1;
for (auto student = Students.begin(); student < Students.end(); student++) {
cout << setw(6) << count++;
student->dsp();
cout << endl;
}
string tmp;
cout << endl << "b: <20><><EFBFBD><EFBFBD>" << endl;
cin >> tmp;
goBack();
}
//status 12
void Manager::stuAddPage() {
char choice = '0';
cout << "<EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><><D1A7>-<2D><><EFBFBD><EFBFBD>" << endl;
int year;
int selectionNo;
int classNo;
char name[100];
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>:" << endl;
do {
cin.getline(name, 100);
} while (name[0] == '\0');
cout << "<EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>:" << endl;
cin >> year;
cout << "ѡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:" << endl;
cin >> selectionNo;
cout << "<EFBFBD>༶:" << endl;
cin >> classNo;
if (!cin.good()) {
throw InputError("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD>Ƿ<EFBFBD>!");
}
Students.push_back(Student(year, selectionNo, classNo, name));
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӣ<EFBFBD>" << endl;
string tmp;
cout << endl << "b: <20><><EFBFBD><EFBFBD>" << endl;
cin >> tmp;
goBack();
}
//status 13
void Manager::stuSearchPage() {
char choice = '0';
cout << "<EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><><D1A7>-<2D><><EFBFBD><EFBFBD>" << endl;
cout << "<EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD>:" << endl;
cout << "1: <20><>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" << endl;
cout << "2: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" << endl;
cout << "3: <20><><EFBFBD><EFBFBD><E0BCB6><EFBFBD><EFBFBD>" << endl;
cout << "4: <20><>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" << endl;
cout << "5: <20><><EFBFBD><EFBFBD>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" << endl;
cout << "b: <20><><EFBFBD><EFBFBD>" << endl;
cin >> choice;
vector<Student> result;
int enrollmentYear;
switch (choice) {
case '1':
long long int inputNo;
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD>:";
cin >> inputNo;
if (!cin.good()) {
throw InputError("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD>Ƿ<EFBFBD>!");
}
for (auto stu = Students.begin(); stu < Students.end(); stu++) {
if (stu->stuNoEqual(inputNo)) {
result.push_back(*stu);
}
}
break;
case '2':
char inputName[100];
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:";
do {
cin.getline(inputName, 100);
} while (inputName[0] == '\0');
for (auto stu = Students.begin(); stu < Students.end(); stu++) {
if (stu->nameEqual(inputName)) {
result.push_back(*stu);
}
}
break;
case '3':
int inputClassNo;
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>:";
cin >> enrollmentYear;
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>༶:";
cin >> inputClassNo;
if (!cin.good()) {
throw InputError("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD>Ƿ<EFBFBD>!");
}
for (auto stu = Students.begin(); stu < Students.end(); stu++) {
if (stu->clsNoEqual(inputClassNo) && stu->yearEqual(enrollmentYear)) {
result.push_back(*stu);
}
}
break;
case '4':
int inputSelectionNo;
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>:";
cin >> enrollmentYear;
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:";
cin >> inputSelectionNo;
if (!cin.good()) {
throw InputError("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD>Ƿ<EFBFBD>!");
}
for (auto stu = Students.begin(); stu < Students.end(); stu++) {
if (stu->slcNoEqual(inputSelectionNo) && stu->yearEqual(enrollmentYear)) {
result.push_back(*stu);
}
}
break;
case '5':
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>:";
cin >> enrollmentYear;
if (!cin.good()) {
throw InputError("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD>Ƿ<EFBFBD>!");
}
for (auto stu = Students.begin(); stu < Students.end(); stu++) {
if (stu->yearEqual(enrollmentYear)) {
result.push_back(*stu);
}
}
break;
case 'b':
case 'B':
goBack();
}
if (status != 1) {
cout << setw(6) << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
Student::dspHeader();
cout << endl;
int count = 1;
for (auto student = result.begin(); student < result.end(); student++) {
cout << setw(6) << count++;
student->dsp();
cout << endl;
}
cout << endl;
if (result.size() == 0) {
cout << "δ<EFBFBD>ҵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD>" << endl;
}
cout << "b: <20><><EFBFBD><EFBFBD>" << endl;
string tmp;
cin >> tmp;
goBack();
}
}
//status 14
void Manager::stuEdtRmvPage() {
int inputNo;
string tmp;
cout << "<EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><><D1A7>-<2D>༭/ɾ<><C9BE>" << endl;
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD>:";
cin >> inputNo;
if (!cin.good()) {
throw InputError("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD>Ƿ<EFBFBD>!");
}
auto it = Students.end();
for (auto stu = Students.begin(); stu < Students.end(); stu++) {
if (stu->stuNoEqual(inputNo)) {
it = stu;
}
}
if (it == Students.end()) {
cout << "<EFBFBD><EFBFBD><EFBFBD>޴<EFBFBD><EFBFBD><EFBFBD>" << endl;
cout << "b: <20><><EFBFBD><EFBFBD>" << endl;
cin >> tmp;
goBack();
}
else {
char choice;
cout << "1: <20>༭ѧ<E0BCAD><D1A7><EFBFBD><EFBFBD>Ϣ" << endl;
cout << "2: ɾ<><C9BE>" << endl;
cin >> choice;
Student::dspHeader();
cout << endl;
it->dsp();
cout << endl;
if (choice == '1') {
int year;
int selectionNo;
int classNo;
char name[100];
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>:" << endl;
do {
cin.getline(name, 100);
} while (name[0] == '\0');
cout << "<EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>:" << endl;
cin >> year;
cout << "ѡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:" << endl;
cin >> selectionNo;
cout << "<EFBFBD>༶:" << endl;
cin >> classNo;
if (!cin.good()) {
throw InputError("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD>Ƿ<EFBFBD>!");
}
it->setInfo(year, selectionNo, classNo, name);
cout << "<EFBFBD><EFBFBD><EFBFBD>޸<EFBFBD>" << endl;
}
else if (choice == '2') {
cout << "ɾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD>?(Y(<28><>)/N(<28><>))" << endl;
char yorn;
cin >> yorn;
if (yorn == 'y' || yorn == 'Y') {
Students.erase(it);
}
cout << "<EFBFBD><EFBFBD>ɾ<EFBFBD><EFBFBD>" << endl;
}
cout << "b: <20><><EFBFBD><EFBFBD>" << endl;
string tmp;
cin >> tmp;
goBack();
}
}
//status 15
void::Manager::stuExportPage() {
cout << "<EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><><D1A7>-<2D><><EFBFBD><EFBFBD>" << endl;
string csvName;
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>:" << endl;
do {
getline(cin, csvName);
} while (csvName == "");
csvName = csvName + ".csv";
ofstream csv(csvName);
if (!csv.good()) {
throw FileError("<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>!");
}
Student::toCsvHeader(csv);
csv << '\n';
for (auto student = Students.begin(); student < Students.end(); student++) {
student->toCsv(csv);
csv << '\n';
}
string tmp;
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>" << endl;
cout << "b: <20><><EFBFBD><EFBFBD>" << endl;
cin >> tmp;
goBack();
}
//status 16
void::Manager::stuImportPage() {
string fileName;
string tmp;
bool eof = false;
int firstRow=1;
int clsColumn, slcColumn, yearColumn,nameColumn;
cout << "<EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><><D1A7>-<2D><><EFBFBD><EFBFBD>" << endl;
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƻ<EFBFBD>·<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>չ<EFBFBD><EFBFBD>" << endl;
cin >> fileName;
if (!cin.good()) {
throw InputError("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD>Ƿ<EFBFBD>!");
}
ifstream csvFile(fileName);
if (!csvFile.good()) {
throw FileError("<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>!");
}
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: " << endl;
cin >> firstRow;
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: " << endl;
cin >> nameColumn;
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: " << endl;
cin >> yearColumn;
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: " << endl;
cin >> clsColumn;
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: " << endl;
cin >> slcColumn;
if (!cin.good()) {
throw InputError("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD>Ƿ<EFBFBD>!");
}
for (int i = 1; i < firstRow; i++) {
getline(csvFile, tmp);
}
while (!eof) {
Student tmpStu(csvFile, yearColumn, clsColumn, slcColumn, nameColumn);
if (tmpStu.stuNoEqual(-1)) {
eof = true;
}
else if (tmpStu.stuNoEqual(0)) {
continue;
}
else {
Students.push_back(tmpStu);
}
}
cout << "<EFBFBD>ѵ<EFBFBD><EFBFBD><EFBFBD>" << endl;
cout << "b: <20><><EFBFBD><EFBFBD>" << endl;
cin >> tmp;
goBack();
}
//status 2
void Manager::examPage() {
char choice = '0';
cout << "<EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD>-<2D><><EFBFBD><EFBFBD>" << endl;
cout << setw(6) << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
Exam::dspHeader();
for (auto exam = Exams.begin(); exam < Exams.end(); exam++) {
cout << setw(4) << distance(Exams.begin(), exam) + 1;
(*exam)->dsp();
}
cout << endl;
cout << "<EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD>" << endl;
cout << "1: <20><><EFBFBD>ӿ<EFBFBD><D3BF><EFBFBD>" << endl;
cout << "2: ѡ<><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" << endl;
cout << "b: <20><><EFBFBD><EFBFBD>" << endl;
cin >> choice;
switch (choice) {
case '1':
status = 21;
break;
case '2':
status = 22;
break;
case 'b':
case 'B':
goBack();
break;
}
}
//status 21
void Manager::examAddPage() {
cout << "<EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD>-<2D><><EFBFBD><EFBFBD>-<2D><><EFBFBD><EFBFBD>" << endl;
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>:" << endl;
char name[100];
do {
cin.getline(name, 100);
} while (name[0] == '\0');
auto p = make_shared<Exam>(name);
Exams.push_back(p);
cout << "<EFBFBD><EFBFBD><EFBFBD>ӳɹ<EFBFBD>!" << endl;
cout << "b: <20><><EFBFBD><EFBFBD>" << endl;
string tmp;
cin >> tmp;
goBack();
}
//status 22
void Manager::examChoosePage() {
int examNo;
string tmp;
cout << "<EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD>-<2D><><EFBFBD><EFBFBD>-ѡ<><D1A1>" << endl;
cout << setw(6) << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
Exam::dspHeader();
for (auto exam = Exams.begin(); exam < Exams.end(); exam++) {
cout << setw(6) << distance(Exams.begin(), exam) + 1;
(*exam)->dsp();
}
cout << endl;
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>:" << endl;
cin >> examNo;
if (!cin.good()) {
throw InputError("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD>Ƿ<EFBFBD>!");
}
examNo--;
if (examNo >= 0 && examNo < Exams.size()) {
currentExam = Exams.begin() + examNo;
status = 23;
}
else {
throw IndexError("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч!");
}
}
//status 23
void Manager::examSubPage() {
cout << "<EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD>-<2D><><EFBFBD><EFBFBD>-";
(*currentExam)->dspName();
cout << endl;
cout << "<EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD>:" << endl;
cout << "1: <20>鿴ȫ<E9BFB4><C8AB><EFBFBD>ɼ<EFBFBD>" << endl;
cout << "2: <20><><EFBFBD><EFBFBD>ΪCSV" << endl;
cout << "3: <20><><EFBFBD><EFBFBD><EFBFBD>ɼ<EFBFBD>" << endl;
cout << "4: ɾ<><C9BE><EFBFBD>ɼ<EFBFBD>" << endl;
cout << "5: <20>޸Ŀ<DEB8><C4BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" << endl;
cout << "6: <20><>CSV<53><56><EFBFBD><EFBFBD>" << endl;
cout << "7: ɾ<><C9BE><EFBFBD>˿<EFBFBD><CBBF>Լ<EFBFBD><D4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>гɼ<D0B3><C9BC><EFBFBD>Ϣ" << endl;
cout << "b: <20><><EFBFBD><EFBFBD>" << endl;
char choice = '0';
cin >> choice;
switch (choice) {
case '1':
status = 231;
break;
case '2':
status = 232;
break;
case '3':
status = 233;
break;
case '4':
status = 234;
break;
case '5':
status = 235;
break;
case '6':
status = 236;
break;
case '7':
status = 237;
break;
case 'b':
case 'B':
goBack();
}
}
//status 231
void Manager::examViewPage() {
cout << "<EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD>-<2D><><EFBFBD><EFBFBD>-";
(*currentExam)->dspName();
cout << "-<2D>" << endl;
Item::dspHeader();
cout <<setw(6)<< "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>" << endl;
(*currentExam)->dspItems();
string tmp;
cout << endl << "b: <20><><EFBFBD><EFBFBD>" << endl;
cin >> tmp;
goBack();
}
//status 232
void Manager::examExportPage() {
string csvName;
cout << "<EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD>-<2D><><EFBFBD><EFBFBD>-";
(*currentExam)->dspName();
cout << "-<2D><><EFBFBD><EFBFBD>" << endl;
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>:" << endl;
do {
getline(cin, csvName);
} while (csvName == "");
csvName = csvName + ".csv";
ofstream csv(csvName);
if (!csv.good()) {
throw FileError("<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>!");
}
Item::toCsvHeader(csv);
csv << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>" << endl;
(*currentExam)->toCsvItems(csv);
csv.close();
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" << endl;
string tmp;
cout << endl << "b: <20><><EFBFBD><EFBFBD>" << endl;
cin >> tmp;
goBack();
}
//status 233
void Manager::examAddRowPage() {
long long int studentNo;
double score[9];
char yorn;
cout << "<EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD>-<2D><><EFBFBD><EFBFBD>-";
(*currentExam)->dspName();
cout << "-<2D><><EFBFBD><EFBFBD><EFBFBD>ɼ<EFBFBD>" << endl;
cout << "ѧ<EFBFBD><EFBFBD>:" << endl;
cin >> studentNo;
if (!cin.good()) {
throw InputError("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD>Ƿ<EFBFBD>!");
}
if ((*currentExam)->itemExists(studentNo)) {
cout << "ѧ<EFBFBD><EFBFBD>" << studentNo << "<EFBFBD>ijɼ<EFBFBD><EFBFBD>Ѵ<EFBFBD><EFBFBD><EFBFBD>, <20>Ƿ񸲸<C7B7>? (Y(<28><>)/N(<28><>))" << endl;
cin >> yorn;
if (yorn != 'Y' && yorn != 'y') {
status = 23;
return;
}
}
cout << "<EFBFBD><EFBFBD>ѧ:" << endl;
cin >> score[0];
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>:" << endl;
cin >> score[1];
cout << "Ӣ<EFBFBD><EFBFBD>:" << endl;
cin >> score[2];
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>:" << endl;
cin >> score[3];
cout << "<EFBFBD><EFBFBD>ѧ:" << endl;
cin >> score[4];
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>:" << endl;
cin >> score[5];
cout << "<EFBFBD><EFBFBD>ʷ:" << endl;
cin >> score[6];
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>:" << endl;
cin >> score[7];
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>:" << endl;
cin >> score[8];
if (!cin.good()) {
throw InputError("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD>Ƿ<EFBFBD>!");
}
(*currentExam)->addItem(studentNo, score);
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" << endl;
string tmp;
cout << endl << "b: <20><><EFBFBD><EFBFBD>" << endl;
cin >> tmp;
goBack();
}
//status 234
void Manager::examDelRowPage() {
char yorn;
long long int studentNo;
string tmp;
cout << "<EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD>-<2D><><EFBFBD><EFBFBD>-";
(*currentExam)->dspName();
cout << "<><C9BE><EFBFBD>ɼ<EFBFBD>" << endl;
cout << "ѧ<EFBFBD><EFBFBD>:" << endl;
cin >> studentNo;
if (!cin.good()) {
throw InputError("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD>Ƿ<EFBFBD>!");
}
cout << "ȷ<EFBFBD><EFBFBD>ɾ<EFBFBD><EFBFBD>(Y(<28><>)/N(<28><>))" << endl;
cin >> yorn;
if (yorn == 'Y' || yorn == 'y') {
yorn=(*currentExam)->rmvItem(studentNo);
if (yorn) {
cout << "<EFBFBD><EFBFBD>ɾ<EFBFBD><EFBFBD>" << endl;
}
else {
cout << "δ<EFBFBD>ҵ<EFBFBD>" << endl;
}
}
else {
cout << "<EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD>" << endl;
}
cout << "b: <20><><EFBFBD><EFBFBD>" << endl;
cin >> tmp;
goBack();
}
//status 235
void Manager::examNamePage() {
string tmp;
char name[100];
cout << "<EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD>-<2D><><EFBFBD><EFBFBD>-";
(*currentExam)->dspName();
cout << "-<2D>޸<EFBFBD><DEB8><EFBFBD><EFBFBD><EFBFBD>" << endl;
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:" << endl;
do {
cin.getline(name, 100);
} while (name[0] == '\0');
(*currentExam)->changeName(name);
cout << "<EFBFBD><EFBFBD><EFBFBD>޸<EFBFBD>" << endl;
cout << "b: <20><><EFBFBD><EFBFBD>" << endl;
cin >> tmp;
goBack();
}
//status 236
void Manager::examImportPage() {
string tmp;
string fileName;
int firstRow;
int stuNoColumn;
int scoreColumn[9];
bool eof=false;
char name[100];
cout << "<EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD>-<2D><><EFBFBD><EFBFBD>-";
(*currentExam)->dspName();
cout << "-<2D><><EFBFBD><EFBFBD>" << endl;
cout << "ע<EFBFBD><EFBFBD><EFBFBD><EFBFBD>˿<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ѵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬѧ<EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD>ijɼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD><EFBFBD><EFBFBD>CSV<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݻὫ<EFBFBD><EFBFBD><EFBFBD>" << endl;
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƻ<EFBFBD>·<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>չ<EFBFBD><EFBFBD>" << endl;
cin >> fileName;
ifstream csvFile(fileName);
if (!csvFile.good()) {
throw FileError("<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>!");
}
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: " << endl;
cin >> firstRow;
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" << endl;
cin >> stuNoColumn;
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ġ<EFBFBD>Ӣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ρ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Կո<EFBFBD><EFBFBD>ָ<EFBFBD>" << endl;
cin >> scoreColumn[0] >> scoreColumn[1] >> scoreColumn[2] >> scoreColumn[3] >> scoreColumn[4] >> scoreColumn[5] >> scoreColumn[6] >> scoreColumn[7] >> scoreColumn[8];
if (!cin.good()) {
throw InputError("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD>Ƿ<EFBFBD>!");
}
for (int i = 1; i < firstRow; i++) {
getline(csvFile, tmp);
}
while (!eof) {
Item tmpItem(csvFile, stuNoColumn, scoreColumn);
if (tmpItem.getStuNo()==-1) {
eof = true;
}
else if(tmpItem.getStuNo()==0) {
continue;
}
else {
(*currentExam)->addItem(tmpItem);
}
}
cout << "<EFBFBD>ѵ<EFBFBD><EFBFBD><EFBFBD>" << endl;
cout << "b: <20><><EFBFBD><EFBFBD>" << endl;
cin >> tmp;
goBack();
}
//status 237
void Manager::examRmvPage() {
string tmp;
cout << "<EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD>-<2D><><EFBFBD><EFBFBD>-";
(*currentExam)->dspName();
cout << "<><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" << endl;
cout << "<EFBFBD><EFBFBD>ȷ<EFBFBD><EFBFBD>Ҫɾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\"";
(*currentExam)->dspName();
cout<< "\"<EFBFBD><EFBFBD>" << endl;
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD> \"confirm\" <20><>ȷ<EFBFBD><C8B7>ɾ<EFBFBD><C9BE>" << endl;
cin >> tmp;
if (tmp == "confirm") {
(*currentExam)->rm();
Exams.erase(currentExam);
currentExam = Exams.begin();
goBack();
goBack();
cout << "<EFBFBD><EFBFBD>ɾ<EFBFBD><EFBFBD>" << endl;
}
else {
goBack();
cout << "<EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD>" << endl;
}
cout << "b: <20><><EFBFBD><EFBFBD>" << endl;
cin >> tmp;
}
//status 3
void Manager::stuPfmPage() {
long long int studentNo;
cout << "<EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><><D1A7><EFBFBD>ɼ<EFBFBD><C9BC><EFBFBD>ѯ" << endl;
cout << "ѧ<EFBFBD><EFBFBD>:" << endl;
cin >> studentNo;
if (!cin.good()) {
throw InputError("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD>Ƿ<EFBFBD>!");
}
Student::dspHeader();
cout << endl;
if (searchByNo(studentNo) == nullptr) {
cout << setw(20) << "δ<EFBFBD>ҵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" << endl;
}
else {
searchByNo(studentNo)->dsp();
}
cout << endl << endl;
cout << "<EFBFBD><EFBFBD><EFBFBD>ο<EFBFBD><EFBFBD>Գɼ<EFBFBD>:" << endl<<endl;
cout << setw(20) << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
Item::dspHeader(0);
cout << setw(6) << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>" << endl;
for (auto exam = Exams.begin(); exam < Exams.end(); exam++) {
auto item = (*exam)->StudentInquiry(studentNo);
(*exam)->dspName(20);
if (item == nullptr) {
cout << setw(20) << "δ<EFBFBD>ҵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" << endl;
}
else {
item->dsp(0);
cout << setw(6)<<(*exam)->getStuRanking(*item)<<endl;
}
}
string tmp;
cout <<endl<< "b: <20><><EFBFBD><EFBFBD>" << endl;
cin >> tmp;
goBack();
}