125 lines
3.0 KiB
C++
125 lines
3.0 KiB
C++
|
#include"Student.h"
|
|||
|
#include"Manager.h"
|
|||
|
#pragma warning(disable:4996)
|
|||
|
using namespace std;
|
|||
|
extern Manager mainManager;
|
|||
|
Student::Student(int year, int selectionNo, int classNo, char name[]) :year(year), selectionNo(selectionNo), classNo(classNo), serialNo(serialNo) {
|
|||
|
strcpy_s(this->name, name);
|
|||
|
studentNo = infoToNo(year, selectionNo, classNo);
|
|||
|
serialNo = studentNo % 100;
|
|||
|
}
|
|||
|
Student::Student(long long int studentNo) {
|
|||
|
this->studentNo = studentNo;
|
|||
|
strcpy(this->name, "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|||
|
year = 0;
|
|||
|
selectionNo = 0;
|
|||
|
classNo = 0;
|
|||
|
serialNo = 0;
|
|||
|
}
|
|||
|
Student::Student(ifstream& csv, int yearColumn, int clsColumn, int slcColumn,int nameColumn) {
|
|||
|
string line, tmp;
|
|||
|
vector<string> tmpvector;
|
|||
|
if (!getline(csv, line)) {
|
|||
|
studentNo = -1;
|
|||
|
return;
|
|||
|
}
|
|||
|
stringstream linestream(line);
|
|||
|
while (getline(linestream, tmp, ',')) {
|
|||
|
tmpvector.push_back(tmp);
|
|||
|
};
|
|||
|
try {
|
|||
|
year = stoi(tmpvector.at(yearColumn - 1));
|
|||
|
}
|
|||
|
catch (const exception& e) {
|
|||
|
year = 0;
|
|||
|
}
|
|||
|
try {
|
|||
|
classNo = stoi(tmpvector.at(clsColumn - 1));
|
|||
|
}
|
|||
|
catch (const exception& e) {
|
|||
|
classNo = 0;
|
|||
|
}
|
|||
|
try {
|
|||
|
selectionNo = stoi(tmpvector.at(slcColumn - 1));
|
|||
|
}
|
|||
|
catch (const exception& e) {
|
|||
|
selectionNo = 0;
|
|||
|
}
|
|||
|
strcpy(this->name, tmpvector.at(nameColumn - 1).c_str());
|
|||
|
if (year != 0 && classNo != 0 && selectionNo != 0) {
|
|||
|
studentNo = infoToNo(year, selectionNo, classNo);
|
|||
|
serialNo = studentNo % 100;
|
|||
|
}
|
|||
|
else {
|
|||
|
studentNo = 0;
|
|||
|
serialNo = 0;
|
|||
|
}
|
|||
|
}
|
|||
|
void Student::dspHeader() {
|
|||
|
cout << setw(10) << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>" << setw(12) << "ѧ<EFBFBD><EFBFBD>" << setw(10) << "<EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>" << setw(5) << "<EFBFBD>༶" << setw(5) << "ѡ<EFBFBD><EFBFBD>";
|
|||
|
}
|
|||
|
void Student::dsp() const {
|
|||
|
cout << setw(10) << name << setw(12) << studentNo << setw(10) << year << setw(5) << classNo << setw(5) << selectionNo;
|
|||
|
}
|
|||
|
void Student::toCsvHeader(ofstream& csv) {
|
|||
|
csv<< "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>,"<< "ѧ<EFBFBD><EFBFBD>,"<< "<EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>,"<< "<EFBFBD>༶," << "ѡ<EFBFBD><EFBFBD>,";
|
|||
|
}
|
|||
|
void Student::toCsv (ofstream& csv) const {
|
|||
|
csv << name << ',' << studentNo << ',' << year << ',' << classNo << ',' << selectionNo << ',';
|
|||
|
}
|
|||
|
void Student::setInfo(int year, int selectionNo, int classNo, char name[]) {
|
|||
|
this->year = year;
|
|||
|
this->selectionNo = selectionNo;
|
|||
|
this->classNo = classNo;
|
|||
|
strcpy(this->name, name);
|
|||
|
}
|
|||
|
bool Student::stuNoEqual(long long int studentNo) const {
|
|||
|
if (this->studentNo == studentNo) {
|
|||
|
return true;
|
|||
|
}
|
|||
|
else {
|
|||
|
return false;
|
|||
|
}
|
|||
|
}
|
|||
|
bool Student::slcNoEqual(int selectionNo) const {
|
|||
|
if (this->selectionNo == selectionNo) {
|
|||
|
return true;
|
|||
|
}
|
|||
|
else {
|
|||
|
return false;
|
|||
|
}
|
|||
|
}
|
|||
|
bool Student::clsNoEqual(int classNo) const {
|
|||
|
if (this->classNo == classNo) {
|
|||
|
return true;
|
|||
|
}
|
|||
|
else {
|
|||
|
return false;
|
|||
|
}
|
|||
|
}
|
|||
|
bool Student::nameEqual(char name[]) const {
|
|||
|
if (strcmp(this->name, name) == 0) {
|
|||
|
return true;
|
|||
|
}
|
|||
|
else {
|
|||
|
return false;
|
|||
|
}
|
|||
|
}
|
|||
|
bool Student::yearEqual(int year) const {
|
|||
|
if (this->year == year) {
|
|||
|
return true;
|
|||
|
}
|
|||
|
else {
|
|||
|
return false;
|
|||
|
}
|
|||
|
}
|
|||
|
long long int Student::infoToNo(int year, int selectionNo, int classNo) {
|
|||
|
long long int initNo = year * 1000000 + selectionNo * 10000 + classNo * 100 + 1;
|
|||
|
for (auto i = initNo; i < initNo + 99; i++) {
|
|||
|
if (mainManager.searchByNo(i) == nullptr) {
|
|||
|
return i;
|
|||
|
}
|
|||
|
}
|
|||
|
return -1;
|
|||
|
}
|