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

📄 d_tcard.h

📁 数据结构c++语言描述stl版 威廉兄弟的好书,值得看,这是配书代码
💻 H
字号:
#ifndef TIMECARD_CLASS
#define TIMECARD_CLASS

#include <iostream>

#include "d_time24.h"
#include "d_except.h"
#include "d_util.h"

using namespace std;

class timeCard
{
	public:
		timeCard(const string& ssno, double rate, int punchInHour,
					int punchInMinute);

		void punchOut(const time24& t);
			// assign t to punchOutTime and set hasPunched to true

		void writeSalaryInfo();
			// output a log that includes the beginning and ending times for
			// the day's work, the amount of time worked, the pay rate
			// and the earnings.
			// precondition:  throw a rangeError exception if worker has not
			//						punched out (hasPunched == false)

	private:
		string workerID;
		time24 punchInTime, punchOutTime;	// supplier-class objects
		double payrate;
		bool hasPunched;
};

// use initialization list to initialize data members
timeCard::timeCard(const string& ssno, double rate, int punchInHour,
						 int punchInMinute):
		workerID(ssno), payrate(rate), hasPunched(false),
		punchInTime(punchInHour, punchInMinute)
{}

void timeCard::punchOut(const time24& t)
{
	punchOutTime = t;
	hasPunched = true;
}

void timeCard::writeSalaryInfo()
{
	// throw an exception if the worker did not punch out
	if (hasPunched == false)
		throw rangeError("timeCard: writeSalaryInfo() called before "
							  "punching out");

	// total time worked
	time24 timeWorked = punchInTime.duration(punchOutTime);
	// hours and fraction of an hour worked
	double hoursWorked = timeWorked.getHour() +
								timeWorked.getMinute()/60.0;

	// format the output
	cout << "Worker:      " << workerID << endl;
	cout << "Start time: ";
	punchInTime.writeTime();
	cout << "  End time: ";
	punchOutTime.writeTime();
	cout << endl;
	cout << "Total time:  " << setreal(1,2) << hoursWorked
		  << " hours" << endl;
	cout << "At $" << setreal(1,2) << payrate
		  << " per hour, the days earnings are $"
		  << setreal(1,2) << payrate*hoursWorked << endl;
}

#endif	// TIMECARD_CLASS

⌨️ 快捷键说明

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