You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

169 lines
4.1 KiB

#pragma once
#ifndef UNDERGRADUATE_MANAGER_H
#define UNDERGRADUATE_MANAGER_H
#include <iostream>
#include <string>
#include <fstream>
#include "undergraduate.h"
using namespace std;
class UnderGraduateManager {
private:
int top = 0;
UnderGraduate undergraduates[100];
public:
UnderGraduateManager();//<2F><>ȡ<EFBFBD>ļ<EFBFBD>
int queryByNo(string sno);
void clearStudent();
int addStudent(UnderGraduate s);
int modifyStudent(string sno);
int deleteStudent(string sno);
int queryStudent(string sno);
void displayAll();
void dataManage();
void dataSave();
void dataRead();
~UnderGraduateManager();//д<><D0B4><EFBFBD>ļ<EFBFBD>
};
UnderGraduateManager::UnderGraduateManager() {
dataRead();
}
int UnderGraduateManager::queryByNo(string sno) { // <20><><EFBFBD>ң<EFBFBD><D2A3>У<EFBFBD>i<EFBFBD><69> <20>ޣ<EFBFBD> -1
for (int i = 0; i <= top; i++)
if (undergraduates[i].getStudentNo() == sno)
return i;
return -1;
}
void UnderGraduateManager::clearStudent() {//ֹͣ<CDA3><D6B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>Ԫ<EFBFBD>أ<EFBFBD><D8A3><EFBFBD><E0B5B1>ɾ<EFBFBD><C9BE>Ԫ<EFBFBD><D4AA>
top = -1;
}
int UnderGraduateManager::addStudent(UnderGraduate s) {//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڸ<EFBFBD>Ԫ<EFBFBD>أ<EFBFBD>return -1<><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ԫ<EFBFBD><D4AA><EFBFBD><EFBFBD>+1<><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
int p = queryByNo(s.getStudentNo());
if (p == -1) {
top++;
undergraduates[top] = s;
dataSave();
return 1;
}
else {
cout << "existed!" << endl;
return 0;
}
}
int UnderGraduateManager::modifyStudent(string sno) {//<2F><><EFBFBD><EFBFBD><EFBFBD>ڸ<EFBFBD>Ԫ<EFBFBD>أ<EFBFBD>return <20><>= -1<><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>޸<EFBFBD><DEB8><EFBFBD><EFBFBD>ԣ<EFBFBD><D4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
int p = queryByNo(sno);
if (p == -1) {
cout << "Not exist!" << endl;
return 0;
}
else {
cout << "please input new detials" << endl;
undergraduates[p].inputData();
dataSave();
return 1;
}
}
int UnderGraduateManager::deleteStudent(string sno) {//ɾ<><C9BE>Ԫ<EFBFBD>أ<EFBFBD><D8A3><EFBFBD><EFBFBD><EFBFBD>Ԫ<EFBFBD><D4AA>ǰ<EFBFBD><C7B0>
int p = queryByNo(sno);
if (p == -1) {
cout << "Not exist!" << endl;
return 0;
}
else {
for (int i = 0; i < top; i++)
undergraduates[i] = undergraduates[i + 1];
top--;
cout << "Deleted!" << endl;
dataSave();
return 1;
}
}
int UnderGraduateManager::queryStudent(string sno) {
int p = queryByNo(sno);
if (p == -1) {
cout << "Not exist!" << endl;
return 0;
}
else {
cout << "exist!" << endl;
undergraduates[p].displayDetails();
return 1;
}
}
void UnderGraduateManager::displayAll() {
for (int i = 0; i <= top; i++) {
cout << "The NO." << i << "student's info:" << endl;
undergraduates[i].displayDetails();
}
}
UnderGraduateManager::~UnderGraduateManager() {
dataSave();
}
void UnderGraduateManager::dataManage() {
int choice = 1;
string sstudentNo;
UnderGraduate s;
while (choice != 0) {
cout << "**********************************" << endl;
cout << "\t\t undergraduate maintainace\n";
cout << "**********************************" << endl;
cout << "\n\t\t 1<><31><EFBFBD><EFBFBD>";
cout << "\n\t\t 2.<2E>޸<EFBFBD>";
cout << "\n\t\t 3.ɾ<><C9BE>";
cout << "\n\t\t 4.<2E><><EFBFBD><EFBFBD>";
cout << "\n\t\t 5.<2E><>ʾ";
cout << "\n\t\t 6.ȫ<><C8AB>ɾ<EFBFBD><C9BE>";
cout << "\n\t\t 0.<2E>˳<EFBFBD>";
cout << endl;
cout << "**********************************" << endl;
cout << "Please take your choice: ";
cin >> choice;
switch (choice) {
case 1:
s.inputData();
addStudent(s);
break;
case 2:
cout << " Please input student's number:";
cin >> sstudentNo;
modifyStudent(sstudentNo);
break;
case 3:
cout << " Please input student's number:";
cin >> sstudentNo;
deleteStudent(sstudentNo);
break;
case 4:
cout << " Please input student's number:";
cin >> sstudentNo;
queryStudent(sstudentNo);
break;
case 5:
displayAll();
break;
case 6:
clearStudent();
default:
break;
}
}
}
void UnderGraduateManager::dataSave() {
fstream file("D:\\ProgramData\\vs\\design\\UGM.docx", ios::out);// !
for (int i = 0; i <= top; i++) {
file.write((char*)&undergraduates[i], sizeof(undergraduates[i]));
}
file.close();
}
void UnderGraduateManager::dataRead() {
UnderGraduate s;
top--;
fstream file("D:\\ProgramData\\vs\\design\\UGM.docx", ios::in); // !
while (1) {
file.read((char*)&s, sizeof(s));
if (!file) break;
top++;
undergraduates[top] = s;
}
file.close();
}
#endif //UNDERGRADUATE_MANAGER_H