企业人力资源管理系统—工资管理(C++)

发布于:2023-07-04 ⋅ 阅读:(173) ⋅ 点赞:(0)

设计内容及要求:
1、问题描述:
《企业人力资源管理系统——工资管理》案例主要对企业员工信息和工资进行管理。将企业员工按工种的不同分为经理、销售人员、技术人员、销售经理和技术总监五类人员。该案例具备五类人员信息的添加、删除、修改、查询、浏览、保存和计算工资等功能,很好的达到了对企业员工信息和工资管理的目的。
2.功能要求:
根据企业实际需求和课堂教学的需要,将案例分为5个模块。
(1)模块一:
对企业中所有员工的基本信息提取出来定义一个类。该类包括员工的编号、姓名、性别、年龄、参加工作时间、部门、职务、联系方式,奖金、扣发工资和基本工资等属性,还包括对员工基本信息的录入、显示和计算实发工资等功能。
(2)模块二:
实现统计员工总数功能;实现插入和提取运算符的重载。
(3)模块三:
根据企业中员工的工作性质的不同,将所有员工分为经理、销售人员、技术人员等三类。其中,经理又可分为销售经理和技术总监两类。
经理类除了包含员工的基本信息外,还包括级别和职务津贴两个属性,还包括对经理信息的录入、显示和计算实发工资等功能。经理类是从员工类派生的。实发工资等于基本工资+奖金-扣发工资+职务津贴。
销售人员类除了包含员工的基本信息外,还包括销售额和提成比例两个属性,还包括对销售人员信息的录入、显示和计算实发工资等功能。销售人员类是从员工类派生的。实发工资等于基本工资+奖金-扣发工资+销售额提成比例。
技术人员除了包含员工的基本信息外,还包括工作时数和每小时金额两个属性,还包括对技术人员信息的录入、显示和计算实发工资等功能。技术人员类也是从员工类派生的。实发工资等于基本工资+奖金-扣发工资+工作时数
每小时金额。每小时金额随工作时数的不同而取不同的值。
销售经理即包含经理的信息,也包含销售人员的信息。所以销售经理是由经理类和销售人员类派生的。它具备信息的录入、显示和计算实发工资等功能。实发工资等于基本工资+奖金-扣发工资+销售额提成比例+职务津贴。
技术总监即包含经理的信息,也包含技术人员的信息。所以技术总监是由经理类和技术人员类派生的。它具备信息的录入、显示和计算实发工资等功能。实发工资等于基本工资+奖金-扣发工资+工作时数
每小时金额+职务津贴。
(4)模块四:
定义管理类实现对不同的员工的管理。
(5)模块五:
从文件中读取员工信息和将修改后的员工信息保存到文件中。

程序亮点:

  1. 利用vector容器进行操作使程序便于编写及维护
  2. 读写csv文件提升用户体验
  3. 对统计员工总数功能实现了自动维护
  4. 将计算的实发工资输出为csv文件,便于后期处理。

源码:


#include<iostream>
#include<fstream>
#include<string>
#include<iomanip>
#include<vector>
#include <windows.h>
using namespace std;

double	string_to_double(string& s1)	
					{
					
					int left=0;
					double	num=0;
					int i=0;
					while(i<s1.size())
						{
						if(s1[i]=='.')
							break;
							
						i++;
						left++;	
						}
					i++;
				
					for(double j=0.1;i<s1.size();j=j*0.1,i++)	
						{	
						num+=(s1[i]-48)*j;
						}
					
					int k=0;
					while(left--)	
						{
						int i=1;
						for(int j=0;j<left;j++)
							i=i*10;
						num+=(s1[k]-48)*i;
						k++;
						}
						
					return num;
				}

string double_to_string(double num)		//double限两位小数 限1500000000以内 
	{
	
	string	s1;
	int i=num;	//整数部分 
	num=num-i;	//小数部分 
	string	temp;
	while(i!=0)
		{
		temp+=i%10+48;
		i=i/10;
		} 
	
	for(i=temp.size()-1;i>=0;i--)
		s1+=temp[i];
	if(num==0)
	return s1;
	s1+='.';
	for(i=0;i<2;i++)
		{
		num=num*10;
		s1+=(int)num%10+48;
		}
		
	return s1;
	}


class	staff
	{
		public:
				staff();	//构造函数 
				int	del(char*,int);	//删除信息 						 						
				int	output();	//显示信息				
				int	calculate_people();	//计算人数 
				~staff();	//析构函数 	
		
		protected:
					
				int	staff_base_head();	
				int staff_base_body(string&);		
				string	staff_base_input(string&,const string&);
				double	staff_change_guide();	
				int	change_base1(vector<string>&,char*,int&) ;
				int	change_base2(vector<string>&,string&,char*,int&);
				int	find_base(char*,string&);
				int	staff_base_salary(ifstream&,vector<string>&,vector<double>&m,vector<int>&);
				int	write_count(int,int);		
				char*	staff_filename;	
		private:
				int	head();
				int body(string);
	 };
	staff::staff(){staff_filename="staff.csv";}
	int	staff::staff_base_head()
					{
					cout<<left<<setw(7)<<"编号";	//编号 
					cout<<left<<setw(10)<<"姓名";	//姓名 
					cout<<left<<setw(6)<<"性别";	//性别 
					cout<<left<<setw(6)<<"年龄";	//年龄	
					cout<<left<<setw(14)<<"参加工作时间";	//参加工作时间	
					cout<<left<<setw(8)<<"部门";	//部门
					cout<<left<<setw(10)<<"职务";	//职务 
					cout<<left<<setw(13)<<"联系方式";	//联系方式 
					cout<<left<<setw(11)<<"奖金";	//奖金 
					cout<<left<<setw(11)<<"扣发工资";	//扣发工资 
					cout<<left<<setw(11)<<"基础工资";	//基础工资	
					return 0;	
					}
	int staff::head()	 
					{
					staff_base_head();
					cout<<endl;
					return 0;
					} 
	int	staff::staff_base_body(string& s1)
					{	
					int	i=0;
					string temp;
					
					while(s1[i]!=',')
						{
						temp+=s1[i];
						i++;
						}
					cout<<left<<setw(7)<<temp;	//编号
					temp.clear();
					i++;
					
					while(s1[i]!=',')
						{
						temp+=s1[i];
						i++;
						}
					cout<<left<<setw(10)<<temp;	//姓名 
					temp.clear();
					i++;
					
					while(s1[i]!=',')
						{
						temp+=s1[i];
						i++;
						}
					cout<<left<<setw(6)<<temp;	//性别 
					temp.clear();
					i++;
					
					while(s1[i]!=',')
						{
						temp+=s1[i];
						i++;
						}
					cout<<left<<setw(6)<<temp;	//年龄 
					temp.clear();
					i++;
					
					while(s1[i]!=',')
						{
						temp+=s1[i];
						i++;
						}
					cout<<left<<setw(14)<<temp;	//参加工作时间 
					temp.clear();
					i++;
					
					while(s1[i]!=',')
						{
						temp+=s1[i];
						i++;
						}
					cout<<left<<setw(8)<<temp;	//部门 
					temp.clear();
					i++;
					
					while(s1[i]!=',')
						{
						temp+=s1[i];
						i++;
						}
					cout<<left<<setw(10)<<temp;	//职务 
					temp.clear();
					i++;
					
					while(s1[i]!=',')
						{
						temp+=s1[i];
						i++;
						}
					cout<<left<<setw(13)<<temp;	//联系方式 
					temp.clear();
					i++;
					
					while(s1[i]!=',')
						{
						temp+=s1[i];
						i++;
						}
					cout<<left<<setw(11)<<temp;	//奖金 
					temp.clear();
					i++;
					
					while(s1[i]!=',')
						{
						temp+=s1[i];
						i++;
						}
					cout<<left<<setw(11)<<temp;	//扣发工资 
					temp.clear();
					i++;
						
					while(s1[i]!=',')
						{
						temp+=s1[i];
						i++;
						}
					cout<<left<<setw(11)<<temp;	//基础工资			
					return	i+1; 
					}
	int	staff::body(string	s1)	
					{
					s1+=',';
					staff_base_body(s1);
					cout<<endl;
					return 0;
					}

	string	staff::staff_base_input(string&	add,const string&	position)
				{
				cout<<"现在对新加入的员工的信息进行录入"<<endl;
				ofstream	ofile;
				ofile.open(staff_filename,ios::app);
				
				string	temp;
				cout<<"输入员工编号:";
				cin>>temp;
				add+=temp;
				add+=',';
				
				cout<<"输入姓名:";
				cin>>temp;
				add+=temp;
				add+=',';
				
				cout<<"输入性别:";
				cin>>temp;
				add+=temp;
				add+=',';
				
				cout<<"输入年龄:";
				cin>>temp;
				add+=temp;
				add+=',';
				
				cout<<"输入参加工作时间:";
				cin>>temp;
				add+=temp;
				add+=',';
				
				cout<<"输入部门:";
				cin>>temp;
				add+=temp;
				add+=',';
				
				add+=position;
				add+=',';
				
				cout<<"输入联系方式:";
				cin>>temp;
				add+=temp;
				add+=',';
				
				cout<<"输入奖金:";
				cin>>temp;
				add+=temp;
				add+=','; 
				
				cout<<"输入扣发工资:";
				cin>>temp;
				add+=temp;
				add+=',';
				
				cout<<"输入基础工资:";
				cin>>temp;
				add+=temp;
				
				ofile<<add<<endl;
				ofile.close();
				
				return add;		
				}
	
	int	staff::del(char*	filename,int k)	//k为第几列的数需要改动 
				{
				string	s1;
				cout<<"输入要删除的员工的编号:";
				cin>>s1;
				vector<string>	v1;
				int no=-1;
				string need;
				ifstream	ifile;
				ifile.open(filename,ios::in);	
				for(int i=0;getline(ifile,need);i++)
					{
					v1.push_back(need);
					string temp;
					int j=0;
					while(v1[i][j]!=',')
						{
						temp+=v1[i][j];	
						j++;
						}
					if(temp==s1)
						no=i;
					}
					
					ifile.close();
					if(no==-1)
						{
						cout<<"无该员工,删除失败"<<endl;
						return 0;	
						}
					
				
					ofstream	ofile;
					ofile.open(filename,ios::out);	
					for(int i=0;i<v1.size();i++)
						if(i!=no)
							ofile<<v1[i]<<endl;
					ofile.close();
				
				v1.clear();	
				ifile.open(staff_filename,ios::in);
						
				for(int i=0;getline(ifile,need);i++)
					{
					v1.push_back(need);
					string temp;
					int j=0;
					while(v1[i][j]!=',')
						{
						temp+=v1[i][j];	
						j++;
						}
					if(temp==s1)
						no=i;
					}
					
					ofile.open(staff_filename,ios::out);	
					for(int i=0;i<v1.size();i++)
						if(i!=no)
							ofile<<v1[i]<<endl;
					ofile.close();
					write_count(-1,k);
					cout<<"删除完毕"<<endl;
					return 0;	
				}
	double	staff::staff_change_guide()
					{
					cout<<left<<setw(7)<<"0";	//编号 
					cout<<left<<setw(10)<<"1";	//姓名 
					cout<<left<<setw(6)<<"2";	//性别 
					cout<<left<<setw(6)<<"3";	//年龄	
					cout<<left<<setw(14)<<"4";	//参加工作时间	
					cout<<left<<setw(8)<<"5";	//部门
					cout<<left<<setw(10)<<"6";	//职务 
					cout<<left<<setw(13)<<"7";	//联系方式 
					cout<<left<<setw(11)<<"8";	//奖金 
					cout<<left<<setw(11)<<"9";	//扣发工资 
					cout<<left<<setw(11)<<"10";	//基础工资
					return 10;	
					}
	int	staff::change_base1(vector<string>&	v1,char*	filename,int& no) 
				{
				string	s1;
				cout<<"输入要修改的员工的编号:";
				cin>>s1;
				ifstream ifile;
				ifile.open(filename,ios::in);
				string need;
				for(int i=0;getline(ifile,need);i++)
					{
					v1.push_back(need);
					string temp;
					int j=0;
					while(v1[i][j]!=',')
						{
						temp+=v1[i][j];	
						j++;
						}
					if(temp==s1)
						no=i;
					}
					ifile.close();
					if(no==-1)
					{
					cout<<"无该员工,无法修改"<<endl;
					return -1;	
					}
				cout<<"已查找到该员工,修改初始化完毕"<<endl;
				return 0;	
				}
	int	staff::change_base2(vector<string>&	v1,string&	temp,char*	filename,int& no)
				{
				
				string	s1;		
				cout<<"输入要修改的字段号,按照字段顺序输入从0开始:"; 
				int	t; 
				cin>>t;	
				
				ofstream  ofile;
				ofile.open(filename,ios::out);
				
				if(t==6)
					{
						cout<<"若修改部门,请在本部门删除该员工,再在新加入的部门添加该员工"<<endl;	
						for(int i=0;i<v1.size();i++)
								ofile<<v1[i]<<endl;	
					}
				else
					{
					vector<string>	v2;	
					int i=0;
					for(;i<v1.size();i++)
					if(i!=no)
						ofile<<v1[i]<<endl;
					else
						{
						
						for(int j=0;j<v1[i].length();j++)
							{
							if(v1[i][j]!=',')
								temp+=v1[i][j];
							else
								{
								v2.push_back(temp);
								temp.clear();	
								}		
							}
						v2.push_back(temp);	
						
						cout<<"输入修改后的数据:";
						
						cin>>s1;
						v2[t]=s1;	
						
						temp.clear();
						int	k=0;
						for(;k<v2.size()-1;k++)
							{
							ofile<<v2[k]<<',';
							temp+=v2[k];
							temp+=',';	
							}
							ofile<<v2[k]<<endl;	
							temp+=v2[k];
							}
							
							
							
						
						if(t<11)
							{
								ifstream	ifile;
								string	need;
								v1.clear();
								ifile.open(staff_filename,ios::in);
							for(int i=0;getline(ifile,need);i++)
								{
								v1.push_back(need);
								string temp;
								int j=0;
								while(v1[i][j]!=',')
									{
									temp+=v1[i][j];	
									j++;
									}
								if(temp==s1)
									no=i;
								}
								ifile.close();	
								
								ofile.open(staff_filename,ios::out);
								for(int i=0;i<v1.size();i++)
									if(i!=no)
										ofile<<v1[i]<<endl;
									else
										{
											int j=0;
										for(;j<10;j++)
											{
											ofile<<v2[j]<<",";
											}
										ofile<<v2[j]<<endl;		
										}	
								
								
							}
							cout<<"修改完毕,结果为"<<endl;
							ofile.close();
							return -1;
						}	
					ofile.close();
					return 0;	
						}		
	
	int	staff::find_base(char*	filename,string&	temp)
				{
				ifstream ifile;
				ifile.open(filename,ios::in);
				string	s1;
				cout<<"输入要查找的员工的编号:";
				cin>>s1; 
				while(getline(ifile,temp))
					{
					string	get;
					int i=0;
					while(temp[i]!=',')
						{
						get+=temp[i];	
						i++;
						}
					
					if(get==s1)
						{
						cout<<"查找结果为:"<<endl;
						ifile.close();
						return 1;
						
						}
					}
				cout<<"未找到该员工"<<endl;
				ifile.close();
				return 0;		
				}			
		
	int staff::output()	
				{
				ifstream ifile;
				ifile.open(staff_filename,ios::in);
				string	temp;
				getline(ifile,temp);
				head();
				while(getline(ifile,temp))	
				body(temp);			
				ifile.close();
				return 0;
				}
	int	staff::calculate_people()
				{
				string	s1;	
				ifstream	ifile;
				ifile.open("count.csv",ios::in);	
				
				
				while(getline(ifile,s1))
					{
					int	i=0;
					string	temp;
					for(int j=0;j<2;j++)
						{
						while(s1[i]!=',')
							{
							temp+=s1[i];
							i++;	
							}
				
							cout<<left<<setw(10)<<temp;	
							temp.clear();
							i++;	
						}
					for(int j=0;j<3;j++)
						{
						while(s1[i]!=',')
							{
							temp+=s1[i];
							i++;	
							}
				
							cout<<left<<setw(14)<<temp;	
							temp.clear();
							i++;	
							}	
					
						
					 while(i!=s1.size())
					 	{
					 	temp+=s1[i];
						 i++;	
						}
					 	cout<<left<<setw(14)<<temp<<endl;
					}
				return 0;
				}						 
	int	staff::write_count(int i,int k)
				{
				string	temp;
				ifstream	ifile;
				ifile.open("count.csv",ios::in);
				getline(ifile,temp);
				
				ofstream	ofile;
				ofile.open("count.csv",ios::out);
				ofile<<temp<<endl;
				
				getline(ifile,temp);
				ifile.close();
				
				vector<string>	v1;
				string	t;
				for(int j=0;j<temp.size();j++)
					{
					if(temp[j]!=',')
						t+=temp[j];
					else
						{
						v1.push_back(t);
						t.clear();
						}
					} 
				v1.push_back(t);
		

				switch(i)
					{
					case 1:	
							v1[0]=double_to_string(string_to_double(  v1[0] )  +1);
							v1[k]=double_to_string(string_to_double(  v1[k] )  +1);
							
							break;
					case -1:
							v1[0]=double_to_string(string_to_double(  v1[0] )  -1);
							v1[k]=double_to_string(string_to_double(  v1[k] )  -1);
							break;	
					}
				i=0;
				for(;i<v1.size()-1;i++)
					ofile<<v1[i]<<',';
				ofile<<v1[i]<<endl;
				ofile.close();	
				return 0;	
				}
	
				
//以后不用传ifile因为已经读取完毕并存入vector中了				
int	staff::staff_base_salary(ifstream&	ifile,vector<string>&	v1,vector<double>&	v2,vector<int>& v3)
					{
					double	sum;
					string	temp;
					getline(ifile,temp);
					temp+=",实发工资"; 
					v1.push_back(temp);
					v2.push_back(0);
					v3.push_back(0);	
					int k=1;
				
					while(getline(ifile,temp))
						{
							
						temp+=',';
						v1.push_back(temp);
						
						int i=0;
						for(int j=0;j<8;i++)
							{
							if(v1[k][i]==',')
								j++;
							}
						string	s1;
						
						while(v1[k][i]!=',')		
							{
							s1+=v1[k][i];
							i++;	
							}
						
						sum=string_to_double(s1);
						s1.clear();
						i++;
					
						while(v1[k][i]!=',')		
							{
							s1+=v1[k][i];	
							i++;
							}
							
						sum=sum-string_to_double(s1);
						s1.clear();
						i++;
						
						while(v1[k][i]!=',')		
							{
							s1+=v1[k][i];
							i++;	
							}
						
						sum=sum+string_to_double(s1);
						i++;
						v2.push_back(sum);
						k++;
					
						v3.push_back(i);
					
						}
					ifile.close();
					return 0;				
					}
				
	
	staff::~staff(){;}
	
	
	
	
	
class	manager	:virtual public	staff
				{
				public:
					manager();
					int	input(); 
					int	change(); 
					int	find();
					int	output();
					int	salary();
					~manager();
				protected:
					int manager_base_head();
					int	manager_base_body(string&,int);
					int	manager_base_input(string&);
					double	manager_change_guide(double);
					int	manager_base_salary(vector<string>&,vector<double>&,vector<int>&);
					char*	manager_filename;	
				private:
					int	head();	
					int	body(string);	
				 } ;
				 
				 
				 
	manager::manager():staff(){manager_filename="manager.csv";}
	int manager::manager_base_head()
							{
							cout<<left<<setw(6)<<"级别";	//级别 
							cout<<left<<setw(10)<<"职务津贴";	//职务津贴
							return 0; 
							}
	int manager::head()
							{
							staff_base_head();
							manager_base_head();
							cout<<endl;
							return 0;	
							}

	int	manager::manager_base_body(string&	s1,int i)	
					{
					string temp;
					
					while(s1[i]!=',')
						{
						temp+=s1[i];
						i++;
						}
					cout<<left<<setw(6)<<temp;	//级别 
					temp.clear();
					i++;
					
					while(s1[i]!=',')
						{
						temp+=s1[i];
						i++;
						}
					cout<<left<<setw(10)<<temp;	//职务津贴
					return i+1;		
					}
	
	int	manager::body(string	s1)
							{
							s1+=',';
							manager_base_body(s1,   staff_base_body(s1)    );
							cout<<endl;
							return 0;	
							}	
	int	manager::manager_base_input(string&	add)
				{
			
				string	temp;
				add+=',';
				
				cout<<"请输入级别:";
				cin>>temp;
				add+=temp;
				add+=',';
				
				cout<<"请输入职务津贴:";
				cin>>temp;
				add+=temp;
				return 0; 	
				}
				
	int	manager::input()
							{
							string	add;
							const string	position="经理"; 
							staff_base_input(add,position);
							manager_base_input(add);
							ofstream	ofile;
							ofile.open(manager_filename,ios::app);
							ofile<<add<<endl;
							ofile.close(); 
							write_count(1,1);
							cout<<"录入完毕"<<endl;                                                                        
							return 0; 
							}
	double	manager::manager_change_guide(double	i)
				{
				cout<<left<<setw(6)<<double_to_string(++i);	//级别 
				cout<<left<<setw(10)<<double_to_string(++i);	//职务津贴
				return i;
				}
	int	manager::change() 	
				{
				vector<string>	v1;	
				int no=-1;
				
				int	judge=change_base1(v1,manager_filename,no);
				if(judge==-1)
					return 0;	
					manager_change_guide(staff_change_guide());
					cout<<endl;
					head();
					body(v1[no]);
				
				string temp;
				judge=change_base2(v1,temp,manager_filename,no);
				if(judge==-1)
					body(temp);		
				return 0;	
				}
	int	manager::find() 
				{
				string	temp;
				if(find_base(manager_filename,temp))
					{
					head();
					body(temp);	
					}	
				return 0;	
				}	
	int manager::output()	
				{
				ifstream ifile;
				ifile.open(manager_filename,ios::in);
				string	temp;
				getline(ifile,temp);
				head();
				while(getline(ifile,temp))	
				body(temp);			
				ifile.close();
				return 0;
				}
	int	manager::salary()
				{
				double	sum=0;
				
				ifstream	ifile;
				ifile.open(manager_filename,ios::in);
				vector<string>	v1;
				vector<double>	v2;
				vector<int>	v3;
				
				staff_base_salary(ifile,v1,v2,v3);
			
				manager_base_salary(v1,v2,v3);
			
				for(int i=1;i<v1.size();i++)
					v1[i]+=double_to_string(v2[i]);
					
				ofstream	ofile;
				ofile.open("manager_outsalary.csv",ios::out);
			
				for(int i=0;i<v1.size();i++)
					ofile<<v1[i]<<endl;
				cout<<"输出工资表完毕,请查看:manager_outsalary.csv"<<endl;
				return 0;
				}
	int	manager::manager_base_salary(vector<string>& v1,vector<double>& v2,vector<int>& v3)
					{
					
					for(int k=1;k<v1.size();k++)
						{
					
						int i=v3[k];
					
						while(v1[k][i]!=',')
							i++;
						i++;
						string	s1;
						while(v1[k][i]!=',')		
							{
							
							s1+=v1[k][i];	
							i++;
							}
						
						v2[k]+=string_to_double(s1);
					
						i++;
						v3[k]=i;	
						}
						
						return 0;	
					}
	manager::~manager(){;}		
	
	
	
	class	salesman	:virtual public	staff
				{
				public:
				salesman();
				int input();
				int	change();
				int	find(); 
				int	output();
				int	salary();
				~salesman();
				
				protected:
				
				int salesman_base_head(); 
				int	salesman_base_body(string&,int);
				int salesman_base_input(string&);
				double	salesman_change_guide(double	i);
				int	salesman_base_salary(vector<string>&,vector<double>&,vector<int>&);
				char*	salesman_filename;
				private:
				int	head();	
				int	body(string);
				};
	salesman::salesman():staff(){salesman_filename="salesman.csv";}
