本文实例为大家分享了c++实现教职工信息管理系统的具体代码,供大家参考,具体内容如下
一个小公司包含四类人员:经理,技术人员,销售人员和销售经理,各类人员的工资计算方法如下:经理:固定月薪(8000);技术人员:月薪按技术等级(1~8)(1600+等级*300);销售人员:按提成(4%*销售额);销售经理:底薪+提成(1500+0.2%*总销售额);设计一个管理程序,实现对各类人员的信息输入,修改和显示。
(1)使用面向对象编程思想编写开发过程中需要用到的类,比如:设计person类:编号,姓名,岗位,工资,成员函数孟州市政府可设一个计算月薪的纯虚函数;另外再设计四个针对四类人员的类均继承 person;添加相应的派生类数据成员和函数,经理和销售经理可以没有新的数据成员,计算月薪即可; 技术人员添加技术等级数据成员,销售人员添加数据成员:销售额。还需设计一个manage 类来完成各种操作。人员数组 vector,数据类型为基类指针。
(2)需要使用菜单功能显示添加人员(输入),修改信息,浏览信息,按姓名查找,月薪排序。
(3)为了设计简洁,假定经理和销售经理都只能有一个;用文本编辑器编辑一个文本文件(总数 20 人以上)包含各类人员的信息;并且在程序中能修改保存。
#include<iostream>#include<vector>#include<string>#include<cstdlib>#include<windows.h>#include<iomanip>#include<fstream>#include <algorithm>#define filename "student.txt"using namespace std;class person{public: person(string, string, int = 0);//构造函数 double virtual pay_salary() = 0; //借用虚函数进行工资初始化 void virtual show(); //显示信息 bool operator<(const person*&) const; //重载<比较薪水大小用于排序 static int num; //定义静态变量,自动赋予员工编号 int number; //编号 double salary;//工资 string name;//姓名 string department;//部门 int c;//技术级};bool person::operator<(const person*& obj) const//函数重载<,用于比较薪水{ return this->salary > obj->salary;}person::person(string name1, string work1, int c1) //构造函数的实现{ c = c1; number = num++; name = name1; department = work1;}int person::num = 1;//编号从1开始void person::show() { cout<<"-----------------------------------"<<endl; cout <<right<<tw(3)<<number<<tw(10)<<name<<tw(11)<<department<<tw(8)<<salary; //tw()控制输出宽度 }class manager :public person //经理类,继承person类{public: manager(string, string, int);//构造函数 double pay_salary();//计算工资函数 void show();//显示经理的信息};manager::manager(string name1, string post1, int c1) :person(name1, post1, c1) //构造函数 的实现{ pay_salary();}double manager::pay_salary()//计算经理的工资{ salary = 8000; return salary;}void manager::show() //显示经理的信息{ cout<<"-----------------------------------"<<endl; cout <<right<<tw(3)<<number<<tw(10)<<name<<tw(9)<<department<<tw(10)<<salary;}class salemanager :public person//销售经理类,继承person类{public: salemanager(string, string, int);//构造函数 double pay_salary();//计算销售经理的工资 void show();//显示销售经理的信息};salemanager::salemanager电子商务发展前景(string name1, string post1, int c1) :person(name1, post1, c1)//构造函数 的实现{ pay_salary();}double salemanager::pay_salary() //计算经理的工资,基本工资 1500元{ salary = 亲子游戏音乐1500; return salary;}void salemanager::show() //显示销售经理的信息{ cout<<"-----------------------------------"<<endl; cout <<right<<tw(3)<<number<<tw(10)<<name<<tw(11)<<department<<tw(8)<<salary;}class salesman :public person//销售人员类,继承person类{public: salesman(string, string, int);//构造函数 int salevolume;//销售额 double pay_salary();//计算销婚礼背景音乐大全售人员的工资 void show();//显示销售人员的信息};salesman::salesman(string name1, string post1, int sv) :person(name1, post1, sv)//构造函数的实现{ salevolume = sv; pay_salary();}double salesman::pay_salary()//计算销售人员工资,4%×销售额{ salary = 0.04 * salevolume; return salary;}void salesman::show() //显示销售人员的信息{ cout<<"-----------------------------------"<<endl; cout <<right<<tw(3)<<number<<tw(10)<<name<<tw(11)<<department<<tw(8)<<salary;}class technician :public person //技术人员类,继承person类{public: technician(string, string, int);//技术等级为继承来的参数c double pay_salary();//计算技术人员的工资 void show();//显示技术人员的所有信息};technician::technician(string name1, string post1, int rank1) :person(name1, post1, rank1){ pay_salary();}double technician::pay_salary() //计算技术人员的工资,技术等级×300+1600{ salary = 1600 + 300 * c; return salary;}void technician::show()//显示所有技术人员的信息{ cout<<"-----------------------------------"<<endl; cout <<right<<tw(3)<<number<<tw(10)<<name<<tw(11)<<department<<tw(8)<<salary;}class manage//管理类{public: void menu() { salevolume = 0; }//菜单函数 int salevolume;//总销售额 vector<person*> ma;//vector数组,存放person类的对象指针 void add(person*);//添加人员信息 void alter(string);//删除人员信息 void addtofile();//写入文件 void show();//显示所有信息 void show1();//按月薪降序 person* find(string&);//查找人员信息};person* manage::find(string& name1) { //查找 for (vector<person*>::iterator iter = ma.begin(); iter != ma.end(); iter++) { if ((*iter)->name == name1) { return *iter; } } return null;}void manage::alter(string name1) { //删除 for (vector<person*>::iterator iter = ma.begin(); iter != ma.end(); iter++) { if ((*iter)->name == name1) { ma.era(iter); return; } } cout << "查无此人" << endl;}void manage::add(person* people) //添加{ if (people->department == "销售人员") { salevolume += ((salesman*)people)->salevolume; } ma.push_back(people);}void manage::addtofile()//写入文件{ ofstream outfile(filename);//打开文件写入 for (vector<person*>::iterator iter = ma.begin(); iter != ma.end(); iter++) { outfile << (*iter)->department << " " << (*iter)->name << " "; if ((*iter)->c == 0) outfile << endl; el outfile << (*iter)->c << endl; } outfile.clo();//关闭}bool cmp(person* x, person* y) { //比较薪水 return x->salary > y->salary;}void manage::show() { for (vector<person*>::iterator iter = ma.begin(); iter != ma.end(); iter++) { if ((*iter)->department == "销售经理") { (*iter)->salary = salevolume * 0.002 +1500; break; } } sort(ma.begin(), ma.end(), cmp);//薪水大小排序 for (vector<person*>::iterator iter = ma.begin(); iter != ma.end(); iter++) { (*iter)->show(); cout << endl; }}void readfile(manage& obj)//读取文件{ file* fp; fp = fopen(filename, "r");//打开文件,只读 if (fp == null) { cout << "未找到人员名单" << endl; return; } while (!feof(fp)) { char post[20]; char name[20]; int c; //销售额或技术等级 fscanf(fp, "%s%s%d", post, name,&c); if (!strcmp(post, "经理")) { //文件中为经理的人的信息先填入 person* 硕士答辩开场白peo = new manager(name, post, 0); obj.add(peo); } el if (!strcmp(post, "技术人员")) { person* peo = new technician(name, post, c); obj.add(peo); } el if (!strcmp(post, "销售人员")) { person* peo = new salesman(name, post, c); obj.add(peo); } el if (!strcmp(post, "销售经理")) { person* peo = new salemanager(name, post, 0); obj.add(peo); } } fclo(fp);//关闭文件}void manage::show1()//对vector数组进行读取{ for (vector<person*>::iterator iter = ma.begin(); iter != ma.end(); iter++) { (*iter)->show(); cout << endl; }}int main(){ int x; manage t; readfile(t); while(1){ cout<< " ———————————————————————————————" << endl << " | 公司人事管理系统 |" << endl << " ———————————————————————————————" << endl << " | 1.添加员工 |" << endl << " | 2.修改信息 |" << endl << " | 3.按姓名查找 |" << endl << " | 4.显示所有信息 |" << endl << " | 5.按月薪降序排序 |" << endl << " | 0.保存并退出程序 |" << endl << " ———————————————————————————————" << endl; cout<< "请选择->"; cin >> x; switch (x) { ca 1: { while (1) { int n; string name; cout << "请输入姓名:" ; cin >> name; cout << "请输入人员岗位(1.经理 2.技术人员 3. 销售人员 4.销售经理):" ; cin >> n; if (n == 1) { person* peo = new manager(name, "经理", 0); t.add(peo); cout << "添加成功" << endl << endl << endl; break; } el if (n == 2) { while (1) { int rank = 0; cout << "请输入技术等级(1~8):" ; cin >> rank; if (rank > 8 || rank < 1) { cout << "输入错误,请在1~8之间输入:" ; } el { person* peo = new technician(name, "技术人员", rank); t.add(peo); break; } } cout << "添加成功" << endl << endl << endl; break; } el if (n == 3) { int sales = 0; cout << "请输入销售额:" << endl; cin >> sales; person* peo = new salesman(name, "销售人员", sales); t.add(peo); cout << "添加成功" << endl << endl << endl; break; } el if (n == 4) { person* peo = new salemanager(name, "销售经理", 0); t.add(peo); cout << "添加成功" << endl << endl << endl; break; } el { cout << "输入错误,请重新输入:" << endl; } } system("pau");} break; ca 2: { string name; int n = 0; cout << "请输入姓名:" ; cin >> name; person* peo = t.find(name); if (peo == null) { cout << " 查无此人" << endl << endl << endl; break; } peo->show(); if (peo->department == "经理") { cout << " 经理无法修改" << endl; } el if (peo->department == "技术人员") { int rank = 0; while (1) { cout <<endl<< "请输入技术等级(1~8):" << endl; cin >> rank; if (rank > 8 || rank < 1) { cout << "等级输入错误,请重新输入" << endl; } el break; } t.alter(name); peo = new technician(name, "技术人员", rank); t.add(peo); cout << "修改成功!" << endl; } el if (peo->department == "销售人员") { int sales = 0; cout <<endl<< "请输入销售额:" << endl; cin >> sales; t.alter(name); peo = new salesman(name, "销售人员", sales); t.add(peo); cout << " 修改成功!" << endl; } el if (peo->department == "销售经理") { cout << " 销售经理无法修改" << endl; } el { cout << "输入错误" << endl; } }system("pau"); break; ca 3: { string name; int n = 0; cout << "请输入所查找人的姓名:"; cin >> name; person* peo = t.find(name); if (peo == null) { cout << "查无此人" << endl; system("cls"); break; } cout<<"-----------------------------------"<<endl; cout <<left<<tw(8)<<"序 号"<<tw(9)<<"姓 名"<<tw(10)<<"岗 位"<<tw(10)<<"工 资"<< endl; peo->show(); cout<<endl<<"-----------------------------------"<<endl; cout << endl; system("pau"); } break; ca 4: { cout<<"-----------------------------------"<<endl; cout <<left<<tw(8)<<"序 号"<<tw(9)<<"姓 名"<<tw(10)<<"岗 位"<<tw(10)<<"工 资"<< endl; t.show1(); cout<<"-----------------------------------"<<endl; system("pau"); system("cls"); } break; ca 5: { cout<<"-----------------------------------"<<endl; cout <<left<<tw(8)<<"序 号"<<tw(9)<<"姓 名"<<tw(10)<<"岗 位"<<tw(10)<<"工 资"<< endl; t.show(); } system("pau"); break; ca 0: t.addtofile(); exit(0); default: cout << "输入错误请重新输入" << endl; break; } } return 0;}
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持www.887551.com。
本文发布于:2023-04-06 04:41:21,感谢您对本站的认可!
本文链接:https://www.wtabcd.cn/fanwen/zuowen/3032f42215a0bcd56bcbd1aba024a4d6.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文word下载地址:C++实现教职工信息管理系统.doc
本文 PDF 下载地址:C++实现教职工信息管理系统.pdf
留言与评论(共有 0 条评论) |