123 lines
3.2 KiB
C++
123 lines
3.2 KiB
C++
|
#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) << "<EFBFBD><EFBFBD>ѧ" << setw(5) << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>" << setw(5) << "Ӣ<EFBFBD><EFBFBD>" << setw(5) << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>" << setw(5) << "<EFBFBD><EFBFBD>ѧ" << setw(5) << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>" << setw(5) << "<EFBFBD><EFBFBD>ʷ" << setw(5) << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>" << setw(5) << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>" << setw(6) << "<EFBFBD>ܷ<EFBFBD>";
|
|||
|
}
|
|||
|
void Item::dspHeader(int w) {
|
|||
|
cout << setw(5) << "<EFBFBD><EFBFBD>ѧ" << setw(5) << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>" << setw(5) << "Ӣ<EFBFBD><EFBFBD>" << setw(5) << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>" << setw(5) << "<EFBFBD><EFBFBD>ѧ" << setw(5) << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>" << setw(5) << "<EFBFBD><EFBFBD>ʷ" << setw(5) << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>" << setw(5) << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>" << setw(6) << "<EFBFBD>ܷ<EFBFBD>";
|
|||
|
}
|
|||
|
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 << "<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>,";
|
|||
|
}
|
|||
|
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<string> 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];
|
|||
|
}
|
|||
|
}
|