I'm very new to C++, I'm trying to get some university work done. I'm building my C++ program in Visual Studio 2010. I've poured over the code, and can't figure out why it isn't working. The following is all the code in my project. Sorry that I had to post it all, but I don't know where the problem lies.
employee.h
#ifndef EMPLOYEE_H
#define EMPLOYEE_H
#include <string>
using namespace std;
class Employee
{
public:
int empNumber;
string getName();
int getId();
float getBaseSalary();
virtual string getTitle();
virtual int getNumTaskCompleted();
virtual float getGrossSalary();
virtual float getBonus();
virtual void setEmployeeDetails();
};
#endif
employee.cpp
#include <string>
#include <iostream>
using namespace std;
class Employee
{
private:
string name;
int id;
float salary;
public:
string getName()
{
return this->name;
}
int getId()
{
return this->id;
}
float getBaseSalary()
{
return this->salary;
}
void setEmployeeDetails()
{
cout << "Enter employee name (no spaces): ";
cin >> this->name;
cout << "Enter employee id (numeric): ";
cin >> this->id;
cout << "Enter employee salary: ";
cin >> this->salary;
}
};
projectManager.h
#ifndef PROJECT_MANAGER_H
#define PROJECT_MANAGER_H
#include <string>
#include "employee.h"
using namespace std;
class ProjectManager : public Employee
{
public:
string getTitle();
int getNumTaskCompleted();
float getGrossSalary();
float getBonus();
void setBonus(float bonus);
void setEmployeeDetails();
};
#endif
projectManager.cpp
#include <string>
#include <iostream>
#include "employee.h"
using namespace std;
class ProjectManager : public Employee
{
private:
int numTaskCompleted;
float bonus;
public:
string getTitle()
{
return "Manager";
}
int getNumTaskCompleted()
{
return this->numTaskCompleted;
}
float getGrossSalary()
{
return this->getBaseSalary() + this->bonus;
}
float getBonus()
{
return this->bonus;
}
void setBonus(float bonus)
{
this->bonus = bonus;
}
void setEmployeeDetails()
{
Employee::setEmployeeDetails();
cout << "Enter tasks completed (numeric): ";
cin >> this->numTaskCompleted;
if (numTaskCompleted >= 5)
this->setBonus(10000.00f);
}
};
softwareEngineer.h
#ifndef SOFTWARE_ENGINEER_H
#define SOFTWARE_ENGINEER_H
#include <string>
#include "employee.h"
using namespace std;
class SoftwareEngineer : public Employee
{
public:
string getTitle();
int getNumTaskCompleted();
float getGrossSalary();
float getBonus();
void setBonus(float bonus);
void setEmployeeDetails();
};
#endif
softwareEngineer.cpp
#include <string>
#include <iostream>
#include "employee.h"
using namespace std;
class SoftwareEngineer : public Employee
{
private:
int numTaskCompleted;
float bonus;
public:
string getTitle()
{
return "Engineer";
}
int getNumTaskCompleted()
{
return this->numTaskCompleted;
}
float getGrossSalary()
{
return this->getBaseSalary() + this->bonus;
}
float getBonus()
{
return this->bonus;
}
void setBonus(float bonus)
{
this->bonus = bonus;
}
void setEmployeeDetails()
{
Employee::setEmployeeDetails();
cout << "Enter tasks completed (numeric): ";
cin >> this->numTaskCompleted;
if (numTaskCompleted >= 30)
this->setBonus(5000.00f);
}
};
program.cpp
#include <string>
#include <iostream>
#include <iomanip>
#include "employee.h"
#include "projectManager.h"
#include "softwareEngineer.h"
using namespace std;
Employee *_employees[4];
int main()
{
for (int employeeIndex = 0; employeeIndex < 4; employeeIndex++)
{
Employee *CurrentEmployee = new Employee();
CurrentEmployee->setEmployeeDetails();
_employees[employeeIndex] = CurrentEmployee;
}
cout
<< setw(12) << "Employee"
<< setw(5) << "Id"
<< setw(15) << "Employee"
<< setw(7) << "Task"
<< setw(10) << "Base"
<< setw(13) << "Bonus"
<< setw(12) << "Gross" << endl;
cout
<< setw(11) << "Title"
<< setw(9) << "Number"
<< setw(10) << "Name"
<< setw(12) << "Completed"
<< setw(8) << "Salary"
<< setw(15) << "Entitlement"
<< setw(9) << "Salary" << endl;
for (int employeeIndex = 0; employeeIndex < 4; employeeIndex++)
{
cout
<< setw(12) << _employees[employeeIndex]->getTitle()
<< setw(8) << _employees[employeeIndex]->getId()
<< setw(13) << _employees[employeeIndex]->getName()
<< setw(5) << _employees[employeeIndex]->getNumTaskCompleted()
<< setw(13) << _employees[employeeIndex]->getBaseSalary()
<< setw(14) << _employees[employeeIndex]->getBonus()
<< setw(11) << _employees[employeeIndex]->getGrossSalary() << endl;
}
return 0;
}
When I try to debug this program, I get a message that there are build errors. These are the build errors I am getting.
Error 1 error LNK2019: unresolved external symbol "public: int __thiscall Employee::getId(void)" (?getId@Employee@@QAEHXZ) referenced in function _main E:\C++ Assignments\assignment_7\assignment_7\program.obj assignment_7 Error 3 error LNK2019: unresolved external symbol "public: float __thiscall Employee::getBaseSalary(void)" (?getBaseSalary@Employee@@QAEMXZ) referenced in function _main E:\C++ Assignments\assignment_7\assignment_7\program.obj assignment_7 Error 2 error LNK2019: unresolved external symbol "public: class std::basic_string,class std::allocator > __thiscall Employee::getName(void)" (?getName@Employee@@QAE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) referenced in function _main E:\C++ Assignments\assignment_7\assignment_7\program.obj assignment_7 Error 8 error LNK2001: unresolved external symbol "public: virtual void __thiscall Employee::setEmployeeDetails(void)" (?setEmployeeDetails@Employee@@UAEXXZ) E:\C++ Assignments\assignment_7\assignment_7\program.obj assignment_7 Error 5 error LNK2001: unresolved external symbol "public: virtual int __thiscall Employee::getNumTaskCompleted(void)" (?getNumTaskCompleted@Employee@@UAEHXZ) E:\C++ Assignments\assignment_7\assignment_7\program.obj assignment_7 Error 6 error LNK2001: unresolved external symbol "public: virtual float __thiscall Employee::getGrossSalary(void)" (?getGrossSalary@Employee@@UAEMXZ) E:\C++ Assignments\assignment_7\assignment_7\program.obj assignment_7 Error 7 error LNK2001: unresolved external symbol "public: virtual float __thiscall Employee::getBonus(void)" (?getBonus@Employee@@UAEMXZ) E:\C++
I have absolutely no idea what these errors mean. I've looked up the error codes, but couldn't gleam any information from them that would help me understand what I'm doing wrong.
Can anyone figure out what is wrong? Thanks!