網(wǎng)站首頁(yè) 編程語(yǔ)言 正文
本文實(shí)例為大家分享了C++實(shí)現(xiàn)教職工信息管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下
一.問(wèn)題描述
一個(gè)小公司包含四類人員:經(jīng)理,技術(shù)人員,銷(xiāo)售人員和銷(xiāo)售經(jīng)理,各類人員的工資計(jì)算方法如下:經(jīng)理:固定月薪(8000);技術(shù)人員:月薪按技術(shù)等級(jí)(1~8)(1600+等級(jí)*300);銷(xiāo)售人員:按提成(4%*銷(xiāo)售額);銷(xiāo)售經(jīng)理:底薪+提成(1500+0.2%*總銷(xiāo)售額);設(shè)計(jì)一個(gè)管理程序,實(shí)現(xiàn)對(duì)各類人員的信息輸入,修改和顯示。
二 .基本要求
(1)使用面向?qū)ο缶幊趟枷刖帉?xiě)開(kāi)發(fā)過(guò)程中需要用到的類,比如:設(shè)計(jì)Person類:編號(hào),姓名,崗位,工資,成員函數(shù)可設(shè)一個(gè)計(jì)算月薪的純虛函數(shù);另外再設(shè)計(jì)四個(gè)針對(duì)四類人員的類均繼承 Person;添加相應(yīng)的派生類數(shù)據(jù)成員和函數(shù),經(jīng)理和銷(xiāo)售經(jīng)理可以沒(méi)有新的數(shù)據(jù)成員,計(jì)算月薪即可; 技術(shù)人員添加技術(shù)等級(jí)數(shù)據(jù)成員,銷(xiāo)售人員添加數(shù)據(jù)成員:銷(xiāo)售額。還需設(shè)計(jì)一個(gè)Manage 類來(lái)完成各種操作。人員數(shù)組 vector,數(shù)據(jù)類型為基類指針。
(2)需要使用菜單功能顯示添加人員(輸入),修改信息,瀏覽信息,按姓名查找,月薪排序。
(3)為了設(shè)計(jì)簡(jiǎn)潔,假定經(jīng)理和銷(xiāo)售經(jīng)理都只能有一個(gè);用文本編輯器編輯一個(gè)文本文件(總數(shù) 20 人以上)包含各類人員的信息;并且在程序中能修改保存。
基本流程圖
#include#include #include #include #include #include #include #include #define filename "student.txt" using namespace std;? class Person { public: ?? ?Person(string, string, int = 0);//構(gòu)造函數(shù)? ?? ?double virtual pay_salary() = 0; //借用虛函數(shù)進(jìn)行工資初始化? ?? ?void ?virtual show(); ?? ??? ?//顯示信息? ?? ?bool operator<(const Person*&) const;?? ?//重載<比較薪水大小用于排序? ?? ?static int num; //定義靜態(tài)變量,自動(dòng)賦予員工編號(hào)? ?? ?int Number; ? //編號(hào)? ?? ?double Salary;//工資? ?? ?string Name;//姓名? ?? ?string Department;//部門(mén)? ?? ?int c;//技術(shù)級(jí)? }; bool Person::operator<(const Person*& obj) const//函數(shù)重載<,用于比較薪水? { ?? ?return this->Salary > obj->Salary; } Person::Person(string name1, string work1, int c1) //構(gòu)造函數(shù)的實(shí)現(xiàn)? { ?? ?c = c1; ?? ?Number = num++; ?? ?Name = name1; ?? ?Department = work1; } int Person::num = 1;//編號(hào)從1開(kāi)始? void ?Person::show() { ?? ?cout<<"-----------------------------------"< Ma;//vector數(shù)組,存放Person類的對(duì)象指針? ?? ?void add(Person*);//添加人員信息? ?? ?void alter(string);//刪除人員信息? ?? ?void addtofile();//寫(xiě)入文件? ?? ?void show();//顯示所有信息? ?? ?void show1();//按月薪降序? ?? ?Person* find(string&);//查找人員信息? }; Person* Manage::find(string& name1) { //查找 ?? ?for (vector ::iterator iter = Ma.begin(); iter != Ma.end(); iter++) { ?? ??? ?if ((*iter)->Name == name1) { ?? ??? ??? ?return *iter; ?? ??? ?} ?? ?} ?? ?return NULL; } void Manage::alter(string name1) { //刪除 ?? ?for (vector ::iterator iter = Ma.begin(); iter != Ma.end(); iter++) { ?? ??? ?if ((*iter)->Name == name1) { ?? ??? ??? ?Ma.erase(iter); ?? ??? ??? ?return; ?? ??? ?} ?? ?} ?? ?cout << "查無(wú)此人" << endl; } void Manage::add(Person* people) //添加? { ?? ?if (people->Department == "銷(xiāo)售人員") { ?? ??? ?salevolume += ((Salesman*)people)->salevolume; ?? ?} ?? ?Ma.push_back(people); } void Manage::addtofile()//寫(xiě)入文件? ?{ ?? ?ofstream outfile(filename);//打開(kāi)文件寫(xiě)入? ?? ?for (vector ::iterator iter = Ma.begin(); iter != Ma.end(); iter++) { ?? ??? ?outfile << (*iter)->Department << " " << (*iter)->Name << " "; ?? ??? ?if ((*iter)->c == 0) outfile << endl; ?? ??? ?else outfile << (*iter)->c << endl; ?? ?} ?? ?outfile.close();//關(guān)閉? } bool cmp(Person* x, Person* y) { //比較薪水 ?? ?return x->Salary > y->Salary; } void Manage::show() { ?? ?for (vector ::iterator iter = Ma.begin(); iter != Ma.end(); iter++) { ?? ??? ?if ((*iter)->Department == "銷(xiāo)售經(jīng)理") { ?? ??? ??? ?(*iter)->Salary = salevolume * 0.002 +1500; ?? ??? ??? ?break; ?? ??? ?} ?? ?} ?? ?sort(Ma.begin(), Ma.end(), cmp);//薪水大小排序 ?? ?for (vector ::iterator iter = Ma.begin(); iter != Ma.end(); iter++) { ?? ??? ?(*iter)->show(); ?? ??? ?cout << endl; ?? ?} } void readfile(Manage& obj)//讀取文件? ?{ ?? ?FILE* fp; ?? ?fp = fopen(filename, "r");//打開(kāi)文件,只讀? ?? ?if (fp == NULL) { ?? ??? ?cout << "未找到人員名單" << endl; ?? ??? ?return; ?? ?} ?? ?while (!feof(fp)) { ?? ??? ?char post[20]; ?? ??? ?char Name[20]; ?? ??? ?int c; ? //銷(xiāo)售額或技術(shù)等級(jí) ?? ??? ?fscanf(fp, "%s%s%d", post, Name,&c); ?? ??? ?if (!strcmp(post, "經(jīng)理")) { //文件中為經(jīng)理的人的信息先填入 ?? ??? ??? ?Person* peo = new Manager(Name, post, 0); ?? ??? ??? ?obj.add(peo); ?? ??? ?} ?? ??? ?else if (!strcmp(post, "技術(shù)人員")) { ?? ??? ??? ?Person* peo = new Technician(Name, post, c); ?? ??? ??? ?obj.add(peo); ?? ??? ?} ?? ??? ?else if (!strcmp(post, "銷(xiāo)售人員")) { ?? ??? ??? ?Person* peo = new Salesman(Name, post, c); ?? ??? ??? ?obj.add(peo); ?? ??? ?} ?? ??? ?else if (!strcmp(post, "銷(xiāo)售經(jīng)理")) { ?? ??? ??? ?Person* peo = new SaleManager(Name, post, 0); ?? ??? ??? ?obj.add(peo); ?? ??? ?} ?? ?} ?? ?fclose(fp);//關(guān)閉文件? } void Manage::show1()//對(duì)vector數(shù)組進(jìn)行讀取? { ?? ?for (vector ::iterator iter = Ma.begin(); iter != Ma.end(); iter++) { ?? ??? ?(*iter)->show(); ?? ??? ?cout << endl; ?? ?} } int main(){ ?? ?int x; ?? ?Manage T; ?? ?readfile(T); ?? ?while(1){ ? ? ? ? cout<< " ? ?———————————————————————————————" << endl ?? ??? ??? ?<< " ? ?| ? ? ? 公司人事管理系統(tǒng) ? ? ? ?|" << endl ?? ??? ??? ?<< " ? ?———————————————————————————————" << endl ?? ??? ??? ?<< " ? ?| ? ? ? ? 1.添加員工 ? ? ? ? ? |" << endl ?? ??? ??? ?<< " ? ?| ? ? ? ? 2.修改信息 ? ? ? ? ? |" << endl ?? ??? ??? ?<< " ? ?| ? ? ? ? 3.按姓名查找 ? ? ? ? |" << endl ?? ??? ??? ?<< " ? ?| ? ? ? ? 4.顯示所有信息 ? ? ? |" << endl ?? ??? ??? ?<< " ? ?| ? ? ? ? 5.按月薪降序排序 ? ? |" << endl ?? ??? ??? ?<< " ? ?| ? ? ? ? 0.保存并退出程序 ? ? |" << endl ?? ??? ??? ?<< " ? ?———————————————————————————————" << endl;?? ??? ? ?? ??? ?cout<< "請(qǐng)選擇->"; ?? ??? ?cin >> x; ?? ??? ?switch (x) { ?? ??? ?case 1: { ?? ??? ??? ?while (1) { ?? ??? ??? ??? ?int n; ?? ??? ??? ??? ?string Name; ?? ??? ??? ??? ?cout << "請(qǐng)輸入姓名:" ; ?? ??? ??? ??? ?cin >> Name; ?? ??? ??? ??? ?cout << "請(qǐng)輸入人員崗位(1.經(jīng)理 2.技術(shù)人員 3. 銷(xiāo)售人員 4.銷(xiāo)售經(jīng)理):" ;? ?? ??? ??? ??? ?cin >> n; ?? ??? ??? ??? ?if (n == 1) { ?? ??? ??? ??? ??? ?Person* peo = new Manager(Name, "經(jīng)理", 0); ?? ??? ??? ??? ??? ?T.add(peo); ?? ??? ??? ??? ??? ?cout << "添加成功" << endl << endl << endl; ?? ??? ??? ??? ??? ?break; ?? ??? ??? ??? ?} ?? ??? ??? ??? ?else if (n == 2) { ?? ??? ??? ??? ??? ?while (1) { ?? ??? ??? ??? ??? ??? ?int rank = 0; ?? ??? ??? ??? ??? ??? ?cout << "請(qǐng)輸入技術(shù)等級(jí)(1~8):" ; ?? ??? ??? ??? ??? ??? ?cin >> rank; ?? ??? ??? ??? ??? ??? ?if (rank > 8 || rank < 1) { ?? ??? ??? ??? ??? ??? ??? ?cout << "輸入錯(cuò)誤,請(qǐng)?jiān)?~8之間輸入:" ; ?? ??? ??? ??? ??? ??? ?} ?? ??? ??? ??? ??? ??? ?else { ?? ??? ??? ??? ??? ??? ??? ?Person* peo = new Technician(Name, "技術(shù)人員", rank); ?? ??? ??? ??? ??? ??? ??? ?T.add(peo); ?? ??? ??? ??? ??? ??? ??? ?break; ?? ??? ??? ??? ??? ??? ?} ?? ??? ??? ??? ??? ?} ?? ??? ??? ??? ??? ?cout << "添加成功" << endl << endl << endl; ?? ??? ??? ??? ??? ?break; ?? ??? ??? ??? ?} ?? ??? ??? ??? ?else if (n == 3) { ?? ??? ??? ??? ??? ?int sales = 0; ?? ??? ??? ??? ??? ?cout << "請(qǐng)輸入銷(xiāo)售額:" << endl; ?? ??? ??? ??? ??? ?cin >> sales; ?? ??? ??? ??? ??? ?Person* peo = new Salesman(Name, "銷(xiāo)售人員", sales); ?? ??? ??? ??? ??? ?T.add(peo); ?? ??? ??? ??? ??? ?cout << "添加成功" << endl << endl << endl; ?? ??? ??? ??? ??? ?break; ?? ??? ??? ??? ?} ?? ??? ??? ??? ?else if (n == 4) { ?? ??? ??? ??? ??? ?Person* peo = new SaleManager(Name, "銷(xiāo)售經(jīng)理", 0); ?? ??? ??? ??? ??? ?T.add(peo); ?? ??? ??? ??? ??? ?cout << "添加成功" << endl << endl << endl; ?? ??? ??? ??? ??? ?break; ?? ??? ??? ??? ?} ?? ??? ??? ??? ?else { ?? ??? ??? ??? ??? ?cout << "輸入錯(cuò)誤,請(qǐng)重新輸入:" << endl; ?? ??? ??? ??? ?} ?? ??? ??? ?} ?? ??? ? system("pause");} ?? ??? ??? ??? ?break; ?? ??? ?case 2: { ?? ??? ??? ?string Name; ?? ??? ??? ?int n = 0; ?? ??? ??? ?cout << "請(qǐng)輸入姓名:" ; ?? ??? ??? ?cin >> Name; ?? ??? ??? ?Person* peo = T.find(Name); ?? ??? ??? ?if (peo == NULL) { ?? ??? ??? ??? ?cout << "?? ??? ?查無(wú)此人" << endl << endl << endl; ?? ??? ??? ??? ?break; ?? ??? ??? ?} ?? ??? ??? ?peo->show(); ?? ??? ??? ?if (peo->Department == "經(jīng)理") { ?? ??? ??? ??? ?cout << " ? ?經(jīng)理無(wú)法修改" << endl; ?? ??? ??? ?} ?? ??? ??? ?else if (peo->Department == "技術(shù)人員") { ?? ??? ??? ??? ?int rank = 0; ?? ??? ??? ??? ?while (1) { ?? ??? ??? ??? ??? ?cout < > rank; ?? ??? ??? ??? ??? ?if (rank > 8 || rank < 1) { ?? ??? ??? ??? ??? ??? ?cout << "等級(jí)輸入錯(cuò)誤,請(qǐng)重新輸入" << endl; ?? ??? ??? ??? ??? ?} ?? ??? ??? ??? ??? ?else break; ?? ??? ??? ??? ?} ?? ??? ??? ??? ?T.alter(Name); ?? ??? ??? ??? ?peo = new Technician(Name, "技術(shù)人員", rank); ?? ??? ??? ??? ?T.add(peo); ?? ??? ??? ??? ?cout << "修改成功!" << endl; ?? ??? ??? ??? ? ?? ??? ??? ?} ?? ??? ??? ?else if (peo->Department == "銷(xiāo)售人員") { ?? ??? ??? ??? ?int sales = 0; ?? ??? ??? ??? ?cout < > sales; ?? ??? ??? ??? ?T.alter(Name); ?? ??? ??? ??? ?peo = new Salesman(Name, "銷(xiāo)售人員", sales); ?? ??? ??? ??? ?T.add(peo); ?? ??? ??? ??? ?cout << "?? ?修改成功!" << endl; ?? ??? ??? ??? ? ?? ??? ??? ?} ?? ??? ??? ?else if (peo->Department == "銷(xiāo)售經(jīng)理") { ?? ??? ??? ??? ?cout << " ? 銷(xiāo)售經(jīng)理無(wú)法修改" << endl; ?? ??? ??? ?} ?? ??? ??? ?else { ?? ??? ??? ??? ?cout << "輸入錯(cuò)誤" << endl; ?? ??? ??? ?} ?? ??? ?}system("pause"); ?? ??? ??? ??? ?break; ?? ??? ?case 3: { ?? ??? ??? ?string Name; ?? ??? ??? ?int n = 0; ?? ??? ??? ?cout << "請(qǐng)輸入所查找人的姓名:"; ?? ??? ??? ?cin >> Name; ?? ??? ??? ?Person* peo = T.find(Name); ?? ??? ??? ?if (peo == NULL) { ?? ??? ??? ??? ?cout << "查無(wú)此人" << endl; ?? ??? ??? ??? ?system("cls"); ?? ??? ??? ??? ?break; ?? ??? ??? ?} ?? ??? ??? ?cout<<"-----------------------------------"< show(); ?? ??? ??? ?cout<
原文鏈接:https://blog.csdn.net/cjl1831050185/article/details/109231213
相關(guān)推薦
- 2022-04-16 python隊(duì)列基本操作和多線程隊(duì)列_python
- 2022-07-22 python:實(shí)現(xiàn)abbreviation縮寫(xiě)算法(附完整源碼)
- 2022-07-17 關(guān)于python通過(guò)新建環(huán)境安裝tfx的問(wèn)題_python
- 2022-07-21 nginx的配置優(yōu)化及經(jīng)常使用的超時(shí)配置說(shuō)明
- 2022-12-02 React函數(shù)式組件Hook中的useEffect函數(shù)的詳細(xì)解析_React
- 2023-06-17 C語(yǔ)言中帶返回值的宏定義方式_C 語(yǔ)言
- 2022-06-15 golang?Gin上傳文件返回前端及中間件實(shí)現(xiàn)示例_Golang
- 2023-02-14 教你使用SQL語(yǔ)句進(jìn)行數(shù)據(jù)庫(kù)復(fù)雜查詢_MsSql
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲(chǔ)小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過(guò)濾器
- Spring Security概述快速入門(mén)
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯(cuò)誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實(shí)現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡(jiǎn)單動(dòng)態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對(duì)象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊(duì)列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支