📄 hourly.cpp
字号:
// Exercise 17.11: Hourly.cpp
// HourlyEmployee class member-function definitions.
#include <iostream> // required to perform C++-style stream I/O
using namespace std; // for accessing C++ Standard Library members
#include "Hourly.h" // HourlyEmployee class definition
// constructor for class HourlyEmployee
HourlyEmployee::HourlyEmployee( string &first,
string &last, string &socialSecurityNumber,
double hourlyWage, double hoursWorked )
: Employee( first, last, socialSecurityNumber )
{
setWage( hourlyWage );
setHours( hoursWorked );
} // end HourlyEmployee constructor
// set hourly worker's wage
void HourlyEmployee::setWage( double wageAmount )
{
if ( wageAmount < 0 )
{
wage = 0.0;
} // end if
else
{
wage = wageAmount;
} // end else
} // end function setWage
// set hourly worker's hours worked
void HourlyEmployee::setHours( double hoursWorked )
{
// ensure that hoursWorked is less than hours in one week
if ( hoursWorked < 168.0 )
{
hours = hoursWorked;
} // end if
else
{
hours = 0.0;
} // end else
} // end function setHours
// return hours worked
double HourlyEmployee::getHours()
{
return hours;
} // end function getHours
// return wage
double HourlyEmployee::getWage()
{
return wage;
} // end function getWage
// get hourly worker's pay
double HourlyEmployee::earnings()
{
if ( hours <= 40 ) // no overtime
{
return wage * hours;
} // end if
else // overtime is paid at wage * 1.5
{
return 40 * wage + ( hours - 40 ) * wage * 1.5;
} // end else
} // end function earnings
// print hourly worker's information
void HourlyEmployee::print()
{
cout << "\nHourly employee: ";
Employee::print(); // code reuse
} // end function print
/**************************************************************************
* (C) Copyright 1992-2005 by Deitel & Associates, Inc. and *
* Pearson Education, Inc. All Rights Reserved. *
* DISCLAIMER: The authors and publisher of this book have used their *
* best efforts in preparing the book. These efforts include the *
* development, research, and testing of the theories and programs *
* to determine their effectiveness. The authors and publisher make *
* no warranty of any kind, expressed or implied, with regard to these *
* programs or to the documentation contained in these books. The authors *
* and publisher shall not be liable in any event for incidental or *
* consequential damages in connection with, or arising out of, the *
* furnishing, performance, or use of these programs. *
**************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -