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.

216 lines
5.7 KiB

#pragma once
#pragma once
/*************************************************
Copyright (C), 2010, Tyut
File name: GradateManager.h
Author: gaobaolu Version: 1.0 Date: 2010.6.28
Description: <EFBFBD>о<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*************************************************/
//#ifndef UNDERGRADUATE_MANAGER_H
#define UNDERGRADUATE_MANAGER_H
#include <iostream>
#include <string>
#include <fstream>
#include"graduate.h"
using namespace std;
/* Define a Class : GradateManager <20>о<EFBFBD><D0BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
class GradateManager
{
private:
int top; //<2F><>¼ָ<C2BC><D6B8>
Graduate graduates[100]; //<2F>о<EFBFBD><D0BE><EFBFBD><EFBFBD><EFBFBD>¼
public:
GradateManager();//<2F><><EFBFBD><EFBFBD><ECBAAF>,<2C><>Undergraduate.txt<78><74><EFBFBD><EFBFBD>undergraduates[]<5D><>
int queryByNo(string sno);//<2F><><EFBFBD>о<EFBFBD><D0BE><EFBFBD><EFBFBD>Ų<EFBFBD><C5B2><EFBFBD> //<2F>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>±<EFBFBD>//û<>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>-1
void clearStudent(); //ɾ<><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>о<EFBFBD><D0BE><EFBFBD><EFBFBD><EFBFBD>Ϣ
int addStudent(Graduate s); //<2F><><EFBFBD><EFBFBD><EFBFBD>о<EFBFBD><D0BE><EFBFBD>,<2C><>Ҫ<EFBFBD>Ȳ<EFBFBD><C8B2><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
int modifyStudent(string sno); //<2F>޸<EFBFBD>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD>Ϣ ,<2C><>Ҫ<EFBFBD>Ȳ<EFBFBD><C8B2><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
int deleteStudent(string sno);//ɾ<><C9BE><EFBFBD>о<EFBFBD><D0BE><EFBFBD><EFBFBD><EFBFBD>ɾ<EFBFBD><C9BE>ǰ<EFBFBD>Ȳ<EFBFBD><C8B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
int queryStudent(string sno);//<2F><><EFBFBD><EFBFBD><EFBFBD>о<EFBFBD><D0BE><EFBFBD>,<2C><EFBFBD><E9B5BD><EFBFBD><EFBFBD>ʾ,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾδ<CABE>
void displayAll();//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>о<EFBFBD><D0BE><EFBFBD><EFBFBD><EFBFBD>Ϣ
void dataManage(); //<2F>о<EFBFBD><D0BE><EFBFBD><EFBFBD><EFBFBD>ά<EFBFBD><CEAC>
void dataSave();
void dataRead();
~GradateManager();//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><>undergraduates[]д<><D0B4>Undergraduate.txt<78>ļ<EFBFBD><C4BC><EFBFBD>
};
//<2F><><EFBFBD><EFBFBD><ECBAAF>,<2C><>Undergraduate.txt<78><74><EFBFBD><EFBFBD>undergraduates[]<5D><>
GradateManager::GradateManager()
{
dataRead();
}
//<2F><><EFBFBD>о<EFBFBD><D0BE><EFBFBD><EFBFBD>Ų<EFBFBD><C5B2><EFBFBD>
//<2F>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>±<EFBFBD>
//û<>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>-1
int GradateManager::queryByNo(string sno)
{
for (int i = 0; i <= top; i++)
if (graduates[i].getStudentNo() == sno)
return i;
return -1;
}
//ɾ<><C9BE><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD><D0B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
void GradateManager::clearStudent()
{
top = -1;
}
//<2F><><EFBFBD><EFBFBD><EFBFBD>о<EFBFBD><D0BE><EFBFBD>,<2C><>Ҫ<EFBFBD>Ȳ<EFBFBD><C8B2><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
int GradateManager::addStudent(Graduate s)
{
int p = queryByNo(s.getStudentNo());
if (p == -1)
{
top++;
graduates[top] = s;
dataSave();//<2F><><EFBFBD><EFBFBD>
return 1;
}
else
{
cout << "---------><3E><>ѧ<EFBFBD><D1A7><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD> !<----------" << endl << endl;
return 0;
}
}
//<2F>޸<EFBFBD><DEB8>о<EFBFBD><D0BE><EFBFBD><EFBFBD><EFBFBD>ɾ<EFBFBD><C9BE>ǰ<EFBFBD>Ȳ<EFBFBD><C8B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
int GradateManager::modifyStudent(string sno)
{
int p = queryByNo(sno);
if (p == -1)
{
cout << "---------><3E><>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> !<----------" << endl << endl;
return 0;
}
else
{
cout << "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ: " << endl << endl;
graduates[p].inputData();
dataSave();//<2F><><EFBFBD><EFBFBD>
return 1;
}
}
//ɾ<><C9BE><EFBFBD>о<EFBFBD><D0BE><EFBFBD><EFBFBD><EFBFBD>ɾ<EFBFBD><C9BE>ǰ<EFBFBD>Ȳ<EFBFBD><C8B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
int GradateManager::deleteStudent(string sno)
{
int p = queryByNo(sno);
if (p == -1)
{
cout << "---------><3E><>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> !<----------" << endl << endl;
return 0;
}
else
{
for (int i = p; i < top; i++)
graduates[i] = graduates[i + 1];
top--;
cout << "--------->ɾ<><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!<----------" << endl << endl;
dataSave();//<2F><><EFBFBD><EFBFBD>
return 1;
}
}
//<2F><><EFBFBD><EFBFBD><EFBFBD>о<EFBFBD><D0BE><EFBFBD>
int GradateManager::queryStudent(string sno)
{
int p = queryByNo(sno);
if (p == -1)
{
cout << "---------><3E><>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> !<----------" << endl << endl;
return 0;
}
else
{
cout << "---------><3E><>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:<----------" << endl << endl;
graduates[p].displayDetails();
return 1;
}
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>о<EFBFBD><D0BE><EFBFBD><EFBFBD><EFBFBD>Ϣ
void GradateManager::displayAll()
{
for (int i = 0; i <= top; i++)
{
cout << "--------<2D><>" << i << "<EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>----------" << endl << endl;
graduates[i].displayDetails();
}
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><>undergraduates[]д<><D0B4>Undergraduate.txt<78>ļ<EFBFBD><C4BC><EFBFBD>
GradateManager::~GradateManager()
{
dataSave();
}
void GradateManager::dataManage()
{
int choice = 1;
string sstudentNo;
Graduate s;
while (choice != 0)
{
cout << "********************************************" << endl;
cout << "\t\t<EFBFBD>о<EFBFBD><EFBFBD><EFBFBD>ά<EFBFBD><EFBFBD>\n";
cout << "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" << endl;
cout << "\n \t\t 1:<3A><><EFBFBD><EFBFBD> ";
cout << "\n \t\t 2:<3A>޸<EFBFBD> ";
cout << "\n \t\t 3:ɾ<><C9BE> ";
cout << "\n \t\t 4:<3A><><EFBFBD><EFBFBD> ";
cout << "\n \t\t 5:<3A><>ʾ ";
cout << "\n \t\t 6:ȫ<><C8AB>ɾ<EFBFBD><C9BE> ";
cout << "\n \t\t 0:<3A>˳<EFBFBD> ";
cout << endl;
cout << "*********************************************" << endl;
cout << "<EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>" << endl;
cin >> choice;
switch (choice)
{
case 1:
s.inputData();
addStudent(s);
break;
case 2:
cout << " <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><D1A7>:";
cin >> sstudentNo;
modifyStudent(sstudentNo);
break;
case 3:
cout << " <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><D1A7>:";
cin >> sstudentNo;
deleteStudent(sstudentNo);
break;
case 4:
cout << " <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><D1A7>:";
cin >> sstudentNo;
queryStudent(sstudentNo);
break;
case 5:
displayAll();
break;
case 6:
clearStudent();
break;
default:
break;
}
}
}
void GradateManager::dataSave()//<2F><EFBFBD><E6B4A2><EFBFBD>Ϻ<EFBFBD><CFBA><EFBFBD>,<2C><>read[]д<><D0B4>Undergraduate.txt<78>ļ<EFBFBD><C4BC><EFBFBD>
{
fstream file("C:\\Undergraduate.dat", ios::out);
for (int i = 0; i <= top; i++)
file.write((char*)&graduates[i], sizeof(graduates[i]));
file.close();
}
void GradateManager::dataRead() //<2F><><EFBFBD><EFBFBD><ECBAAF>,<2C><>Undergraduate.txt<78><74><EFBFBD><EFBFBD>read[]<5D><>
{
Graduate s;
top = -1;
fstream file("C:\\graduate.dat", ios::in);
while (1)
{
file.read((char*)&s, sizeof(s));
if (!file) break;
top++;
graduates[top] = s;
}
file.close();
}
//#endif //UNDERGRADUATE_MANAGER_H