zoukankan      html  css  js  c++  java
  • 数据结构 教师信息管理系统

    该系统能够对信息学院的教师信息进行管理,主要功能如下:

    设计要求:

    (1) 实现人事资料输入、修改、删除等:

    (2) 输入教师信息,如姓名、身份证号、地址、电话、部门、工资、参加工作时间、专业、职务、备注等。

    (3) 实现信息查询:可根据教师编号、教师姓名、出生年月范围、工资范围、参加工作时间范围等条件查询等。

    #include <iostream>
    #include <fstream>
    #include <sstream>
    #include <string>
    #include <iomanip>
    #include <windows.h>
    #define WIDTH 20
    #define space setw(WIDTH)
    #define NEWLINE " "
    using namespace std;
    struct students{
     int IDNumber ,wage, time,birthday;
     string name, address, phone, department,spe, zhiwu, remarks;
    };
     

    void write(const char *filename)
    {
     students stu;
     ofstream out;
     out.open(filename, ios::app);
     if (!out.is_open())
     {
      cout << "open error" << endl;
      return;
     }
     else
     {
      cout << "请输入身份证号、姓名、地址、电话、部门、工资、参加工作的时间、专业、职务、备注:" << endl;
      cin >> stu.IDNumber >> stu.name>> stu.address >> stu.phone >> stu.department >> stu.wage >> stu.time >> stu.spe >> stu.zhiwu >> stu.remarks;
      out.fill(' ');
      out.setf(ios::left);
      out << space << stu.IDNumber << space << stu.name <<space << stu.address << space << stu.phone << space << stu.department << space << stu.wage << space << stu.time << space << stu.spe << space << stu.zhiwu << space << stu.remarks << NEWLINE;
      out.close();
      cout << "添加成功!!" << endl;
     }
    }
    void read(const char *filename)
    {
     students stu;
     ifstream in;
     in.open(filename, ios::in);
     if (!in.is_open())
     {
      cout << "file open error" << endl;
      return;
     }
     else
     {
      stringstream ss;
      char line[100000];
      cout.setf(ios::left);
      cout.fill(' ');
      cout << space << "身份证号" << space << "姓名" << space << "地址" << space << "电话" << space << "部门" << space << "工资" << space << "参加工作时间" << space << "专业" << space << "职务" << space << "备注" << endl;
      while (in.peek() != EOF)
      {
       in.getline(line,100000);
       ss << line;
       ss >> stu.IDNumber >> stu.name>> stu.address >> stu.phone >> stu.department >> stu.wage >> stu.time >> stu.spe >> stu.zhiwu >> stu.remarks;
       cout << space << stu.IDNumber << space << stu.name << space << stu.address << space << stu.phone << space << stu.department << space << stu.wage << space << stu.time << space << stu.spe << space << stu.zhiwu << space << stu.remarks << NEWLINE;
       ss.str("");
       ss.clear();
      }
      in.close();
     }
    }
    void del(const char *filename)
    {
     int IDNumber;
     cout << "请输入您要删除教师的身份证号" << endl;
     cin >> IDNumber;
     ifstream in;
     in.open(filename, ios::in);
     if (!in.is_open())
     {
      cout << "file open error" << endl;
      return;
     }
     else
     {
      string temp;
      stringstream ss;
      int curId;;
      while (in.peek() != EOF)
      {
       string line;
       getline(in, line);
       ss << line;
       ss >> curId;
       if (curId != IDNumber)
       {
        temp += line + NEWLINE;
       }
       ss.str("");
       ss.clear();
      }
      in.close();
      ofstream out;
      out.open("D:\teachermanage.txt", ios::out);
      if (!out.is_open())
      {
       cout << "file open error" << endl;
       return;
      }
      else
      {
       out << temp;
       out.close();
       cout << "删除成功!!" << endl;
      }
     }
    }
     
    int search_pos(const char *filename, int id)
    {
     ifstream in;
     in.open(filename, ios::in | ios::binary);
     if (!in.is_open())
     {
      cout << "file open error" << endl;
      return -1;
     }
     else
     {
      stringstream ss;
      while (in.peek() != EOF)
      {
       int start = in.tellg();
       string line;
       getline(in, line);
       ss << line;
       int curID;
       ss >> curID;
       if (curID == id)
       {
        in.close();
        return start;
       }
       ss.str("");
      }
      cout << "对不起您查找的同学信息不存在!" << endl;
      in.close();
     }
     return -1;
    }

    int search_name(const char *filename, string name)
    {
     students stu;
     ifstream in;
     in.open(filename, ios::in | ios::binary);
     if (!in.is_open())
     {
      cout << "file open error" << endl;
      return -1;
     }
     else
     {
      stringstream ss;
      while (in.peek() != EOF)
      {
       int start = in.tellg();
       string line;
       getline(in, line);
       ss << line;
       ss >> stu.IDNumber >> stu.name >> stu.address >> stu.phone >> stu.department >> stu.wage >> stu.time >> stu.spe >> stu.zhiwu >> stu.remarks;
       if (stu.name == name)
       {
        in.close();
        return start;
       }
       ss.str("");
      }
      cout << "对不起您查找的教师信息不存在!" << endl;
      in.close();
     }
     return -1;
    }
    void searchName(const char *filename)
    {
     cout << "请输入您要查找的教师姓名:" << endl;
     string name;
     cin >> name;
     int pos = search_name(filename, name);
     string line;
     fstream in;
     in.open(filename, ios::in | ios::binary);
     in.seekg(pos, ios::beg);
     getline(in, line);
     cout.setf(ios::left);
     cout << space << "身份证号" << space << "姓名" << space << "地址" << space << "电话" << space << "部门" << space << "工资" << space << "参加工作时间" << space << "专业" << space << "职务" << space << "备注" << endl;
     cout << line << endl;
    }

    void searchID(const char *filename)
    {
     cout << "请输入您要查找的教师id:" << endl;
     int id;
     cin >> id;
     int pos = search_pos(filename, id);
     string line;
     fstream in;
     in.open(filename, ios::in | ios::binary);
     in.seekg(pos, ios::beg);
     getline(in, line);
     cout.setf(ios::left);
     cout << space << "身份证号" << space << "姓名" << space << "地址" << space << "电话" << space << "部门" << space << "工资" << space << "参加工作时间" << space << "专业" << space << "职务" << space << "备注" << endl;
     cout << line << endl;
    }
    void edit(const char *filename)
    {
     int id, age;
     string name,address, phone, department, wage, time, spe, zhiwu, remarks;
     cout << "请输入您要修改的教师身份证号:" << endl;
     cin >> id;
     cout << "请输入该教师新的姓名、地址、电话、部门、工资、参加工作的时间、专业、职务、备注:" << endl;
     cin >> name >> address >> phone >> department >> wage >> time >> spe >> zhiwu >> remarks;
     stringstream infoTemp;
     infoTemp.fill(' ');
     infoTemp.setf(ios::left);
     infoTemp << space << id << space << name << space << address << space << phone << space << department << space << wage << space << time << space << spe << space << zhiwu << space << remarks;
     string newInfo;
     getline(infoTemp, newInfo);
     fstream file;
     file.open(filename, ios::in | ios::out | ios::binary);
     if (!file.is_open())
     {
      cout << "file open error" << endl;
      return;
     }
     else
     {
      int pos = search_pos(filename, id);
      file.seekg(pos, ios::beg);
      file << newInfo;
      cout << "修改后信息为:" << endl;
      cout << newInfo << endl;
      file.close();
     }
    }

    void searchwage(const char *filename)
    {
     int max1, min1;
     cout << "请输入教师公资范围(最大、最小)"<<endl;
     cin >> max1>>min1;
     students stu;
     ifstream in;
     in.open(filename, ios::in);
     if (!in.is_open())
     {
      cout << "file open error" << endl;
      return;
     }
     else
     {
      stringstream ss;
      char line[100000];
      cout.setf(ios::left);
      cout.fill(' ');
      cout << space << "身份证号" << space << "姓名" << space << "地址" << space << "电话" << space << "部门" << space << "工资" << space << "参加工作时间" << space << "专业" << space << "职务" << space << "备注" << endl;
      while (in.peek() != EOF)
      {
       in.getline(line, 100000);
       ss << line;
       ss >> stu.IDNumber >> stu.name >> stu.address >> stu.phone >> stu.department >> stu.wage >> stu.time >> stu.spe >> stu.zhiwu >> stu.remarks;
       if (stu.wage<max(max1,min1)&&stu.wage>min(max1,min1))
       cout << space << stu.IDNumber << space << stu.name << space << stu.address << space << stu.phone << space << stu.department << space << stu.wage << space << stu.time << space << stu.spe << space << stu.zhiwu << space << stu.remarks << NEWLINE;
       ss.str("");
       ss.clear();
      }
      in.close();
     }
    }
    void searchtime(const char *filename)
    {
     int max1, min1;
     cout << "请输入教师参加工作时间范围(最大、最小)" << endl;
     cin >> max1 >> min1;
     students stu;
     ifstream in;
     in.open(filename, ios::in);
     if (!in.is_open())
     {
      cout << "file open error" << endl;
      return;
     }
     else
     {
      stringstream ss;
      char line[100000];
      cout.setf(ios::left);
      cout.fill(' ');
      cout << space << "身份证号" << space << "姓名" << space << "地址" << space << "电话" << space << "部门" << space << "工资" << space << "参加工作时间" << space << "专业" << space << "职务" << space << "备注" << endl;
      while (in.peek() != EOF)
      {
       in.getline(line, 100000);
       ss << line;
       ss >> stu.IDNumber >> stu.name >> stu.address >> stu.phone >> stu.department >> stu.wage >> stu.time >> stu.spe >> stu.zhiwu >> stu.remarks;
       if (stu.time<max(max1, min1) && stu.time>min(max1, min1))
        cout << space << stu.IDNumber << space << stu.name << space << stu.address << space << stu.phone << space << stu.department << space << stu.wage << space << stu.time << space << stu.spe << space << stu.zhiwu << space << stu.remarks << NEWLINE;
       ss.str("");
       ss.clear();
      }
      in.close();
     }
    }
    int main()
    {

     const char *filename = "D:\teachermanage.txt";
     while (true)
     {
      cout << "--------------------------" << endl;
      cout << "0、查看全部信息" << endl;
      cout << "1、新增教师信息" << endl;
      cout << "2、删除教师信息" << endl;
      cout << "3、修改教师信息" << endl;
      cout << "4、查找教师信息(身份证号)" << endl;
      cout << "5、查找教师信息(姓名)" << endl;
      cout << "6、查找教师信息(工资)" << endl;
      cout << "7、查找教师信息(工作时间)" << endl;
      int cmd;
      cin >> cmd;
      system("cls");
      switch (cmd)
      {
      case 0:read(filename); break;
      case 1:write(filename); break;
      case 2:del(filename); break;
      case 3:edit(filename); break;
      case 4:searchID(filename); break;
      case 5:searchName(filename); break;
      case 6:searchwage(filename); break;
      case 7:searchtime(filename); break;
      }
     }
     return 0;
    }
     
     
     
    //新增出生年月查询     未增加出生年月属性,而是通过身份证号进行教师身份的查询
    void searchbirth(const char *filename)
    {
     int max1, min1;
     cout << "请输入教师出生年月范围(最大、最小)" << endl;
     cin >> max1 >> min1;
     students stu;
     ifstream in;
     in.open(filename, ios::in);
     if (!in.is_open())
     {
      cout << "file open error" << endl;
      return;
     }
     else
     {
      stringstream ss;
      char line[100000];
      cout.setf(ios::left);
      cout.fill(' ');
      cout << space << "身份证号" << space << "姓名" << space << "地址" << space << "电话" << space << "部门" << space << "工资" << space << "参加工作时间" << space << "专业" << space << "职务" << space << "备注" << endl;
      while (in.peek() != EOF)
      {
       in.getline(line, 100000);
       ss << line;
       ss >> stu.IDNumber >> stu.name >> stu.address >> stu.phone >> stu.department >> stu.wage >> stu.time >> stu.spe >> stu.zhiwu >> stu.remarks;
       string t(stu.IDNumber.substr(6, 8));
       int b = atoi(t.c_str());
       if (b<max(max1, min1) && b>min(max1, min1))
        cout << space << stu.IDNumber << space << stu.name << space << stu.address << space << stu.phone << space << stu.department << space << stu.wage << space << stu.time << space << stu.spe << space << stu.zhiwu << space << stu.remarks << NEWLINE;
       ss.str("");
       ss.clear();
      }
      in.close();
     }
    }
     
     
     
  • 相关阅读:
    【随机过程】随机过程之泊松过程的直观理解
    【随机过程】随机过程之泊松过程的直观理解
    【读书笔记】程序员的自我修养总结(四)
    【读书笔记】程序员的自我修养总结(四)
    【编程开发】CMake相关注意事项
    【编程开发】CMake相关注意事项
    【随机过程】几种容易混淆的概率分布
    【随机过程】几种容易混淆的概率分布
    【DSP开发】DSP能用VS2010生成的链接库文件吗?
    【DSP开发】DSP能用VS2010生成的链接库文件吗?
  • 原文地址:https://www.cnblogs.com/NCLONG/p/11129401.html
Copyright © 2011-2022 走看看