写一个职工类,其中私有数据成员包括职工姓名name,职工号id,入职年月rznf,年度评分score(每年每个员工会得到一个分,是4-9之中的整数值,当得到第三个评分后,会判断是否加薪或辞退,然后清零这三个评分),员工月薪wages员工总数Total。成员函数有构造函数,析构函数,判断是否加薪(连续3年评分都大于等于9,则加薪10%),判断是否辞退(连续3年评分小于等于6,辞退)。再写一个友元函数,用来计算该公司每月应付职工薪酬,和年应付职工薪酬。【20分】
//Employee.h
#ifndef EMPLOYEE_H
#define EMPLOYEE_H
#include <string>
using namespace std;
class Employee
{
friend void wageOfMonAndYear( Employee &e)
{
for( int i = 0; i < e.Total; i++ )
sumOfMon += e.getWage();
sumOfYear = sumOfMon * 12;
//两种通过public static函数访问private static数据成员的方法
cout << "Wage of month in this company is " << e.getSumOfMon() << "k" << endl;
cout << "wage of Year in this company is " << Employee::getSumOfYear() << "k" << endl;
}
public:
Employee(string = "",int = 0,string = "",double = 0);
~Employee();
void setWage( double );
double getWage() const;
void setScore( int );
void ifRaseWage();
void ifDismiss();
static int getTotal();
static double getSumOfMon();
static double getSumOfYear();
private:
string name;
int ID;
string rznf;
int score[ 3 ];
double wages;
static int Total;
static double sumOfMon;
static double sumOfYear;
void clearScore();
};
#endif
//Employee.cpp
#include <iostream>
#include "Employee.h"
using namespace std;
int Employee::Total = 0;
double Employee::sumOfMon = 0.0;
double Employee::sumOfYear = 0.0;
Employee::Employee( string ename,int eid,string erznf,double ewage )
{
name = ename;
ID = eid;
rznf = erznf;
wages = ewage;
Total++; //员工数++
for( int i = 0; i < 3; i++ )
score[ i ] = 0;
}
Employee::~Employee()
{
}
void Employee::setWage( double swage )
{
wages = swage;
}
double Employee::getWage() const
{
return wages;
}
void Employee::setScore( int s )
{
if( s >3 && s < 10 )
{
for( int i = 0; i < 3; i++ )
if( !score[ i ] )
score[ i ] = s;
}
else
cerr << "The score is between 4 and 9!" << endl;
}
void Employee::ifRaseWage()
{
bool flag = true;
for( int i = 0; i < 3; i++ )
if( score[ i ] < 9 )
flag = false;
if( flag )
{
cout << "Raise Wage!" << endl;
setWage( getWage() * 1.1);
}
//clearScore();
}
void Employee::ifDismiss()
{
bool flag = true;
for( int i = 0; i < 3; i++ )
if( score[ i ] > 6 )
flag = false;
if( flag )
cout << "This employee should be dismiss!" << endl;
else
cout << "This employee should be hire!" << endl;
clearScore();
}
void Employee::clearScore()
{
for( int i = 0; i < 3; i++ )
score[ i ] = 0;
}
int Employee::getTotal()
{
return Total;
}
double Employee::getSumOfMon()
{
return sumOfMon;
}
double Employee::getSumOfYear()
{
return sumOfYear;
}
//exam2018_03.cpp
#include <iostream>
#include "Employee.h"
using namespac![在这里插入图片描述](https://img-blog.csdnimg.cn/202004242131543.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM1NTkxMTQw,size_16,color_FFFFFF,t_70)
e std;
int main()
{
//Employee( string ename,int eid,string erznf,double ewage );
Employee e1( "name", 1003, "20210701", 1.5 );
e1.setScore( 9 );
e1.setScore( 9 );
e1.setScore( 9 );
cout << "Before wage: "<< e1.getWage() << "k" << endl;
e1.ifRaseWage();
cout << "After wage: "<< e1.getWage() << "k" << endl;
e1.ifDismiss();
wageOfMonAndYear( e1);
Employee e2( "name", 1003, "20210701", 0.5 );
e2.setScore( 4 );
e2.setScore( 4 );
e2.setScore( 4 );
cout << "Before wage: "<< e2.getWage() << "k" << endl;
e2.ifRaseWage();
cout << "After wage: "<< e2.getWage() << "k" << endl;
e2.ifDismiss();
wageOfMonAndYear( e2 );
}