📄 hourly.cpp
字号:
// Implementation file for the Hourly class#include "hourly.h"#include "emp_exceptions.h"using namespace std;Hourly::Hourly(){ m_PayRate = 0.0; m_HoursPerWeek = 0;}Hourly::Hourly( const string& name, const string& ssn, double payrate, int hours ) : Employee( name, ssn ) { // First the base class constructor is called, to store // the name and ssn. Here, we store the hourly pay // rate and the hours worked per week cout << "Constructing an hourly employee!" << endl; m_PayRate = payrate; m_HoursPerWeek = hours;}Hourly::Hourly( const Hourly& h ): Employee( h ) { // Copy data members that haven't already been copied // using the base class copy constructor m_PayRate = h.m_PayRate; m_HoursPerWeek = h.m_HoursPerWeek;}Hourly::~Hourly() { // Nothing to destroy here, because the data members // will be de-allocated automatically cout << "Destroying an hourly employee!" << endl;}double Hourly::GetYearlyPay() const { // Compute yearly pay from hourly rate, hours per week // and weeks per year double pay = m_PayRate * m_HoursPerWeek * 52; if ( pay > 50000.0 ) throw OverpaidException( m_Name, pay ); return pay;}void Hourly::SendTo( ostream& out ) const { // First call base class function Employee::SendTo( out ); // Now output class-specific members out << "Hourly Pay: $" << m_PayRate << " per hour" << endl; out << "Hours Per Week: " << m_HoursPerWeek << endl;}void Hourly::GetFrom( istream& in, bool prompt ) { // First call base class function Employee::GetFrom( in, prompt ); // Now read class-specific members if ( prompt == true ) cout << "Hourly Pay: "; in >> m_PayRate; if ( prompt == true ) cout << "Hours Per Week: "; in >> m_HoursPerWeek;}Hourly& Hourly::operator=( const Hourly& h ) { // We don't need this operator to do anything since // we never want it to be used return *this;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -