C++实现教职工信息管理系统课程设计
本文实例为大家分享了C++实现教职工信息管理系统的具体代码,供大家参考,具体内容如下
/*教职工信息管理基本要求:定义职工(employee )类,其中至少包括姓名、性别、工号、电话、所在系部和职称。功能要求:1、设计菜单实现功能选择;2、输入功能:输入职工信息,并保存到文件中;3、查询功能:1)能够根据工号精确查询职工信息;2)能够根据姓名、科室查询职工信息3)分系部进行职称统计,计算各职称的人数4、根据职工的职称排序输出5、根据工号修改职工信息6、根据工号删除职工信息*/#include#include #include using namespace std; class employee{public:employee(){}employee(char na[50], char sex[50], int num, char tel[20], char off[50], char pos[50]) :m_number(num){strcpy(m_name, na); strcpy(m_sex, sex); strcpy(m_telephone, tel); strcpy(m_office, off); strcpy(m_posting, pos); }int getnum(){return m_number; }char *getna()//{return m_name; }char *getoff(){return m_office; }char *getposting()//{return m_posting; }friend ostream& operator <<(ostream &os, const employee & s){os << "姓名:" << s.m_name << "性别:" << s.m_sex << "工号:" << s.m_number << "电话:" << s.m_telephone << "所在系部:" << s.m_office << "职称:" << s.m_posting << endl; return os; }friend istream& operator >>(istream &is, employee &s){is >> s.m_name >> s.m_sex >> s.m_number >> s.m_telephone >> s.m_office >> s.m_posting; return is; }~employee(){}private:char m_name[50]; char m_sex[50]; int m_number; char m_telephone[20]; char m_office[50]; char m_posting[50]; };
菜单功能选择:
void menu()//1)菜单功能选择{cout << "*************************************教职工信息管理系统*************************************" << endl; cout << "**----------------------------------------------------------------------------------------------**" << endl; 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 << "**| * 0.关闭系统|**" << endl; cout << "**-----------------------------**" << endl; cout << "**----------------------------------------------------------------------------------------------**" << endl; cout << "**请输入序号使用对应的功能:(0,1,2,3,4,5,6,7,8)**" << endl; cout << "**************************************************************************************************" << endl; }
输入信息:
void input()//2)输入保存{fstream fs; int len; cout << "请输入教职工人数:" << endl; cin >> len; employee *emp = new employee[len]; //开辟空间,存教职工数据fs.open("guanli.dat", ios::out | ios::app | ios::binary); if (!fs)cout << "Open failed." << endl; else{cout << "Open succeedly." << endl; cout << "请输入教职工的姓名,性别,工号,电话,所在系部,职称:" << endl; for (int i = 0; i> emp[i]; fs.write((char *)& emp[i], sizeof(emp[i])); //fs<
查询功能(根据工号):
void find1()//3-1)查询---能够根据工号精确查询职工信息;{int num; cout << "请输入教职工的工号:" << endl; cin >> num; fstream fs; fs.open("guanli.dat", ios::in | ios::binary); fs.seekg(0, ios::end); //文件调到末尾int s = fs.tellg(); //告诉文件大小int n = s / sizeof(employee); //计算职工人数fs.seekg(ios::beg); //文件指针调到文件开头employee *emp = new employee[n]; for (int i = 0; i
查询功能(根据姓名、科室):
void find2()//3-2)查询---能够根据姓名、科室查询职工信息{char na[50]; char off[50]; cout << "请输入教职工的姓名:" << endl; cin >> na; cout << "请输入教职工所属科室:" << endl; cin >> off; fstream fs; fs.open("guanli.dat", ios::in | ios::binary); fs.seekg(0, ios::end); int s = fs.tellg(); int n = s / sizeof(employee); fs.seekg(ios::beg); employee *emp = new employee[n]; for (int i = 0; i
统计人数:
void find3()//3-3)分系部进行职称统计,计算各职称的人数{char off[50], posting[50]; cout << "请输入所查系部:" << endl; cin >> off; cout << "请输入所查职称:" << endl; cin >> posting; fstream fs; fs.open("guanli.dat", ios::in | ios::binary); fs.seekg(0, ios::end); int s = fs.tellg(); int n = s / sizeof(employee); fs.seekg(ios::beg); employee *emp = new employee[n]; for (int i = 0; i
排序输出:
void output()//4)根据职工的职称排序输出{fstream fs; fs.open("guanli.dat", ios::in | ios::binary); fs.seekg(0, ios::end); int s = fs.tellg(); int n = s / sizeof(employee); fs.seekg(ios::beg); employee *emp = new employee[n]; for (int i = 0; i0){temp = emp[k]; emp[k] = emp[k + 1]; emp[k + 1] = temp; }}}for (i = 0; i
修改功能:
void modify()//5)根据工号修改职工信息{fstream fs; fs.open("guanli.dat", ios::in | ios::out | ios::binary); fs.seekg(0, ios::end); int s = fs.tellg(); int n = s / sizeof(employee); fs.seekg(ios::beg); employee *emp = new employee[n]; for (int i = 0; i> num; int a=-100; for (i = 0; i < n; i++){if (num == emp[i].getnum()){fs.seekp(sizeof(employee)*i); employee e; cout << "请输入要修改的教职工的姓名,性别,工号,电话,所属系部,职称:" << endl; cin >> e; fs.write((char *)&e, sizeof(employee)); cout << "职工信息修改成功!" << endl; a = i; }}if(a==-100)cout << "工号不正确!无此人!" << endl; fs.close(); delete[] emp; }
删除功能:
void del()// 6)根据工号删除职工信息{fstream fs; fs.open("guanli.dat", ios::in | ios::out | ios::binary); fs.seekg(0, ios::end); int s = fs.tellg(); int n = s / sizeof(employee); fs.seekg(ios::beg); employee *emp = new employee[n]; for (int i = 0; i> num; int a=-100; for ( i = 0; i = 0 && a <= n)cout << "删除成功!" << endl; elsecout << "删除失败!" << endl; fs.close(); fs.clear(); delete[] emp; }
查看功能:
void show()//8.查看所有人员信息{fstream fs; fs.open("guanli.dat", ios::in | ios::binary); fs.seekg(0, ios::end); int s = fs.tellg(); int n = s / sizeof(employee); fs.seekg(ios::beg); employee *emp = new employee[n]; for (int i = 0; i
主函数:
int main(){char flag = 'n'; while (flag == 'n' || flag == 'N')//由y/n控制循环{menu(); int judge; cin >> judge; if (judge >= 0 && judge <= 8){switch (judge){case 0:cout << "是否退出系统(y/n):" << endl; cin >> flag; break; case 1:input(); break; case 2:find1(); break; case 3:find2(); break; case 4:find3(); break; case 5:output(); break; case 6:modify(); break; case 7:del(); break; case 8:show(); break; default:break; }}elsecout << "输入错误,请重新输入!" << endl; cout << "------------------------------------------Press any key to continue!------------------------------" << endl; getchar(); getchar(); system("cls"); }return 0; }
【C++实现教职工信息管理系统课程设计】运行主界面:(其余的图就不图啦)
文章图片
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
推荐阅读
- QT实现单词检索软件的示例代码
- python写tcp传输程序_Python实现tcp网络传输 python怎么实现tc
- linux|linux sha1 字符串,linux sha1 实现
- linux中用c语言实现ping函数|linux中用c语言实现ping函数,linux c语言实现ping
- C++|基于QT实现简单的TCP通信
- QT|Qt实现隐藏按钮功能
- QT|QT实现TCP通信
- Python|python实现UDP
- [Qt学习笔记]Qt实现多摄像头的识别、显示、截图、分辨率帧率设置等功能
- OpenCV使用级联分类器实现人脸检测