极简单的员工工资系统

头文件

#include 
   
   
    
    
#include 
    
    
     
     
#include 
     
     
      
      
#pragma once
using namespace std;

const int max_size = 1000;

class Employee
{
public:
	Employee (string name, int years) 
		:employee_name (name), work_years (years)
	{};
	virtual int get_salary () = 0;
	string get_name () { return employee_name; };
protected:
	int work_years;
	string employee_name;
};

class Worker: public Employee
{
public:
	Worker (string name, int years) 
		:Employee (name, years)
	{};
	virtual int get_salary ()
	{
		return 2000 + 200 * work_years;
	}
};

class Manager : public Employee
{
public:
	Manager (string name, int years)
		:Employee (name, years)
	{};
	virtual int get_salary ()
	{
		return 10000 + 5000 * work_years;
	}
};

class salary_system
{
public:
	salary_system (void) {};
	void input_employee (void);
	void display_salary (void);
	double get_averge_salary (void);
private:
	vector
      
      
       
       managers;
	vector
       
       
         workers; }; 
       
      
      
     
     
    
    
   
   

源文件

#include  "stdafx.h" 
#include "SalarySystem.h"
#include 
   
   
    
    
#include 
    
    
     
     
#include 
     
     
      
      
#include 
      
      
       
       

using namespace std;

void salary_system::input_employee (void)
{
	cout << "请输入员工信息\n" <<
		"格式: 员工姓名 工龄 是否为经理\n" <<
		"例如: Ian 4 1" <<
		"按Ctrl + Z 表示结束" << endl;

	string name = " ";
	int years = 0;
	bool is_manager = false;
	int index = 0;

	while (index < max_size) {
		cin.clear ();
		cin >> name >> years >> is_manager;
		if (!cin)break;
		(is_manager) ?
			managers.push_back (Manager (name, years))
			: workers.push_back (Worker (name, years));
		++index;
	}
}

void salary_system::display_salary (void)
{
	cout << "工资管理系统" << endl;
	cout << "当前员工总数:" << (managers.size () + workers.size ());
	cout << "\n平均工资为:" << get_averge_salary () << endl;
	cout << "员工具体工资信息如下:\n" << endl;
	cout << "经理:\n";
	for (auto &manager : managers)
		cout << manager.get_name () << '\t'
		<< manager.get_salary () << endl;
	cout << endl;
	cout << "普通员工:\n";
	for (auto &worker : workers)
		cout << worker.get_name () << '\t'
		<< worker.get_salary () << endl;
}

double salary_system::get_averge_salary (void)
{
	int worker_total = 0;
	for (auto &w_salary : workers)
		worker_total += w_salary.get_salary ();
	int manager_total = 0;
	for (auto &m_total : managers)
		manager_total += m_total.get_salary ();
	return (double)(manager_total + worker_total)
		/ (workers.size () + managers.size ());
}

int main (int argc, char* argv[])
{
	std::ios::sync_with_stdio (false);
	salary_system a_system;

	a_system.input_employee ();

	a_system.display_salary ();
	system ("pause");
	return 0;
}

      
      
     
     
    
    
   
   

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值