Ch 15.1 - 15.2

Sunday, March 04, 2007

1:17 PM

 

 

//DISPLAY 15.1 Interface for the Base Class Employee

//This is the header file employee.h.

//This is the interface for the class Employee.

//This is primarily intended to be used as a base class to derive

//classes for different kinds of employees.

#ifndef EMPLOYEE_H

#define EMPLOYEE_H

 

#include <string>

using namespace std;

 

namespace employeessavitch

{

 

class Employee

{

public:

Employee( );

Employee(string the_name, string the_ssn);

string get_name( ) const;

string get_ssn( ) const;

double get_net_pay( ) const;

void set_name(string new_name);

void set_ssn(string new_ssn);

void set_net_pay(double new_net_pay);

void print_check( ) const;

private:

string name;

string ssn;

double net_pay;

};

 

}//employeessavitch

 

#endif //EMPLOYEE_H

//DISPLAY 15.2 Implementation for the Base Class Employee

//This is the file: employee.cpp.

//This is the implementation for the class Employee.

//The interface for the class Employee is in the header file employee.h.

#include <string>

#include <cstdlib>

#include <iostream>

#include "employee.h"

using namespace std;

 

namespace employeessavitch

{

{

//deliberately empty

}

 

Employee::Employee(string the_name, string the_number)

: name(the_name), ssn(the_number), net_pay(0)

{

//deliberately empty

}

 

string Employee::get_name( ) const

{

return name;

}

 

string Employee::get_ssn( ) const

{

return ssn;

}

 

double Employee::get_net_pay( ) const

{

return net_pay;

}

 

void Employee::set_name(string new_name)

{

name = new_name;

}

void Employee::set_ssn(string new_ssn)

{

ssn = new_ssn;

}

 

void Employee::set_net_pay (double new_net_pay)

{

net_pay = new_net_pay;

}

 

void Employee::print_check( ) const

{

exit(1);

}

 

}//employeessavitch

//DISPLAY 15.3 Interface for the Derived Class HourlyEmployee

//This is the header file hourlyemployee.h.

//This is the interface for the class HourlyEmployee.

#ifndef HOURLYEMPLOYEE_H

#define HOURLYEMPLOYEE_H

 

#include <string>

#include "employee.h"

 

using namespace std;

 

namespace employeessavitch

{

 

class HourlyEmployee : public Employee

{

public:

HourlyEmployee( );

HourlyEmployee(string the_name, string the_ssn,

double the_wage_rate, double the_hours);

void set_rate(double new_wage_rate);

double get_rate( ) const;

void set_hours(double hours_worked);

double get_hours( ) const;

void print_check( ) ;

 

private:

double wage_rate;

double hours;

};

 

}//employeessavitch

 

#endif //HOURLYMPLOYEE_H

//DISPLAY 15.4 Interface for the Derived Class SalariedEmployee

//This is the header file salariedemployee.h.

//This is the interface for the class SalariedEmployee.

#ifndef SALARIEDEMPLOYEE_H

#define SALARIEDEMPLOYEE_H

 

#include <string>

#include "employee.h"

 

using namespace std;

 

namespace employeessavitch

{

 

class SalariedEmployee : public Employee

{

public:

SalariedEmployee( );

SalariedEmployee (string the_name, string the_ssn,

double the_weekly_salary);

double get_salary( ) const;

void set_salary(double new_salary);

void print_check( );

private:

double salary;//weekly

};

 

}//employeessavitch

 

#endif //SALARIEDEMPLOYEE_H

 

//DISPLAY 15.5 Implementation for the Derived Class HourlyEmployee

//This is the file: hourlyemployee.cpp

//This is the implementation for the class HourlyEmployee.

//The interface for the class HourlyEmployee is in

//the header file hourlyemployee.h.

#include <string>

#include <iostream>

#include "hourlyemployee.h"

using namespace std;

 

namespace employeessavitch

{

 

{

//deliberately empty

}

 

HourlyEmployee::HourlyEmployee(string the_name, string the_number,

double the_wage_rate, double the_hours)

{

//deliberately empty

}

 

void HourlyEmployee::set_rate(double new_wage_rate)

{

wage_rate = new_wage_rate;

}

 

double HourlyEmployee::get_rate( ) const

{

return wage_rate;

}

 

void HourlyEmployee::set_hours(double hours_worked)

{

hours = hours_worked;

}

 

double HourlyEmployee::get_hours( ) const

{

return hours;

}

 

void HourlyEmployee::print_check( )

{

set_net_pay(hours * wage_rate);

 

cout << "\n________________________________________________\n";

cout << "Pay to the order of " << get_name( ) << endl;

cout << "The sum of " << get_net_pay( ) << " Dollars\n";

cout << "________________________________________________\n";

cout << "Check Stub: NOT NEGOTIABLE\n";

cout << "Employee Number: " << get_ssn( ) << endl;

cout << "Hourly Employee. \nHours worked: " << hours

cout << "_________________________________________________\n";

}

 

 

}//employeessavitch

 

//DISPLAY 15.6 Implementation for the Derived Class SalariedEmployee

//This is the file salariedemployee.cpp.

//This is the implementation for the class SalariedEmployee.

//The interface for the class SalariedEmployee is in

//the header file salariedemployee.h.

#include <iostream>

#include <string>

#include "salariedemployee.h"

using namespace std;

 

namespace employeessavitch

{

SalariedEmployee::SalariedEmployee( ) : Employee( ), salary(0)

{

//deliberately empty

}

SalariedEmployee::SalariedEmployee(string the_name, string the_number,

double the_weekly_salary)

{

//deliberately empty

}

 

double SalariedEmployee::get_salary( ) const

{

return salary;

}

 

void SalariedEmployee::set_salary(double new_salary)

{

salary = new_salary;

}

void SalariedEmployee::print_check( )

{

 

set_net_pay(salary);

cout << "Pay to the order of " << get_name( ) << endl;

cout << "The sum of " << get_net_pay( ) << " Dollars\n";

cout << "_________________________________________________\n";

cout << "Check Stub NOT NEGOTIABLE \n";

cout << "Employee Number: " << get_ssn( ) << endl;

cout << "Salaried Employee. Regular Pay: "

<< salary << endl;

cout << "_________________________________________________\n";

}

 

 

}//employeessavitch

 

Created with Microsoft Office OneNote 2003
One place for all your notes