#include"Item.h" #include"Student.h" #include"Manager.h" using namespace std; extern Manager mainManager; Item::Item(long long int studentNo, double inscore[]) { sum = 0; for (int i = 0; i < 9; i++) { score[i] = inscore[i]; sum = sum + score[i]; } this->studentNo = studentNo; } Item::Item() { studentNo = -1; } bool Item::operator<(const Item& i) const { if (this->sum < i.sum) { return true; } else if (this->sum > i.sum) { return false; } else if (this->studentNo < i.sum) { return true; } else { return false; } } bool Item::operator>(const Item& i) const { if (this->sum < i.sum) { return false; } else if (this->sum > i.sum) { return true; } else if (this->studentNo < i.sum) { return false; } else { return true; } } long long int Item::getStuNo() const { return studentNo; } bool Item::stuNoEqual(const Item& i) const { if (this->studentNo == i.studentNo) { return true; } else { return false; } } void Item::dspHeader() { Student::dspHeader(); cout << setw(5) << "数学" << setw(5) << "语文" << setw(5) << "英语" << setw(5) << "物理" << setw(5) << "化学" << setw(5) << "生物" << setw(5) << "历史" << setw(5) << "政治" << setw(5) << "地理" << setw(6) << "总分"; } void Item::dspHeader(int w) { cout << setw(5) << "数学" << setw(5) << "语文" << setw(5) << "英语" << setw(5) << "物理" << setw(5) << "化学" << setw(5) << "生物" << setw(5) << "历史" << setw(5) << "政治" << setw(5) << "地理" << setw(6) << "总分"; } void Item::dsp() const { Student* stup = mainManager.searchByNo(this->studentNo); Student stu; if (stup == nullptr) { stu = Student(this->studentNo); } else { stu = *stup; } stu.dsp(); cout << setw(5) << score[0] << setw(5) << score[1] << setw(5) << score[2] << setw(5) << score[3] << setw(5) << score[4] << setw(5) << score[5] << setw(5) << score[6] << setw(5) << score[7] << setw(5) << score[8] << setw(6) << sum; } void Item::dsp(int w) const { cout << setw(5) << score[0] << setw(5) << score[1] << setw(5) << score[2] << setw(5) << score[3] << setw(5) << score[4] << setw(5) << score[5] << setw(5) << score[6] << setw(5) << score[7] << setw(5) << score[8] << setw(6) << sum; } void Item::toCsvHeader(ofstream& csv) { Student::toCsvHeader(csv); csv << "数学," << "语文," << "英语," << "物理," << "化学," << "生物," << "历史," << "政治," << "地理," << "总分,"; } void Item::toCsv(ofstream& csv) const { Student* stup = mainManager.searchByNo(this->studentNo); Student stu; if (stup == nullptr) { stu = Student(this->studentNo); } else { stu = *stup; } stu.toCsv(csv); csv << score[0] << "," << score[1] << "," << score[2] << "," << score[3] << "," << score[4] << "," << score[5] << "," << score[6] << "," << score[7] << "," << score[8] << "," << sum << ","; } Item::Item(ifstream& csv, int stuNoColumn,int scoreColumn[]) { string line, tmp; vector tmpvector; sum = 0; if (!getline(csv,line)) { studentNo = -1; return; } stringstream linestream(line); while (getline(linestream, tmp, ',')) { tmpvector.push_back(tmp); }; try { studentNo = stoi(tmpvector.at(stuNoColumn-1)); } catch (const exception& e) { studentNo = 0; } for (auto i = 0; i < 9; i++) { try { score[i] = stoi(tmpvector.at(scoreColumn[i]-1)); } catch (const exception& e) { score[i] = 0; } sum += score[i]; } }