⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 prg13_3.cpp

📁 这是数据结构和算法的国外经典书籍.清华大学出版社出版的<数据结构C++语言描述-应用模板库STL>陈君 译 英文名称是Data Structures with C++ Using STL.
💻 CPP
字号:
#ifdef _MSC_VER
// disable warning messages that identifier was truncated
// to 'number' characters in the debug information
#pragma warning(disable:4786)
#endif	// _MSC_VER

// File: prg13_3.cpp
// declare four employees and insert each one into a map whose key
// is SSN of a worker and whose value is a pointer to the employee
// object. in a loop, prompt for Social Security Number. use find()
// to search map for an entry with that SSN. if located, pass
// pointer value to function pay() that processes the paycheck for
// employee. if the SSN is not valid, output a message. terminate
// the program when the user inputs the SSN "000-00-0000"

#include <iostream>
#include <fstream>
#include <map>

#include "d_emp.h"	// include the employee hierarchy

using namespace std;

// issue the pay check to the employee pointed to by emp
void pay(employee* emp);

int main()
{
	// declare four employees
	salaryEmployee sEmpA ("Bill Roberts","837-57-8293", 950.00);
	salaryEmployee sEmpB ("Dena Thomas","538-27-4981", 1300.00);
	hourlyEmployee hEmpA ("Sally Gere","583-73-5081", 15.00, 40.00);
	hourlyEmployee hEmpB ("Ty Le","654-20-2981", 30.00, 30.00);

	// database is a map with SSN as the key and a pointer to the
	// employee as the value
	map<string, employee*> empMap;
	string ssn;

	// insert the employees into the map
	empMap["837-57-8293"] = &sEmpA;
	empMap["538-27-4981"] = &sEmpB;
	empMap["583-73-5081"] = &hEmpA;
	empMap["654-20-2981"] = &hEmpB;

	while (true)
	{
		cout << "Enter social security number: ";
		cin >> ssn;
		if (ssn == "000-00-0000")
			break;

		// search for ssn in the map and pay the
		// employee if found
		if (empMap.find(ssn) != empMap.end())
			pay(empMap[ssn]);
		else
			cout << "Not a recognized employee" << endl;
		cout << endl;
	}

	return 0;
}

void pay(employee* emp)
{
	// execute payrollCheck() for the type of employee
	// emp points at
	emp->payrollCheck();
}

/*
Run:

Enter social security number: 538-27-4981
Pay Dena Thomas (538-27-4981)  $1300.00

Enter social security number: 691-45-7651
Not a recognized employee

Enter social security number: 654-20-2981
Pay Ty Le (654-20-2981)  $900.00

Enter social security number: 000-00-0000
*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -