用vector容器写职工管理系统
2017-02-12 19:48
225 查看
职工信息管理系统:
存在一个数据文件,用来存储职工各种信息:职工号,姓名,年龄,性别,
邮编,部门,工资
可以注册新职工;
允许修改职工信息
允许删除职工信息;
4,按照按照姓名和部门查询职工信息;
可以按照工资多少进行排名,
可以浏览所有职工信息;
.有一个主界面,供选择和调用上述选项。
.用C++中,文件和链表实现
1、头文件control.h
2、主函数Staff management system.cpp
存在一个数据文件,用来存储职工各种信息:职工号,姓名,年龄,性别,
邮编,部门,工资
可以注册新职工;
允许修改职工信息
允许删除职工信息;
4,按照按照姓名和部门查询职工信息;
可以按照工资多少进行排名,
可以浏览所有职工信息;
.有一个主界面,供选择和调用上述选项。
.用C++中,文件和链表实现
1、头文件control.h
#ifndef CONTROL_H #define CONTROL_H #include <iostream> #include <vector> #include <string> #include <functional> #include <algorithm> #include <fstream> using namespace std; class Stuff { public: string ID; string name; string age; string sex; string postcodes; string department; string salary; }; class Control { public: void system_init(vector<Stuff> &p); void jiemian(); void Creat_list_tail(vector<Stuff> &p); void Del(vector<Stuff> &p); void Change(vector<Stuff> &p); void Search(vector<Stuff> &p); void Display(vector<Stuff> &p); void Sort(vector<Stuff> &p); }; #endif
2、主函数Staff management system.cpp
#include "control.h" void Control::jiemian() { cout<<endl; 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<<"* (0)退出 *"<<endl; cout<<"* 选择相对的括号里的阿拉伯数字! *"<<endl; cout<<"*******************************************"; cout<<endl; cout<<endl; } void Control::Creat_list_tail(vector<Stuff> &vec) { Stuff m; cout<<"请输入职工号:"; cin>>m.ID; cout<<endl<<"请输入姓名:"; cin>>m.name; cout<<endl<<"请输入年龄:"; cin>>m.age; cout<<endl<<"请输入性别:"; cin>>m.sex; cout<<endl<<"请输入邮编:"; cin>>m.postcodes; cout<<endl<<"请输入部门:"; cin>>m.department; cout<<endl<<"请输入工资:"; cin>>m.salary; vec.push_back(m); } void Control::Del(vector<Stuff> &vec) { string department; string name; int temp = 0; cout<<"请输入部门:"; cin>>department; cout<<endl<<"请输入姓名"; cin>>name; vector<Stuff>::iterator it; for(it=vec.begin(); it!=vec.end(); ++it) { if( ((*it).department == department) && ((*it).name == name)) { vec.erase(it); temp = 1; break; } } if(temp) { cout<<"删除职工"<<name<<"信息成功"<<endl; } else { cout<<"未找到匹配信息"<<endl; } } void Control::Change(vector<Stuff> &vec) { string department; string name; int temp = 0; cout<<"请输入部门:"<<endl; cin>>department; cout<<"请输入姓名"<<endl; cin>>name; vector<Stuff>::iterator it; for(it=vec.begin(); it!=vec.end(); ++it) { if( ((*it).department == department) && ((*it).name==name)) { cout<<"旧的数据"<<endl; cout<<"职工号:"<<(*it).ID<<" 姓名:"<<(*it).name<<" 年龄:"<<(*it).age<<" 性别:"<<(*it).sex<<" 邮编:"<<(*it).postcodes<<" 部门:"<<(*it).department<<" 工资:"<<(*it).salary<<endl; cout<<"请输入新数据..."<<endl; cout<<"请输入职工号:"; cin>>(*it).ID; cout<<endl<<"请输入姓名:"; cin>>(*it).name; cout<<endl<<"请输入年龄:"; cin>>(*it).age; cout<<endl<<"请输入性别:"; cin>>(*it).sex; cout<<endl<<"请输入邮编:"; cin>>(*it).postcodes; cout<<endl<<"请输入部门:"; cin>>(*it).department; temp = 1; break; } } if(temp) { cout<<"修改职工"<<name<<"信息成功"<<endl; } else { cout<<"未找到匹配信息"<<endl; } } void Control::Search(vector<Stuff> &vec) { string department; string name; int temp = 0; cout<<"请输入部门:"<<endl; cin>>department; cout<<"请输入姓名"<<endl; cin>>name; vector<Stuff>::iterator it; for(it=vec.begin(); it!=vec.end(); ++it) { if( ((*it).department == department)&&((*it).name == name) ) { cout<<"职工号:"<<(*it).ID<<" 姓名:"<<(*it).name<<" 年龄:"<<(*it).age<<" 性别:"<<(*it).sex<<" 邮编:"<<(*it).postcodes<<" 部门:"<<(*it).department<<" 工资:"<<(*it).salary<<endl; temp = 1; } } if(!temp) { cout<<"未找到匹配信息"<<endl; } } void Control::Display(vector<Stuff> &vec) { vector<Stuff>::iterator it; for(it=vec.begin(); it!=vec.end(); it++) { cout<<"职工号:"<<(*it).ID<<" 姓名:"<<(*it).name<<" 年龄:"<<(*it).age<<" 性别:"<<(*it).sex<<" 邮编:"<<(*it).postcodes<<" 部门:"<<(*it).department<<" 工资:"<<(*it).salary<<endl; } } bool cmp( Stuff &a, Stuff &b ) { return a.salary > b.salary; } void Control::Sort(vector<Stuff> &vec) { sort(vec.begin(), vec.end(), cmp); Display(vec); } void Control::system_init(vector<Stuff> &vec) { fstream infile("stud.txt",ios::in); if(!infile) { cerr<<"open error!"<<endl; abort( ); } Stuff temp; Control t; while(1) { memset(&temp, 0, sizeof(temp)); if(infile.read((char *)&temp,sizeof(Stuff))) { cout<<"职工号:"<<(temp).ID<<" 姓名:"<<(temp).name<<" 年龄:"<<(temp).age<<" 性别:"<<(temp).sex<<" 邮编:"<<(temp).postcodes<<" 部门:"<<(temp).department<<" 工资:"<<(temp).salary<<endl; vec.push_back(temp); } else { infile.close( ); cout<<"载入本地信息成功"<<endl; break; } } } int main() { char flag; vector<Stuff> vec; Control con; con.system_init(vec); do { con.jiemian(); //显示界面 cin>>flag; cout<<endl; switch(flag) { case '1': con.Creat_list_tail(vec); break; case '2': con.Del(vec); break; case '3': con.Change(vec); break; case '4': con.Search(vec); break; case '5': con.Display(vec); break; case '6': con.Sort(vec); break; } }while(flag!='0'); vector<Stuff>::iterator it; Stuff temp; fstream outfile("stud.txt",ios::out); if(!outfile) { cerr<<"open error!"<<endl; abort( ); } for(it = vec.begin(); it != vec.end(); it++) { temp.age = it->age; temp.department = it->department; temp.ID = it->ID; temp.name = it->name; temp.sex = it->sex; temp.postcodes = it->postcodes; temp.salary = it->salary; outfile.write((char *)&temp,sizeof Stuff); cout<<"职工号:"<<(*it).ID<<" 姓名:"<<(*it).name<<" 年龄:"<<(*it).age<<" 性别:"<<(*it).sex<<" 邮编:"<<(*it).postcodes<<" 部门:"<<(*it).department<<" 工资:"<<(*it).salary<<endl; } cout<<"保存信息成功!"<<endl; outfile.close( ); return 0; }
相关文章推荐
- 用vector容器写职工管理系统
- 用vector容器写职工管理系统
- 用vector容器写职工管理系统
- 用vector容器写职工管理系统
- 用vector容器写职工管理系统
- 用vector容器写职工管理系统
- 用vector容器写职工管理系统
- 员工管理系统之 STL(容器)的vector
- 职工管理系统(list容器)
- 基于容器的用户安全管理系统和JMS(5)
- 基于容器的用户安全管理系统和JMS(6)
- 《c语言课程设计》---职工信息管理系统
- 自动1122徐达武职工信息管理系统(无图)
- C++课程设计:职工综合信息管理系统
- 自动1122徐达武--——职工信息管理系统
- JAVA JDBC实现的职工管理系统(Console版)(期中java课程设计)
- 职工信息管理系统
- 职工管理系统
- 课程设计之职工工资的管理系统
- 职工工资管理系统