高校人员信息管理系统 保存功能 读取功能
时间: 2023-10-14 14:04:36 浏览: 73
好的,您的问题是关于高校人员信息管理系统的保存功能和读取功能。我可以为您解答。
保存功能一般是将已经输入或修改的数据保存在数据库或文件中,以便后续使用或查询。在高校人员信息管理系统中,可以通过编写代码实现保存功能。具体实现方式取决于您使用的编程语言和数据库类型。
读取功能一般是将保存的数据从数据库或文件中读取出来,以便进行查询或展示。在高校人员信息管理系统中,可以通过编写代码实现读取功能。具体实现方式也取决于您使用的编程语言和数据库类型。
需要注意的是,在保存和读取数据时,应该保证数据的安全性和完整性,避免数据被篡改或丢失。同时,也应该合理地设计数据库表结构和字段,方便后续的数据查询和管理。
相关问题
用c++写一个高校师生信息管理系统,功能包括添加,查询,显示,编辑,删除,统计,保存,读取
好的,以下是一个简单的高校师生信息管理系统的代码示例:
```c++
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
using namespace std;
struct Student {
string name;
int age;
string major;
int id;
};
struct Teacher {
string name;
int age;
string department;
int id;
};
// 添加学生信息
void add_student(vector<Student>& students) {
Student s;
cout << "请输入学生姓名:";
cin >> s.name;
cout << "请输入学生年龄:";
cin >> s.age;
cout << "请输入学生专业:";
cin >> s.major;
cout << "请输入学生学号:";
cin >> s.id;
students.push_back(s);
cout << "添加成功!" << endl;
}
// 添加教师信息
void add_teacher(vector<Teacher>& teachers) {
Teacher t;
cout << "请输入教师姓名:";
cin >> t.name;
cout << "请输入教师年龄:";
cin >> t.age;
cout << "请输入教师所在院系:";
cin >> t.department;
cout << "请输入教师工号:";
cin >> t.id;
teachers.push_back(t);
cout << "添加成功!" << endl;
}
// 查询学生信息
void search_student(const vector<Student>& students) {
int id;
cout << "请输入要查询的学生学号:";
cin >> id;
for (const auto& s : students) {
if (s.id == id) {
cout << "姓名:" << s.name << endl;
cout << "年龄:" << s.age << endl;
cout << "专业:" << s.major << endl;
cout << "学号:" << s.id << endl;
return;
}
}
cout << "未找到该学生!" << endl;
}
// 查询教师信息
void search_teacher(const vector<Teacher>& teachers) {
int id;
cout << "请输入要查询的教师工号:";
cin >> id;
for (const auto& t : teachers) {
if (t.id == id) {
cout << "姓名:" << t.name << endl;
cout << "年龄:" << t.age << endl;
cout << "所在院系:" << t.department << endl;
cout << "工号:" << t.id << endl;
return;
}
}
cout << "未找到该教师!" << endl;
}
// 显示所有学生信息
void show_students(const vector<Student>& students) {
for (const auto& s : students) {
cout << "姓名:" << s.name << endl;
cout << "年龄:" << s.age << endl;
cout << "专业:" << s.major << endl;
cout << "学号:" << s.id << endl;
cout << endl;
}
}
// 显示所有教师信息
void show_teachers(const vector<Teacher>& teachers) {
for (const auto& t : teachers) {
cout << "姓名:" << t.name << endl;
cout << "年龄:" << t.age << endl;
cout << "所在院系:" << t.department << endl;
cout << "工号:" << t.id << endl;
cout << endl;
}
}
// 编辑学生信息
void edit_student(vector<Student>& students) {
int id;
cout << "请输入要编辑的学生学号:";
cin >> id;
for (auto& s : students) {
if (s.id == id) {
cout << "请输入学生姓名:";
cin >> s.name;
cout << "请输入学生年龄:";
cin >> s.age;
cout << "请输入学生专业:";
cin >> s.major;
cout << "编辑成功!" << endl;
return;
}
}
cout << "未找到该学生!" << endl;
}
// 编辑教师信息
void edit_teacher(vector<Teacher>& teachers) {
int id;
cout << "请输入要编辑的教师工号:";
cin >> id;
for (auto& t : teachers) {
if (t.id == id) {
cout << "请输入教师姓名:";
cin >> t.name;
cout << "请输入教师年龄:";
cin >> t.age;
cout << "请输入教师所在院系:";
cin >> t.department;
cout << "编辑成功!" << endl;
return;
}
}
cout << "未找到该教师!" << endl;
}
// 删除学生信息
void delete_student(vector<Student>& students) {
int id;
cout << "请输入要删除的学生学号:";
cin >> id;
for (auto it = students.begin(); it != students.end(); ++it) {
if (it->id == id) {
students.erase(it);
cout << "删除成功!" << endl;
return;
}
}
cout << "未找到该学生!" << endl;
}
// 删除教师信息
void delete_teacher(vector<Teacher>& teachers) {
int id;
cout << "请输入要删除的教师工号:";
cin >> id;
for (auto it = teachers.begin(); it != teachers.end(); ++it) {
if (it->id == id) {
teachers.erase(it);
cout << "删除成功!" << endl;
return;
}
}
cout << "未找到该教师!" << endl;
}
// 统计学生人数和教师人数
void count(const vector<Student>& students, const vector<Teacher>& teachers) {
cout << "学生人数:" << students.size() << endl;
cout << "教师人数:" << teachers.size() << endl;
}
// 保存信息到文件
void save(const vector<Student>& students, const vector<Teacher>& teachers) {
ofstream fout("info.txt");
if (!fout) {
cout << "文件打开失败!" << endl;
return;
}
for (const auto& s : students) {
fout << "S " << s.name << " " << s.age << " " << s.major << " " << s.id << endl;
}
for (const auto& t : teachers) {
fout << "T " << t.name << " " << t.age << " " << t.department << " " << t.id << endl;
}
fout.close();
cout << "保存成功!" << endl;
}
// 从文件读取信息
void load(vector<Student>& students, vector<Teacher>& teachers) {
ifstream fin("info.txt");
if (!fin) {
cout << "文件打开失败!" << endl;
return;
}
string type, name, major, department;
int age, id;
while (fin >> type >> name >> age >> major >> id) {
if (type == "S") {
Student s = {name, age, major, id};
students.push_back(s);
} else if (type == "T") {
Teacher t = {name, age, major, id};
teachers.push_back(t);
}
}
fin.close();
cout << "读取成功!" << endl;
}
int main() {
vector<Student> students;
vector<Teacher> teachers;
int choice;
while (true) {
cout << "=====================================" << endl;
cout << "1. 添加学生信息" << endl;
cout << "2. 添加教师信息" << endl;
cout << "3. 查询学生信息" << endl;
cout << "4. 查询教师信息" << endl;
cout << "5. 显示所有学生信息" << endl;
cout << "6. 显示所有教师信息" << endl;
cout << "7. 编辑学生信息" << endl;
cout << "8. 编辑教师信息" << endl;
cout << "9. 删除学生信息" << endl;
cout << "10. 删除教师信息" << endl;
cout << "11. 统计学生人数和教师人数" << endl;
cout << "12. 保存信息到文件" << endl;
cout << "13. 从文件读取信息" << endl;
cout << "0. 退出程序" << endl;
cout << "=====================================" << endl;
cout << "请输入您的选择:";
cin >> choice;
switch (choice) {
case 1:
add_student(students);
break;
case 2:
add_teacher(teachers);
break;
case 3:
search_student(students);
break;
case 4:
search_teacher(teachers);
break;
case 5:
show_students(students);
break;
case 6:
show_teachers(teachers);
break;
case 7:
edit_student(students);
break;
case 8:
edit_teacher(teachers);
break;
case 9:
delete_student(students);
break;
case 10:
delete_teacher(teachers);
break;
case 11:
count(students, teachers);
break;
case 12:
save(students, teachers);
break;
case 13:
load(students, teachers);
break;
case 0:
return 0;
default:
cout << "输入有误,请重新输入!" << endl;
}
}
}
```
这个代码示例实现了一个简单的高校师生信息管理系统,包括添加、查询、显示、编辑、删除、统计、保存和读取等功能。用户可以通过命令行菜单进行操作,所有信息都保存在内存中,并可以保存到文件中。注意,这个示例代码还有很多可以改进的地方,如增加输入检查、优化文件读写等。
用C++写高校员工信息管理系统,人员包括教师,实验员,行政人员,教师兼行政人员,功能包括添加,查询,显示,编辑,删除,统计,保存,读取
好的,这个高校员工信息管理系统可以分为以下几个模块:
1. 员工类(Teacher、LabStaff、Admin、TeacherAdmin):这些类都是继承于基类Employee,每个员工类都包含一些特定属性(如教师类包含授课科目等),以及一些公共属性(如姓名、性别、年龄等)和方法(如获取员工信息、修改员工信息等)。
2. 员工管理类(EmployeeManager):这个类用于实现对员工信息的添加、查询、显示、编辑、删除、统计、保存、读取等功能。其中,添加和编辑功能需要根据用户选择的员工类型创建相应的对象,并向对象中添加员工信息。查询和删除功能需要根据用户输入的员工ID进行查找。统计功能用于计算各类员工的数量和平均年龄等信息。保存和读取功能用于将员工信息存储到文件中或从文件中读取员工信息。
3. 界面类(Interface):这个类用于实现与用户交互的界面,包括菜单、输入输出等。
下面是一个简单的示例代码:
```cpp
#include <iostream>
#include <vector>
#include <fstream>
using namespace std;
// 员工基类
class Employee {
public:
Employee() {}
Employee(int id, string name, char sex, int age)
: m_id(id), m_name(name), m_sex(sex), m_age(age) {}
virtual void display() = 0; // 显示员工信息
int getId() { return m_id; }
string getName() { return m_name; }
char getSex() { return m_sex; }
int getAge() { return m_age; }
void setName(string name) { m_name = name; }
void setSex(char sex) { m_sex = sex; }
void setAge(int age) { m_age = age; }
protected:
int m_id; // 员工ID
string m_name; // 姓名
char m_sex; // 性别
int m_age; // 年龄
};
// 教师类
class Teacher : public Employee {
public:
Teacher() {}
Teacher(int id, string name, char sex, int age, string course)
: Employee(id, name, sex, age), m_course(course) {}
void display() {
cout << "ID: " << m_id << endl;
cout << "Name: " << m_name << endl;
cout << "Sex: " << m_sex << endl;
cout << "Age: " << m_age << endl;
cout << "Course: " << m_course << endl;
}
string getCourse() { return m_course; }
void setCourse(string course) { m_course = course; }
private:
string m_course; // 授课科目
};
// 实验员类
class LabStaff : public Employee {
public:
LabStaff() {}
LabStaff(int id, string name, char sex, int age, string lab)
: Employee(id, name, sex, age), m_lab(lab) {}
void display() {
cout << "ID: " << m_id << endl;
cout << "Name: " << m_name << endl;
cout << "Sex: " << m_sex << endl;
cout << "Age: " << m_age << endl;
cout << "Lab: " << m_lab << endl;
}
string getLab() { return m_lab; }
void setLab(string lab) { m_lab = lab; }
private:
string m_lab; // 实验室名称
};
// 行政人员类
class Admin : public Employee {
public:
Admin() {}
Admin(int id, string name, char sex, int age, string department)
: Employee(id, name, sex, age), m_department(department) {}
void display() {
cout << "ID: " << m_id << endl;
cout << "Name: " << m_name << endl;
cout << "Sex: " << m_sex << endl;
cout << "Age: " << m_age << endl;
cout << "Department: " << m_department << endl;
}
string getDepartment() { return m_department; }
void setDepartment(string department) { m_department = department; }
private:
string m_department; // 部门名称
};
// 教师兼行政人员类
class TeacherAdmin : public Teacher, public Admin {
public:
TeacherAdmin() {}
TeacherAdmin(int id, string name, char sex, int age, string course, string department)
: Employee(id, name, sex, age), Teacher(id, name, sex, age, course), Admin(id, name, sex, age, department) {}
void display() {
cout << "ID: " << m_id << endl;
cout << "Name: " << m_name << endl;
cout << "Sex: " << m_sex << endl;
cout << "Age: " << m_age << endl;
cout << "Course: " << Teacher::getCourse() << endl;
cout << "Department: " << Admin::getDepartment() << endl;
}
};
// 员工管理类
class EmployeeManager {
public:
EmployeeManager() {}
// 添加员工
void addEmployee() {
int id, age;
string name;
char sex, type;
cout << "Please input ID: ";
cin >> id;
cout << "Please input Name: ";
cin >> name;
cout << "Please input Sex(M/F): ";
cin >> sex;
cout << "Please input Age: ";
cin >> age;
cout << "Please select employee type(T/L/A/TA): ";
cin >> type;
Employee *employee = NULL;
switch (type) {
case 'T':
string course;
cout << "Please input Course: ";
cin >> course;
employee = new Teacher(id, name, sex, age, course);
break;
case 'L':
string lab;
cout << "Please input Lab: ";
cin >> lab;
employee = new LabStaff(id, name, sex, age, lab);
break;
case 'A':
string department;
cout << "Please input Department: ";
cin >> department;
employee = new Admin(id, name, sex, age, department);
break;
case 'TA':
string course_ta, department_ta;
cout << "Please input Course: ";
cin >> course_ta;
cout << "Please input Department: ";
cin >> department_ta;
employee = new TeacherAdmin(id, name, sex, age, course_ta, department_ta);
break;
default:
cout << "Invalid type!" << endl;
return;
}
m_employeeList.push_back(employee);
cout << "Add employee successfully!" << endl;
}
// 查询员工
void queryEmployee() {
int id;
cout << "Please input ID: ";
cin >> id;
for (int i = 0; i < m_employeeList.size(); i++) {
if (m_employeeList[i]->getId() == id) {
m_employeeList[i]->display();
return;
}
}
cout << "Employee not found!" << endl;
}
// 显示所有员工
void displayAllEmployee() {
for (int i = 0; i < m_employeeList.size(); i++) {
m_employeeList[i]->display();
cout << endl;
}
}
// 编辑员工信息
void editEmployee() {
int id;
cout << "Please input ID: ";
cin >> id;
for (int i = 0; i < m_employeeList.size(); i++) {
if (m_employeeList[i]->getId() == id) {
cout << "Please input new Name: ";
string name;
cin >> name;
cout << "Please input new Sex(M/F): ";
char sex;
cin >> sex;
cout << "Please input new Age: ";
int age;
cin >> age;
m_employeeList[i]->setName(name);
m_employeeList[i]->setSex(sex);
m_employeeList[i]->setAge(age);
cout << "Edit employee successfully!" << endl;
return;
}
}
cout << "Employee not found!" << endl;
}
// 删除员工
void deleteEmployee() {
int id;
cout << "Please input ID: ";
cin >> id;
for (vector<Employee*>::iterator it = m_employeeList.begin(); it != m_employeeList.end(); it++) {
if ((*it)->getId() == id) {
m_employeeList.erase(it);
cout << "Delete employee successfully!" << endl;
return;
}
}
cout << "Employee not found!" << endl;
}
// 统计员工信息
void statEmployee() {
int teacherCount = 0, labStaffCount = 0, adminCount = 0, teacherAdminCount = 0;
int totalAge = 0;
for (int i = 0; i < m_employeeList.size(); i++) {
if (dynamic_cast<Teacher*>(m_employeeList[i])) {
teacherCount++;
} else if (dynamic_cast<LabStaff*>(m_employeeList[i])) {
labStaffCount++;
} else if (dynamic_cast<Admin*>(m_employeeList[i])) {
adminCount++;
} else if (dynamic_cast<TeacherAdmin*>(m_employeeList[i])) {
teacherAdminCount++;
}
totalAge += m_employeeList[i]->getAge();
}
cout << "Teacher count: " << teacherCount << endl;
cout << "Lab staff count: " << labStaffCount << endl;
cout << "Admin count: " << adminCount << endl;
cout << "Teacher admin count: " << teacherAdminCount << endl;
cout << "Average age: " << totalAge / m_employeeList.size() << endl;
}
// 保存员工信息到文件
void saveToFile() {
ofstream ofs("employee.txt");
for (int i = 0; i < m_employeeList.size(); i++) {
ofs << m_employeeList[i]->getId() << " " << m_employeeList[i]->getName() << " "
<< m_employeeList[i]->getSex() << " " << m_employeeList[i]->getAge() << " ";
if (dynamic_cast<Teacher*>(m_employeeList[i])) {
ofs << "T " << dynamic_cast<Teacher*>(m_employeeList[i])->getCourse() << endl;
} else if (dynamic_cast<LabStaff*>(m_employeeList[i])) {
ofs << "L " << dynamic_cast<LabStaff*>(m_employeeList[i])->getLab() << endl;
} else if (dynamic_cast<Admin*>(m_employeeList[i])) {
ofs << "A " << dynamic_cast<Admin*>(m_employeeList[i])->getDepartment() << endl;
} else if (dynamic_cast<TeacherAdmin*>(m_employeeList[i])) {
ofs << "TA " << dynamic_cast<TeacherAdmin*>(m_employeeList[i])->getCourse() << " "
<< dynamic_cast<TeacherAdmin*>(m_employeeList[i])->getDepartment() << endl;
}
}
ofs.close();
cout << "Save to file successfully!" << endl;
}
// 从文件中读取员工信息
void readFromFile() {
ifstream ifs("employee.txt");
if (!ifs.is_open()) {
cout << "Open file failed!" << endl;
return;
}
while (!ifs.eof()) {
int id, age;
string name, course, lab, department;
char sex, type;
ifs >> id >> name >> sex >> age >> type;
switch (type) {
case 'T':
ifs >> course;
m_employeeList.push_back(new Teacher(id, name, sex, age, course));
break;
case 'L':
ifs >> lab;
m_employeeList.push_back(new LabStaff(id, name, sex, age, lab));
break;
case 'A':
ifs >> department;
m_employeeList.push_back(new Admin(id, name, sex, age, department));
break;
case 'TA':
ifs >> course >> department;
m_employeeList.push_back(new TeacherAdmin(id, name, sex, age, course, department));
break;
default:
break;
}
}
ifs.close();
cout << "Read from file successfully!" << endl;
}
private:
vector<Employee*> m_employeeList; // 员工列表
};
// 界面类
class Interface {
public:
Interface() {}
void showMenu() {
cout << "================ Employee Management System ================" << endl;
cout << "1. Add employee" << endl;
cout << "2. Query employee" << endl;
cout << "3. Display all employee" << endl;
cout << "4. Edit employee" << endl;
cout << "5. Delete employee" << endl;
cout << "6. Stat employee" << endl;
cout << "7. Save to file" << endl;
cout << "8. Read from file" << endl;
cout << "0. Exit" << endl;
cout << "============================================================" << endl;
}
void run() {
EmployeeManager em;
int choice;
while (true) {
showMenu();
cout << "Please input your choice: ";
cin >> choice;
switch (choice) {
case 1:
em.addEmployee();
break;
case 2:
em.queryEmployee();
break;
case 3:
em.displayAllEmployee();
break;
case 4:
em.editEmployee();
break;
case 5:
em.deleteEmployee();
break;
case 6:
em.statEmployee();
break;
case 7:
em.saveToFile();
break;
case 8:
em.readFromFile();
break;
case 0:
cout << "Thanks for using!" << endl;
return;
default:
cout << "Invalid choice!" << endl;
break;
}
}
}
};
int main() {
Interface ui;
ui.run();
return 0;
}
```
阅读全文