生活随笔
收集整理的這篇文章主要介紹了
c++公司人事管理系统
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
(1)問題描述
一個小公司包含四類人員:經理,技術人員,銷售人員和銷售經理,各類 人員的工資計算方法如下:
經理:固定月薪(8000);技術人員:月薪按技 術等級(1~8)( 1600+等級*300);
銷售人員:按提成(4%*銷售額);
銷售經理:底薪+提成(1500+0.2%*總銷售額);
設計一個管理程序,實現對各 類人員的信息輸入,修改和顯示。
(2)基本要求
(1)設計一個 Person 類:編號(自動產生),姓名,崗位,工資(可 設為 protected),成員函數可設一個計算月薪的純虛函數;另外再設計四個針對四類人員的類均繼承 Person; 添加相應的派生類數據成員和函數,經理和銷售經理可以沒有新的數據成員,計算月薪即可; 技術人員添加技術等級數據成員,銷售人員添加數據成員:銷售額。還需設計一個 Manage 類來完成各種操作。(提示:人員數組 vector,數據類型為基類指針)
(2)為了設計簡潔,假定經理和銷售經理都只能有一個;用文本編輯
器編輯一個文本文件(總數 20 人以上)包含各類人員的信息;并且在程 序中能修改保存。
(3)菜單功能:添加人員(輸入),修改信息,瀏覽信息,按姓名查 找,月薪排序。
(3)基本需求
該程序具體要實現以下功能:
(1)能夠顯示出菜單等引導界面,引導使用者進行具體的操作;
(2)能夠提供一些最基本的數據錄入功能,輸入教職工基本信息;
(3)能夠實現基本的增加、刪除、查找(按姓名,按編號)、修改功能,實現對數據的操 作;
(4)提供基礎的文件操作功能,實現對文件的存取,和加載功能;
(5)提供部分統計的功能,幫助用戶管理信息,處理信息;
(4)流程圖
(5)源程序
#include<fstream>
#include<iostream
#include<string>
#include<iomanip>
#include<stdlib.h>
using namespace std
;const int n1
=5,n2
=1,n3
=10,n4
=1;
const double m_salary
=8000;
const double hourpay
=100;
const double basicpay
=1500;
const double s_proportion
=4.0/100;
const double sm_proportion
=0.2/100;
void menu();
void menu2();
void menu3();
void data_input();
void data_print();
void charthead1();
void charthead2();
void chartend();
void statistics();
double sm_salary();
void sm_print();
void data_find();
void data_save();
ofstream outfile
;
string f_name
;
class Person
{
public
:
void input()
{cout
<<"編號:";cin
>>num
;cout
<<"其姓名:";cin
>>name
;cout
<<"性別(m/w):";cin
>>sex
;cout
<<"年齡:";cin
>>age
;
}
void print()
{cout
<<"********************************************************************"<<endl
;cout
<<" "<<setw(6)<<num
<<" "<<setw(8)<<name
<<" "<<setw(6)<<sex
<<" "<<setw(6)<<age
<<" "<<setw(7)<<pay
<<" "<<endl
;
}
void find()
{if(f_name
==name
){charthead2();print();chartend();cout
<<endl
;}
}
void save() {outfile
<<"********************************************************************"<<endl
;outfile
<<" "<<setw(6)<<num
<<" "<<setw(8)<<name
<<" "<<setw(6)<<sex
<<" "<<setw(6)<<age
<<" "<<setw(7)<<pay
<<" "<<endl
;}protected
:int num
; string name
; char sex
; int age
; double pay
;
};
class Technician
:public Person
{
public
:void input()
{cout
<<"技術員的";Person
::input();cout
<<"工作時間:";cin
>>worktime
;
}
void print()
{ pay
=worktime
*hourpay
;
Person
::print();
}
void find()
{Person
::find();
}
void save()
{pay
=worktime
*hourpay
;
Person
::save();
}
protected
:double worktime
;
};
class Manager
:public Person
{
public
:void input()
{cout
<<"經理的";
Person
::input();
}
void print()
{ pay
=m_salary
;
Person
::print();
}
void find()
{
Person
::find();
}
void save()
{ pay
=m_salary
;
Person
::save();
}
};
class Sell_manager
:public Person
{
public
:void input()
{ cout
<<"銷售經理的";
Person
::input();
}
int sm_number()
{return num
;
}
string
sm_name()
{return name
;
}
void print()
{cout
<<"********************************************************************"<<endl
;cout
<<" "<<setw(6)<<num
<<" "<<setw(8)<<name
<<" "<<setw(6)<<sex
<<" "<<setw(6)<<age
<<" ";
}
void save()
{cout
<<"********************************************************************"<<endl
;cout
<<" "<<setw(6)<<num
<<" "<<setw(8)<<name
<<" "<<setw(6)<<sex
<<" "<<setw(6)<<age
<<" ";
}
};
class Seller
:public Person
{
public
:Seller(){ sold_amount
=0; }
void input()
{cout
<<"銷售員的";Person
::input();cout
<<"銷售額:";cin
>>sold_amount
;cout
<<"所屬銷售經理的編號:";cin
>>nu
;
}
void grade()
{cout
<<"**********************\n"<<endl
;cout
<<" "<<setw(6)<<num
<<" "<<setw(8)<<name
<<" "<<setw(7)<<sold_amount
<<" "<<endl
;
}
void print()
{ pay
=sold_amount
*s_proportion
;cout
<<"********************************************************************\n"<<endl
;cout
<<" "<<setw(6)<<num
<<" "<<setw(8)<<name
<<" "<<setw(6)<<sex
<<" "<<setw(6)<<age
<<" "<<setw(7)<<pay
<<" "<<setw(13)<<nu
<<" "<<endl
;
}
int s_number()
{return nu
;
}
double amount()
{return sold_amount
;
}
void find()
{if(f_name
==name
){cout
<<"*****************************************************************\n"<<endl
;cout
<<" 職 工 號 姓 名 性 別 年 齡 工 資 所屬部門經理編號 \n"<<endl
;print();cout
<<"*****************************************************************\n";}
}
void save()
{pay
=sold_amount
*s_proportion
;outfile
<<"*****************************************************************\n"<<endl
;outfile
<<" "<<setw(6)<<num
<<" "<<setw(8)<<name
<<" "<<setw(6)<<sex
<<" "<<setw(6)<<age
<<" "<<setw(7)<<pay
<<" "<<setw(13)<<nu
<<" "<<endl
;
}
protected
:double sold_amount
; int nu
;
};
Technician t
[n1
]; Manager m
[n2
]; Seller s
[n3
]; Sell_manager sm
[n4
];
int main()
{char n
;menu();for(int i
=0;i
<1000;i
++) {cin
>>n
;switch(n
){case'1': cout
<<endl
<<"您所選操作為數據輸入,請繼續——"<<endl
<<endl
;data_input();cout
<<endl
;menu();break;case'2': cout
<<endl
<<"您所選操作為數據統計,請繼續——"<<endl
<<endl
;statistics();cout
<<endl
<<"銷售經理按工資排序為:"<<'\n'<<endl
;sm_print();cout
<<endl
;menu();break;case'3': cout
<<endl
<<"您所選操作為數據輸出,請繼續——"<<endl
<<endl
;cout
<<'\a'<<"數據輸出中,請等待……"<<'\n'<<'\n'<<endl
;cout
<<"職工基本情況一覽表如下:"<<'\n'<<endl
;;data_print();cout
<<endl
<<endl
;cout
<<'\a'<<"——數據輸出完畢——"<<'\n'<<'\n'<<endl
;menu();break;case'4': cout
<<endl
<<"您所選操作為數據查詢,請繼續——"<<endl
<<endl
;cout
<<"請輸入您要查詢的職工姓名: ";cin
>>f_name
;cout
<<endl
<<"——正在查詢,請等待——"<<endl
<<endl
;cout
<<"您查詢的信息如下:"<<endl
<<endl
;data_find();cout
<<endl
<<endl
;menu();break;case'5': outfile
.open("人員名單.txt",ios
::out
); cout
<<endl
<<"您所選操作為數據備份,請繼續——"<<endl
<<endl
;outfile
<<"職工基本情況一覽表如下:"<<'\n'<<endl
;data_save();outfile
.close();cout
<<endl
<<endl
;cout
<<'\a'<<"——數據備份完成,請繼續——"<<endl
<<endl
;menu();break;case'0': cout
<<endl
<<"您所選操作為退出系統,請確認——"<<endl
<<endl
;cout
<<" 是( y )"<<" "<<"否( n ) ";cin
>>n
;if(n
=='y'){ cout
<<'\n'<<"——請按任意鍵退出系統——"<<endl
; exit(0); cout
<<endl
;}else menu();break;default:cout
<<endl
<<"——出錯!請重新選擇操作! "<<'\n'<<endl
;menu();break;}}return 0;
}
void menu()
{cout
<<"Welcome!\n "<<endl
;cout
<<" ****************** 公司人事管理系統*******************\n\n"<<endl
;cout
<<"請選擇您所需的操作: "<<endl
;cout
<<" ******************************************************\n"<<endl
;cout
<<" ***************** 【1】數據輸入 *****************\n"<<endl
;cout
<<" ***************** 【2】數據統計 *****************\n"<<endl
;cout
<<" ***************** 【3】數據輸出 *****************\n"<<endl
;cout
<<" ***************** 【4】數據顯示 *****************\n"<<endl
;cout
<<" ***************** 【5】數據備份 *****************\n"<<endl
;cout
<<" ***************** 【6】退出系統 *****************\n"<<endl
;cout
<<" ******************************************************\n"<<endl
;cout
<<"操作提示:輸入編號并按回車鍵選擇你想實現的功能\n"<<endl
;cout
<<" 請選擇一個操作:";
}
void menu2()
{cout
<<" ****************** 公司人事管理系統*********************\n\n"<<endl
;cout
<<"請選擇您所需的操作: "<<endl
;cout
<<" *********************************************************\n"<<endl
;cout
<<" ***************** 【1】經理數據輸入 ********************\n"<<endl
;cout
<<" ***************** 【2】技術人員數據輸入*****************\n"<<endl
;cout
<<" ***************** 【3】銷售員數據輸入 ******************\n"<<endl
;cout
<<" ***************** 【4】銷售經理數據輸入*****************\n"<<endl
;cout
<<" ***************** 【5】返回上一級 *********************\n"<<endl
;cout
<<" *********************************************************\n"<<endl
;cout
<<"操作提示:輸入編號并按回車鍵選擇你想實現的功能\n"<<endl
;cout
<<" 請選擇一個操作:";
}
void menu3()
{cout
<<" ****************** 公司人事管理系統********************\n\n"<<endl
;cout
<<"請選擇您所需的操作: "<<endl
;cout
<<" ********************************************************\n"<<endl
;cout
<<" ***************** 【1】經理數據輸出 ********************\n"<<endl
;cout
<<" ***************** 【2】技術人員數據輸出*****************\n"<<endl
;cout
<<" ***************** 【3】銷售員數據輸出 ******************\n"<<endl
;cout
<<" ***************** 【4】銷售經理數據輸出*****************\n"<<endl
;cout
<<" ***************** 【5】返回上一級 ********************\n"<<endl
;cout
<<" ********************************************************\n"<<endl
;cout
<<"操作提示:輸入編號并按回車鍵選擇你想實現的功能\n"<<endl
;cout
<<" 請選擇一個操作:";
}
void data_input()
{char p
;int i
;menu2();for(int j
=0;j
<100;j
++){cin
>>p
;if(p
=='5') break;else{switch(p
){case'1':for(i
=0;i
<n2
;i
++)m
[i
].input();cout
<<endl
<<"-----------------------------------------------------"<<endl
;menu2();break;case'2':for(i
=0;i
<n1
;i
++)t
[i
].input();cout
<<endl
<<"-----------------------------------------------------"<<endl
;menu2();break;case'3':for(i
=0;i
<n3
;i
++)s
[i
].input();cout
<<endl
<<"-----------------------------------------------------"<<endl
;menu2();break;case'4':for(i
=0;i
<n4
;i
++)sm
[i
].input();cout
<<endl
<<"--------------------------------------------------"<<endl
;menu2();break;}}}
}
void charthead1()
{cout
<<" ********************************************************\n"<<endl
;cout
<<" 職 工 號 姓 名 銷 售 額 "<<endl
;
}
void charthead2()
{cout
<<" ********************************************************\n"<<endl
;cout
<<" 職 工 號 姓 名 性 別 年 齡 工 資 "<<endl
;
}
void chartend() {cout
<<" ********************************************************\n";}
void statistics() { int i
,j
;for(i
=0;i
<n4
;i
++){double sum
=0;cout
<<endl
<<"職工號為 "<<sm
[i
].sm_number()<<" 銷售經理 "<<sm
[i
].sm_name()<<" 下屬銷售員的業績為:"<<endl
<<endl
;charthead1();for(j
=0;j
<n3
;j
++)if(s
[j
].s_number()==sm
[i
].sm_number()){sum
=sum
+s
[j
].amount();s
[j
].grade();}cout
<<"****************************"<<endl
;cout
<<" 銷售額總計 "<<setw(12)<<sum
<<" "<<endl
;cout
<<"****************************"<<endl
;}}
double salary
[n4
];
double sm_salary() {int i
,j
;double a
;Sell_manager b
;for(int k
=0;k
<n4
;k
++)salary
[k
]=0;for(i
=0;i
<n4
;i
++){double sum
=0;for(j
=0;j
<n3
;j
++)if(s
[j
].s_number()==sm
[i
].sm_number()){ sum
=sum
+s
[j
].amount();salary
[i
]=sum
*sm_proportion
+basicpay
;}}for( j
=0;j
<n4
-1;j
++)for( i
=0;i
<n4
-1-j
;i
++)if(salary
[i
]<salary
[i
+1]){ a
=salary
[i
+1];salary
[i
+1]=salary
[i
];salary
[i
]=a
;b
=sm
[i
+1];sm
[i
+1]=sm
[i
];sm
[i
]=b
;}return 0;
}
void sm_print(){sm_salary();charthead2();for(int i
=0;i
<n4
;i
++){ sm
[i
].print();cout
<<setw(7)<<salary
[i
]<<" "<<endl
;}chartend();cout
<<endl
;}
void data_print() {char p
;int i
,j
;menu2();for(j
=0;j
<100;j
++){cin
>>p
;if(p
=='5') break;else{switch(p
){case'1':cout
<<endl
<<"經理"<<endl
; charthead2();for(i
=0;i
<n2
;i
++)m
[i
].print();chartend();cout
<<endl
<<endl
<<"-----------------------------------------------------------------------"<<endl
;menu3();break;case'2':cout
<<endl
<<"技術人員"<<endl
; charthead2();for(i
=0;i
<n1
;i
++)t
[i
].print();chartend();cout
<<endl
<<endl
<<"-----------------------------------------------------------------------"<<endl
;menu3();break;case'3':cout
<<endl
<<"銷售人員"<<endl
; cout
<<"********************************************************\n"<<endl
;cout
<<" 職 工 號 姓 名 性 別 年 齡 工 資 所屬部門經理編號 "<<endl
;for(i
=0;i
<n3
;i
++)s
[i
].print();cout
<<"********************************************************\n";cout
<<endl
<<endl
<<"------------------------------------------------------------------------"<<'\n'<<endl
;menu3();break;case'4':cout
<<endl
<<"銷售經理"<<endl
; sm_salary();sm_print();cout
<<endl
<<endl
<<"-----------------------------------------------------------------------"<<endl
<<endl
;menu3();break;}}}
}
void data_find() {int i
;for(i
=0;i
<n1
;i
++)t
[i
].find();for(i
=0;i
<n2
;i
++)m
[i
].find();for(i
=0;i
<n3
;i
++)s
[i
].find();for(i
=0;i
<n4
;i
++)if(f_name
==sm
[i
].sm_name()){ charthead2();sm
[i
].print();cout
<<setw(7)<<salary
[i
]<<" "<<endl
;chartend();cout
<<endl
;break;}
}
void data_save() {outfile
<<endl
<<"技術人員"<<endl
; outfile
<<"********************************************************\n"<<endl
;outfile
<<" 職 工 號 姓 名 性 別 年 齡 工 資 "<<endl
;for(int i
=0;i
<n1
;i
++)t
[i
].save();outfile
<<"********************************************************\n";outfile
<<endl
<<endl
<<"---------------------------------------------------------------------------"<<endl
;outfile
<<endl
<<"經理"<<endl
; outfile
<<"********************************************************\n"<<endl
;outfile
<<" 職 工 號 姓 名 性 別 年 齡 工 資 "<<endl
;for(int i
=0;i
<n2
;i
++)m
[i
].save();outfile
<<"********************************************************\n";outfile
<<endl
<<endl
<<"----------------------------------------------------------------------------"<<endl
;outfile
<<endl
<<"銷售經理"<<endl
; sm_salary();outfile
<<"********************************************************\n"<<endl
;outfile
<<" 職 工 號 姓 名 性 別 年 齡 工 資 "<<endl
;for(int i
=0;i
<n4
;i
++){ sm
[i
].save();outfile
<<setw(7)<<salary
[i
]<<" │"<<endl
;}outfile
<<"********************************************************\n";outfile
<<endl
<<endl
<<"----------------------------------------------------------------------------"<<endl
<<endl
;outfile
<<endl
<<"銷售人員"<<endl
; outfile
<<"******************************************************************\n"<<endl
;outfile
<<" 職 工 號 姓 名 性 別 年 齡 工 資 所屬部門經理編號 "<<endl
;for(int i
=0;i
<n3
;i
++)s
[i
].save();outfile
<<"******************************************************************\n";outfile
<<endl
<<endl
<<"-----------------------------------------------------------------------------"<<'\n'<<endl
;
}
(6)主菜單界面顯示
第一次寫項目,查了好多資料,不足之處還請多多指教!
總結
以上是生活随笔為你收集整理的c++公司人事管理系统的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。