1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
//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
{
Employee::Employee( ) : name("no name yet"), ssn("No number yet"), net_pay(0)
{
//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
{
cout << "\nERROR: print_check FUNCTION CALLED FOR AN \n"
<< "UNDIFFERENTIATED EMPLOYEE. Aborting the program.\n"
<< "Check with the author of the program about this bug.\n";
exit(1);
}
} //employeessavitch
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
//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
{
HourlyEmployee::HourlyEmployee( ) : Employee( ), wage_rate(0), hours(0)
{
//deliberately empty
}
HourlyEmployee::HourlyEmployee(string the_name, string the_number,
double the_wage_rate, double the_hours)
: Employee(the_name, the_number), wage_rate(the_wage_rate), hours(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
<< " Rate: " << wage_rate << " Pay: " << get_net_pay( ) << endl;
cout<< "______________________________________________________________\n";
}
} //employeessavitch
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
//This is the file salariedemployee.cpp
//This is the implementation for the class SalariedEmployee.
//The interface for the class SalariedEmployee is in
//the heade fil/e 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)
: Employee(the_name, the_number), salary(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<< "\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";
void SalariedEmployee::print_check()
{
set_net_pay(salary);
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<< "Salaried Employee. Regular Pay: "
<< salary << endl;
cout<< "_____________________________________________________________________\n";
}
} //employeessavitch
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
#include<iostream>
#include "hourlyemployee.h"
#include "salariedemployee.h"
using std::cout;
using std::endl;
using namespace employeessavitch;
int main()
{
HourlyEmployee joe;
joe.set_name("Might Joe") ;
joe.set_ssn("12345-6789" ) ;
joe.set_rate(20.50) ;
joe.set_hours(40);
cout << "Check for " << joe.get_name( )
<< " for " << joe.get_hours( ) << " hours.\n";
joe.print_check( );
cout << endl;
SalariedEmployee boss("Mr. Big Shot", "987-65-4321", 10500.50);
cout << "Check for " << boss.get_name( ) << endl;
boss.print_check( );
return 0;
}
|
When I compile I get this warning message:
C:\Users\Sikhumbu\AppData\Local\Temp\cc1bVVbs.o Display15.7.cpp:(.text+0x64): undefined reference to `employeessavitch::HourlyEmployee::HourlyEmployee()'
C:\Users\Sikhumbu\AppData\Local\Temp\cc1bVVbs.o Display15.7.cpp:(.text+0xad): undefined reference to `employeessavitch::Employee::set_name(std::string)'
C:\Users\Sikhumbu\AppData\Local\Temp\cc1bVVbs.o Display15.7.cpp:(.text+0x117): undefined reference to `employeessavitch::Employee::set_ssn(std::string)'
C:\Users\Sikhumbu\AppData\Local\Temp\cc1bVVbs.o Display15.7.cpp:(.text+0x155): undefined reference to `employeessavitch::HourlyEmployee::set_rate(double)'
C:\Users\Sikhumbu\AppData\Local\Temp\cc1bVVbs.o Display15.7.cpp:(.text+0x16b): undefined reference to `employeessavitch::HourlyEmployee::set_hours(double)'
C:\Users\Sikhumbu\AppData\Local\Temp\cc1bVVbs.o Display15.7.cpp:(.text+0x178): undefined reference to `employeessavitch::HourlyEmployee::get_hours() const'
C:\Users\Sikhumbu\AppData\Local\Temp\cc1bVVbs.o Display15.7.cpp:(.text+0x18e): undefined reference to `employeessavitch::Employee::get_name() const'
C:\Users\Sikhumbu\AppData\Local\Temp\cc1bVVbs.o Display15.7.cpp:(.text+0x213): undefined reference to `employeessavitch::HourlyEmployee::print_check()'
C:\Users\Sikhumbu\AppData\Local\Temp\cc1bVVbs.o Display15.7.cpp:(.text+0x2b0): undefined reference to `employeessavitch::SalariedEmployee::SalariedEmployee(std::string, std::string, double)'
C:\Users\Sikhumbu\AppData\Local\Temp\cc1bVVbs.o Display15.7.cpp:(.text+0x309): undefined reference to `employeessavitch::Employee::get_name() const'
C:\Users\Sikhumbu\AppData\Local\Temp\cc1bVVbs.o Display15.7.cpp:(.text+0x368): undefined reference to `employeessavitch::SalariedEmployee::print_check()'
c:\program files\dev-cpp\mingw64\x86_64-w64-mingw32\bin\ld.exe C:\Users\Sikhumbu\AppData\Local\Temp\cc1bVVbs.o: bad reloc address 0xf in section `.text$_ZN16employeessavitch8EmployeeD2Ev[__ZN16employeessavitch8EmployeeD2Ev]'
C:\Dev-Cpp\SavitchChapter15\collect2.exe [Error] ld returned 1 exit status