int	salesman::salesman_base_head()
							{
								cout<<left<<setw(8)<<"销售额";	//销售额 
								cout<<left<<setw(10)<<"提成比例";	//提成比例
								return 0; 
							}	
int	salesman::head()
					{
						staff_base_head();
						salesman_base_head();
						cout<<endl;
						return 0;	
					}
					
int	salesman::salesman_base_body(string&	s1,int i)
					{	
					string temp;
					
					while(s1[i]!=',')
						{
						temp+=s1[i];
						i++;
						}
					cout<<left<<setw(8)<<temp;	//销售额 
					temp.clear();
					i++;
					
					while(s1[i]!=',')
						{
						temp+=s1[i];
						i++;
						}
					cout<<left<<setw(10)<<temp;	//提成比例
					return i+1;	
													
					} 
							
int salesman::body(string	s1)					
					{
					s1+=',';
					salesman_base_body(s1, staff_base_body(s1))	;
					cout<<endl;
					return 0;
					 
					}
int	salesman::salesman_base_input(string&	add)
				{
				string	temp;
				add+=',';
				
				cout<<"请输入销售额:";
				cin>>temp;
				add+=temp;
				add+=',';
				
				cout<<"请输入提成比例:";
				cin>>temp;
				add+=temp;
				return 0; 	
				}
				
int	salesman::input()
							{
							string	add;
							const string	position="销售人员";
							staff_base_input(add,position);
							salesman_base_input(add);
							ofstream	ofile;
							ofile.open(salesman_filename,ios::app);
							ofile<<add<<endl;
							write_count(1,2);
							cout<<"录入完毕"<<endl;                                                                        
							return 0; 
							}					
double	salesman::salesman_change_guide(double	i)
				{
				cout<<left<<setw(8)<<double_to_string(++i);	//销售额 
				cout<<left<<setw(10)<<double_to_string(++i);	//提成比例
				return i;
				}
int	salesman::change() 
			{
				vector<string>	v1;	
				int no=-1;
				
				int	judge=change_base1(v1,salesman_filename,no);
				if(judge==-1)
					{
					return 0;	
					}
					salesman_change_guide(staff_change_guide());
					cout<<endl;
					head();
					body(v1[no]);
				
				string temp;
				judge=change_base2(v1,temp,salesman_filename,no);
				if(judge==-1)
					body(temp);		
				return 0;	
				}						
int	salesman::find() 
				{
				string	temp;
				if(find_base(salesman_filename,temp))
					{
					head();
					body(temp);	
					}	
				return 0;	
				}	
int salesman::output()	
				{
				ifstream ifile;
				ifile.open(salesman_filename,ios::in);
				string	temp;
				getline(ifile,temp);
				head();
				while(getline(ifile,temp))	
				body(temp);			
				ifile.close();
				return 0;
				}
int	salesman::salary()
				{
				double	sum=0;
				
				ifstream	ifile;
				ifile.open(salesman_filename,ios::in);
				vector<string>	v1;
				vector<double>	v2;
				vector<int>	v3;
				
				staff_base_salary(ifile,v1,v2,v3);
			
				salesman_base_salary(v1,v2,v3);
				for(int i=1;i<v1.size();i++)
					v1[i]+=double_to_string(v2[i]);
				
				ofstream	ofile;
				ofile.open("salesman_outsalary.csv",ios::out);
			
				for(int i=0;i<v1.size();i++)
					ofile<<v1[i]<<endl;
				cout<<"输出工资表完毕,请查看:salesman_outsalary.csv"<<endl;
				return 0;
				}		
int	salesman::salesman_base_salary(vector<string>& v1,vector<double>& v2,vector<int>& v3)
					{
					double sum;
					for(int k=1;k<v1.size();k++)
						{
						string	s1;
						int i=v3[k];
						
						while(v1[k][i]!=',')		
							{
							s1+=v1[k][i];
							i++;	
							}
						
						sum=string_to_double(s1);
						s1.clear();
						i++;
					
						while(v1[k][i]!=',')		
							{
							s1+=v1[k][i];	
							i++;
							}
							
						v2[k]+=sum*string_to_double(s1);
						i++;
						v3[k]=i;	
						}
						
						return 0;	
					}	
	salesman::~salesman(){;}				
					
	
												
		
class	technicist	: virtual public	staff
			{
			public:
					technicist();
					int	input();
					int change();
					int	find();
					int	output();
					int	salary();
					~technicist();
					
			protected:	
					int technicist_base_head();
					int	technicist_base_body(string&,int); 		
					int	technicis_base_input(string&);
					double	technicist_change_guide(double);
					int	technicist_base_salary(vector<string>&,vector<double>&,vector<int>&);
					char*	technicist_filename;	
			private:
					int	head();
					int	body(string);	
			};
technicist::technicist():staff()	{technicist_filename="technicist.csv";}
technicist::technicist_base_head()
							{
								cout<<left<<setw(10)<<"工作时数";	//工作时数 
								cout<<left<<setw(12)<<"每小时金额";	//每小时金额
								return 0; 
							}	
technicist::head()
					{
						staff_base_head();
						technicist_base_head();
						cout<<endl;
						return 0;	
					}		
									
int	technicist::technicist_base_body(string&	s1,int i)
					{
					string temp;
					
					while(s1[i]!=',')
						{
						temp+=s1[i];
						i++;
						}
					cout<<left<<setw(10)<<temp;	//工作时数 
					temp.clear();
					i++;
					
					while(s1[i]!=',')
						{
						temp+=s1[i];
						i++;
						}
					cout<<left<<setw(12)<<temp;	//每小时金额
					return i+1;		
					}					
					
int	technicist::body(string	s1)
					{
					s1+=',';
					technicist_base_body(s1, staff_base_body(s1))	;
					cout<<endl;
					return 0;					
					}					
					
int	technicist::technicis_base_input(string&	add)
				{
				string	temp;
				add+=',';
				cout<<"请输入工作时数:";
				cin>>temp;
				add+=temp;
				add+=',';
				
				cout<<"请输入每小时金额:";
				cin>>temp;
				add+=temp;
				return 0; 	
				}
				
int	technicist::input()
							{
							string	add;
							const string	position="技术人员";
							staff_base_input(add,position);
							technicis_base_input(add);
							ofstream	ofile;
							ofile.open(technicist_filename,ios::app);
							ofile<<add<<endl;
							write_count(1,3);
							cout<<"录入完毕"<<endl;                                                                         
							return 0; 
							}	
double	technicist::technicist_change_guide(double	i)
				{
				cout<<left<<setw(10)<<double_to_string(++i);	//工作时数 
				cout<<left<<setw(12)<<double_to_string(++i);	//每小时金额
				return i;
				}
int	technicist::change()		
			{
				vector<string>	v1;	
				int no=-1;
				
				int	judge=change_base1(v1,technicist_filename,no);
				if(judge==-1)
					{
					return 0;	
					}
					technicist_change_guide(staff_change_guide());
					cout<<endl; 
					head();
					body(v1[no]);
				
				string temp;
				judge=change_base2(v1,temp,technicist_filename,no);
				if(judge==-1)
					body(temp);		
				return 0;	
				}							
int	technicist::find() 
				{
				string	temp;
				if(find_base(technicist_filename,temp))
					{
					head();
					body(temp);	
					}	
				return 0;	
				}
int technicist::output()	
				{
				ifstream ifile;
				ifile.open(technicist_filename,ios::in);
				string	temp;
				getline(ifile,temp);
				head();
				while(getline(ifile,temp))	
				body(temp);			
				ifile.close();
				return 0;
				}
int	technicist::salary()
				{
				double	sum=0;
				
				ifstream	ifile;
				ifile.open(technicist_filename,ios::in);
				vector<string>	v1;
				vector<double>	v2;
				vector<int>	v3;
				staff_base_salary(ifile,v1,v2,v3);
				technicist_base_salary(v1,v2,v3);
				for(int i=1;i<v1.size();i++)
					v1[i]+=double_to_string(v2[i]);
					
				ofstream	ofile;
				ofile.open("technicist_outsalary.csv",ios::out);
			
				for(int i=0;i<v1.size();i++)
					ofile<<v1[i]<<endl;
				cout<<"输出工资表完毕,请查看:technicist_outsalary.csv"<<endl;
				return 0;
				}
int	technicist::technicist_base_salary(vector<string>& v1,vector<double>& v2,vector<int>& v3)
					{
					double sum;
					for(int k=1;k<v1.size();k++)
						{
						string	s1;
						int i=v3[k];
						while(v1[k][i]!=',')		
							{
							s1+=v1[k][i];
							i++;	
							}
						
						sum=string_to_double(s1);
						s1.clear();
						i++;
					
						while(v1[k][i]!=',')		
							{
							s1+=v1[k][i];	
							i++;
							}
							
						v2[k]+=sum*string_to_double(s1);
						i++;
						v3[k]=i;	
						}
						
						return 0;	
					}
technicist::~technicist(){;}						
							
				
						

class	sales_manager	:public manager ,public	salesman
					{
					public: 
					sales_manager();
					int input();
					int	change();
					int	find();
					int	output();
					int salary();
					~sales_manager();
					protected:
					char*	sales_manager_filename;
					private:
					int head();			
					int body(string);
					};
sales_manager::sales_manager():manager(),salesman(){sales_manager_filename="sales_manager.csv";}
int sales_manager::head()
								{
								staff_base_head();
								manager_base_head();
								salesman_base_head();
								cout<<endl;
								return 0; 
								} 
								
int sales_manager::body(string	s1)
				{
				s1+=',';
				salesman_base_body(s1,   manager_base_body(s1,   staff_base_body(s1) )    );
				cout<<endl;	
				return 0;
				}								
								
				
int	sales_manager::input()
			{
				string	add;
				const string	position="销售经理";
				staff_base_input(add,position);
				manager_base_input(add);
				salesman_base_input(add);
				
				ofstream	ofile;
				ofile.open(sales_manager_filename,ios::app);
				ofile<<add<<endl;
				write_count(1,4);
				cout<<"录入完毕"<<endl;                                                                         
				return 0; 
			}	
int	sales_manager::change()			
			{
				vector<string>	v1;	
				int no=-1;
				
				int	judge=change_base1(v1,sales_manager_filename,no);
				if(judge==-1)
					{
					return 0;	
					}
					salesman_change_guide(manager_change_guide(staff_change_guide()));
					cout<<endl;
					head();
					body(v1[no]);
				
				string temp;
				judge=change_base2(v1,temp,sales_manager_filename,no);
				if(judge==-1)
					body(temp);		
				return 0;	
				}
int	sales_manager::find() 
				{
				string	temp;
				if(find_base(sales_manager_filename,temp))
					{
					head();
					body(temp);	
					}	
				return 0;	
				}
int sales_manager::output()	
				{
				ifstream ifile;
				ifile.open(sales_manager_filename,ios::in);
				string	temp;
				getline(ifile,temp);
				head();
				while(getline(ifile,temp))	
				body(temp);			
				ifile.close();
				return 0;
				}
int	sales_manager::salary()
				{
				double	sum=0;
				
				ifstream	ifile;
				ifile.open(sales_manager_filename,ios::in);
				vector<string>	v1;
				vector<double>	v2;
				vector<int>	v3;
				staff_base_salary(ifile,v1,v2,v3);
				manager_base_salary(v1,v2,v3);
				salesman_base_salary(v1,v2,v3);
				for(int i=1;i<v1.size();i++)
					v1[i]+=double_to_string(v2[i]);
					
				ofstream	ofile;
				ofile.open("sales_manager_outsalary.csv",ios::out);
				cout<<"输出工资表完毕,请查看:sales_manager_outsalary.csv"<<endl;
				for(int i=0;i<v1.size();i++)
					ofile<<v1[i]<<endl;
				return 0;
				}
sales_manager::~sales_manager(){;}										




class	technical_director	: public manager ,public	technicist
						{
						public:
						technical_director();
						int input();
						int	change();
						int	find();
						int	output();
						int	salary();
						~technical_director();	
						protected:
						char*	technical_director_filename;	
						private:
						int head();
						int	body(string);
						};
technical_director::technical_director():manager(),technicist(){technical_director_filename="technical_director.csv";}
				
int technical_director::head()
											{
											staff_base_head();
											manager_base_head();
											technicist_base_head();
											cout<<endl;
											return 0; 	
											}
											
											
int technical_director::body(string	s1)
												{
												s1+=',';
												technicist_base_body(s1,   manager_base_body(s1,   staff_base_body(s1)   ) );
												cout<<endl;
												return 0;		
												}											
				
				
int	technical_director::input()
			{
				string	add;
				const string	position="技术总监";
				staff_base_input(add,position);
				manager_base_input(add);
				technicis_base_input(add);
				
				ofstream	ofile;
				ofile.open(technical_director_filename,ios::app);
				ofile<<add<<endl;
				write_count(1,5);
				cout<<"录入完毕"<<endl;                                                                         
				return 0; 
			}	
	
int	technical_director::change()				
				{
				vector<string>	v1;	
				int no=-1;
				
				int	judge=change_base1(v1,technical_director_filename,no);
				if(judge==-1)
					{
					return 0;	
					}
					technicist_change_guide(manager_change_guide(staff_change_guide()));
					cout<<endl;
					head();
					body(v1[no]);
				
				string temp;
				judge=change_base2(v1,temp,technical_director_filename,no);
				if(judge==-1)
					body(temp);		
				return 0;	
				}
int	technical_director::find() 
				{
				string	temp;
				if(find_base(technical_director_filename,temp))
					{
					head();
					body(temp);	
					}	
				return 0;	
				}			
int technical_director::output()	
				{
				ifstream ifile;
				ifile.open(technical_director_filename,ios::in);
				string	temp;
				getline(ifile,temp);
				head();
				while(getline(ifile,temp))	
				body(temp);			
				ifile.close();
				return 0;
				}
int	technical_director::salary()
				{
				double	sum=0;
				
				ifstream	ifile;
				ifile.open(technical_director_filename,ios::in);
				vector<string>	v1;
				vector<double>	v2;
				vector<int>	v3;
				staff_base_salary(ifile,v1,v2,v3);
				manager_base_salary(v1,v2,v3);
				technicist_base_salary(v1,v2,v3);
				for(int i=1;i<v1.size();i++)
					v1[i]+=double_to_string(v2[i]);
					
				ofstream	ofile;
				ofile.open("technical_director_outsalary.csv",ios::out);
			
				for(int i=0;i<v1.size();i++)
					ofile<<v1[i]<<endl;
				cout<<"输出工资表完毕,请查看:technical_director_outsalary.csv"<<endl;
				return 0;
				}
technical_director::~technical_director(){;}

ostream&	operator<<(ostream &os,staff& s)
	{
	s.output();	
	return  os;
	}

istream&	operator>>(istream &is,manager& m)
	{
	m.input();
	return is;	
	}

ostream&	operator<<(ostream &os,manager& m)
	{
	m.output();	
	return  os;
	}

istream&	operator>>(istream &is,salesman& s)
	{
	s.input();
	return is;	
	}

ostream&	operator<<(ostream &os,salesman& s)
	{
	s.output();	
	return  os;
	}

istream&	operator>>(istream &is,technicist& t)
	{
	t.input();
	return is;	
	}

ostream&	operator<<(ostream &os,technicist& t)
	{
	t.output();	
	return  os;
	}

istream&	operator>>(istream &is,sales_manager& s)
	{
	s.input();
	return is;	
	}

ostream&	operator<<(ostream &os,sales_manager& s)
	{
	s.output();	
	return  os;
	}


istream&	operator>>(istream &is,technical_director& t)
	{
	t.input();
	return is;	
	}

ostream&	operator<<(ostream &os,technical_director& t)
	{
	t.output();	
	return  os;
	}

int	manager_control()
	{
	system("cls");
	manager	m;
	cout<<"经理管理系统"<<endl;
	cout<<"1.加入新经理"<<endl;
	cout<<"2.经理离职"<<endl;
	cout<<"3.经理信息修改"<<endl;
	cout<<"4.查找经理"<<endl;
	cout<<"5.经理概览"<<endl;
	cout<<"6.输出经理工资表"<<endl;
	cout<<"7.退出"<<endl;
	int	i;
	while(1)
		{
		cin>>i;
		if(i>0&&i<8)
			break;
		cout<<"指令无法识别请重新输入"<<endl;		
		}
		
	switch(i)
		{
		case	1:	cin>>m;	break;
		case	2:	m.del("manager.csv",1);	break;
		case	3:	m.change() ;	break;
		case	4:	m.find();	break;
		case	5:	cout<<m;	break;
		case	6:	m.salary();	break;
		case	7:	return 0;				
		}	
	system("pause");	
	return 1;	
	}

int	salesman_control()
	{
	system("cls");
	salesman s;
	cout<<"销售人员管理系统"<<endl;
	cout<<"1.加入新销售员"<<endl;
	cout<<"2.销售员离职"<<endl;
	cout<<"3.销售员信息修改"<<endl;
	cout<<"4.查找销售员"<<endl;
	cout<<"5.销售员概览"<<endl;
	cout<<"6.输出销售员工资表"<<endl;
	cout<<"7.退出"<<endl;
	int	i;
	while(1)
		{
		cin>>i;
		if(i>0&&i<8)
			break;
		cout<<"指令无法识别请重新输入"<<endl;	
		}
		
	switch(i)
		{
		case	1:	cin>>s;	break;
		case	2:	s.del("salesman.csv",2);	break;
		case	3:	s.change();	break;
		case	4:	s.find();	break;
		case	5:	cout<<s;	break;
		case	6:	s.salary();	break;
		case	7:	return 0;				
		}	
	system("pause");	
	return 1;	
	}

int	technicist_control()
	{
	system("cls");
	technicist t;
	cout<<"技术人员管理系统"<<endl;
	cout<<"1.加入新技术员"<<endl;
	cout<<"2.技术员离职"<<endl;
	cout<<"3.技术员信息修改"<<endl;
	cout<<"4.查找技术员"<<endl;
	cout<<"5.技术员概览"<<endl;
	cout<<"6.输出技术员工资表"<<endl;
	cout<<"7.退出"<<endl;
	int	i;
	while(1)
		{
		cin>>i;
		if(i>0&&i<8)
			break;	
		cout<<"指令无法识别请重新输入"<<endl;
		}
		
	switch(i)
		{
		case	1:	cin>>t;	break;
		case	2:	t.del("technicist.csv",3);	break;
		case	3:	t.change();	break;
		case	4:	t.find();	break;
		case	5:	cout<<t;	break;
		case	6:	t.salary();	break;
		case	7:	return 0;				
		}	
	system("pause");	
	return 1;	
	}
	
int	sales_manager_control()
	{
	system("cls");
	sales_manager s;
	cout<<"销售经理管理系统"<<endl;
	cout<<"1.加入新销售经理"<<endl;
	cout<<"2.销售经理离职"<<endl;
	cout<<"3.销售经理信息修改"<<endl;
	cout<<"4.查找销售经理"<<endl;
	cout<<"5.销售经理概览"<<endl;
	cout<<"6.输出销售经理工资表"<<endl;
	cout<<"7.退出"<<endl;
	int	i;
	while(1)
		{
		cin>>i;
		if(i>0&&i<8)
			break;	
		cout<<"指令无法识别请重新输入"<<endl;
		}
		
	switch(i)
		{
		case	1:	cin>>s;	break;
		case	2:	s.del("sales_manager.csv",4);	break;
		case	3:	s.change();	break;
		case	4:	s.find();	break;
		case	5:	cout<<s;	break;
		case	6:	s.salary();	break;
		case	7:	return 0;				
		}	
	system("pause");		
	return 1;	
	}
int	technical_director_control()
	{
	system("cls");
	technical_director t;
	cout<<"技术总监管理系统"<<endl;
	cout<<"1.加入新技术总监"<<endl;
	cout<<"2.技术总监离职"<<endl;
	cout<<"3.技术总监信息修改"<<endl;
	cout<<"4.查找技术总监"<<endl;
	cout<<"5.技术总监概览"<<endl;
	cout<<"6.输出技术总监工资表"<<endl;
	cout<<"7.退出"<<endl;
	int	i;
	while(1)
		{
		cin>>i;
		if(i>0&&i<8)
			break;
		cout<<"指令无法识别请重新输入"<<endl;	
		}
		
	switch(i)
		{
		case	1:	cin>>t;	break;
		case	2:	t.del("technical_director.csv",5);	break;
		case	3:	t.change();	break;
		case	4:	t.find();	break;
		case	5:	cout<<t;	break;
		case	6:	t.salary();	break;
		case	7:	return 0;				
		}	
	system("pause");	
	return 1;	
	}	
	
	
	
	
		
int	hello()
		{
		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;	
		int	i;
		
		while(1)
		{
		cin>>i;
		if(i>0&&i<9)
			break;	
		cout<<"指令无法识别请重新输入"<<endl;
		}
		staff	s;
		switch(i)
			{
			case 	1:
						cout<<s;
						system("pause");
						break;
			case 	2:	
						s.calculate_people();
						system("pause");
						break;
			case	3:	while(manager_control());
						break;
			case	4:	while(salesman_control());
						break;
			case	5:	while(technicist_control());
						break;
			case	6:	while(sales_manager_control());
						break;
			case	7:	while(technical_director_control());
						break;
			case	8:
						return 0;
			}
			system("cls");
			return 1;
		}		

int	main()
		{
	 	while(hello());
	 	cout<<"感谢您的使用"<<endl;
	 	Sleep(3000);
		return 0;	
		}									

需配合文件使用:
https://download.csdn.net/download/gy13753867060/10923535

本文含有隐藏内容,请 开通VIP 后查看

网站公告

今日签到

点亮在社区的每一天
去签到