0

I guess someone on this website seems to think this was answered somewhere else. Anyways, I figured it out by myself, all I had to do was include the "EmployeeRecord.cpp" file in the Source Files section of the Solution Explorer... Now I have another problem, so I'll leave this one answered, and ask it somewhere else.

HEADER FILE:

/*******************************************************************
*   File: EmployeeRecord.h
*   Name: You don't need this
*   Assignment 1: Employee Record
*   
*   This program is entirely my own work
*******************************************************************/

// ------------------------------------------------
// EmployeeRecord.h
// Purpose: defining the EmployeeRecord class
// ------------------------------------------------

#ifndef EMPLOYEERECORD_H
#define EMPLOYEERECORD_H

#include <iostream>
#include <string>
using namespace std;

class EmployeeRecord
{
private:
    // private variables
    int m_iEmployeeID;     // employee ID
    char m_sLastName[32];  // employee last name
    char m_sFirstName[32]; // employee first name
    int m_iDeptID;         // department ID
    double m_dSalary;      // employee salary

public:
    // define constructors
    EmployeeRecord();
    EmployeeRecord(int ID, char *fName, char *lName, int dept, double sal);

    // destructor
    ~EmployeeRecord();

    // accessor, mutator, and data manipulation funcitons
    int getID();
    void setID(int ID);

    void getName(char *fName, char *lName);
    void setName(char *fName, char *lName);

    void getDept(int& d);
    void setDept(int d);

    void getSalary(double *sal);
    void setSalary(double sal);
    void printRecord();
};

#endif

OBJECT FILE (MOST IMPORTANT):

/*******************************************************************
*   File: EmployeeRecord.cpp
*   Name: You don't need this
*   Assignment 1: Employee Record
*   
*   This program is entirely my own work
*******************************************************************/

// ------------------------------------------------
// EmployeeRecord.cpp
// Purpose: implementing the funcitons of the EmployeeRecord class
// ------------------------------------------------

#include "EmployeeRecord.h"

//constructor 1 (default)
EmployeeRecord::EmployeeRecord()
{
    m_iEmployeeID = 0;
    m_sLastName = "";
    m_sFirstName = "";
    m_iDeptID = 0;
    m_dSalary = 0.0;
}

// this constructor shall set the member variables to the values passed into the function
EmployeeRecord::EmployeeRecord(int ID, char *fName, char *lName, int dept, double sal)
{
    m_iEmployeeID = ID;
    m_sFirstName = *fName;
    m_sLastName = *lName;
    m_iDeptID = dept;
    m_dSalary = sal;
}

// destructor - cleans up and deallocates any memory that pointers within this class may have referenced to
EmployeeRecord::~EmployeeRecord(){};

// function getID shall return the int value stored in the member variable m_iEmployeeID
int EmployeeRecord::getID()
{
    return m_iEmployeeID;
}

// function setID will set the member variable m_iEmployeeID to the value of its' argument
void EmployeeRecord::setID(int ID)
{
    m_iEmployeeID = ID;
}

// the getName() function shall copy the member variables m_sFirstName and m_sLastName into the character
// arrays pointed to by the function arguments
void EmployeeRecord::getName(char *fName, char *lName)
{
    *fName = m_sFirstName;
    *lName = m_sLastName;
}

// the setName() function will copy the function arguments into the member variables m_sFirstName and m_sLastName
void EmployeeRecord::setName(char *fName, char *lName)
{
    m_sFirstName = *fName;
    m_sLastName = *lName;
}

// the getDept() function shall be defined as a reference function. That is, a call to this function will copy the
// member variable m_iDeptID into the int variable referenced by the function argument
void EmployeeRecord::getDept(int& d)
{
    d = m_iDeptID;
}

// the setDept() function will copy the function argument into the member variable m_iDeptID
void EmployeeRecord::setDept(int d)
{
    m_iDeptID = d;
}

// the getSalary() function shall be defined as a pointer function. That is, a call to this function will copy the
// member variable m_dSalary into the int variable pointed to by the function argument
void EmployeeRecord::getSalary(double *sal)
{
    *sal = m_dSalary;
}

// the function setSalary() shall copy the function argument into the member variable m_dSalary
void EmployeeRecord::setSalary(double sal)
{
    m_dSalary = sal;
}

// this function shall print to the screen all data found in the employee's record
void EmployeeRecord::printRecord()
{
    cout << "Employee ID:   " << m_iEmployeeID << endl;
    cout << "Last Name:     " << m_sLastName << endl;
    cout << "First Name:    " << m_sFirstName << endl;
    cout << "Department ID: " << m_iDeptID << endl;
    cout << "Salary:        " << m_dSalary << endl;
}

MAIN FILE:

/*******************************************************************
*   main function for project Prog1
*******************************************************************/

#include <stdio.h>
#include <time.h>
#include <cstdlib>
#include <windows.h>

#include <string>
#include <iostream>
using namespace std;

#include "EmployeeRecord.h"

int main(void)
{

    int answer, employee_id, dept_id, i;
    char  firstname[35], lastname[35];
    double *salary;

    menu:
    do
    {
        cout << "This program is used to create and modify employee records. This program was" << endl;
        cout << "created and tested by John Doe exclusively under the guidance of the" << endl;
        cout << "Random School Name Here." << endl << endl;
        cout << "Any attempt to copy this program and falsify its origins is punishable under" << endl;
        cout << "both state and federal law." << endl << endl;
        cout << "Thank you for using this program, and I hope you enjoy it." << endl << endl;
        system("pause");

        system("CLS");
        cout << "--------------------------------------------------------------------------------" << endl;
        cout << "                               EMPLOYEE RECORD" << endl;
        cout << "                 Creating and Modifying an Employee Record" << endl << endl;
        cout << "--------------------------------------------------------------------------------" << endl;
        cout << "                            What would you like to do?" << endl << endl;
        cout << " 1. Create a new Employee Record" << endl << endl;
        cout << " 2. Obtain the Employee ID of the current Employee Record" << endl << endl;
        cout << " 3. Enter the Employee ID into the current Employee Record" << endl << endl;
        cout << " 4. Enter the Employee's Name into the current Employee Record" << endl << endl;
        cout << " 5. Enter the Department ID into the current Employee Record" << endl << endl;
        cout << " 6. Enter the Employee's Annual Salary into the current Employee Record" << endl << endl;
        cout << " 7. Print the current Employee Record" << endl << endl;
        cout << " 8. Quit" << endl << endl;
        cin >> answer;


        if (answer == 1)
        {
            system("CLS");
            cout << "--------------------------------------------------------------------------------" << endl;
            cout << "                               EMPLOYEE RECORD" << endl;
            cout << "                 Creating and Modifying an Employee Record" << endl << endl;
            cout << "--------------------------------------------------------------------------------" << endl;
            cout << "                            What would you like to do?" << endl << endl;
            cout << " 1. Create a new Employee Record" << endl << endl;
            cout << "           Enter the Employee's ID:             ";
            cin >> employee_id;
            cout << endl;
            cout << "           Enter the Employee's First Name:     ";
            i = 0;
            cin >> firstname[i];
            while (firstname[i] != '\n' && i < 35)
            {
                i++;
                cin >> firstname[i];
            }
            cout << endl;
            cout << "           Enter the Employee's Last Name:      ";
            i = 0;
            cin >> lastname[i];
            while (lastname[i] != '\n' && i < 35)
            {
                i++;
                cin >> lastname[i];
            }
            cout << endl;
            cout << "           Enter the Department Number:         ";
            cin >> dept_id;
            cout << endl;
            cout << "           Enter the Employee's Annual Salary: $";
            cin >> *salary;

            //EmployeeRecord Employee1 = EmployeeRecord();
            EmployeeRecord Employee1 = EmployeeRecord(employee_id, firstname, lastname, dept_id, *salary);
            Employee1.printRecord();
            system("pause");
            system("CLS");
            goto menu;
        }


        else if (answer == 2)
        {
            EmployeeRecord Employee1 = EmployeeRecord(employee_id, firstname, lastname, dept_id, *salary);
            system("CLS");
            cout << "--------------------------------------------------------------------------------" << endl;
            cout << "                               EMPLOYEE RECORD" << endl;
            cout << "                 Creating and Modifying an Employee Record" << endl << endl;
            cout << "--------------------------------------------------------------------------------" << endl;
            cout << "                            What would you like to do?" << endl << endl;
            cout << " 1. Create a new Employee Record" << endl << endl;
            cout << " 2. Obtain the Employee ID of the current Employee Record" << endl << endl;
            cout << "           The current Employee ID is: " << Employee1.getID();
            system("pause");
            system("CLS");
            goto menu;
        }


        else if (answer == 3)
        {
            EmployeeRecord Employee1 = EmployeeRecord(employee_id, firstname, lastname, dept_id, *salary);
            system("CLS");
            cout << "--------------------------------------------------------------------------------" << endl;
            cout << "                               EMPLOYEE RECORD" << endl;
            cout << "                 Creating and Modifying an Employee Record" << endl << endl;
            cout << "--------------------------------------------------------------------------------" << endl;
            cout << "                            What would you like to do?" << endl << endl;
            cout << " 1. Create a new Employee Record" << endl << endl;
            cout << " 2. Obtain the Employee ID of the current Employee Record" << endl << endl;
            cout << " 3. Enter the Employee ID into the current Employee Record" << endl << endl;
            cout << "          Enter the Employee ID: ";
            cin >> employee_id;
            Employee1.setID(employee_id);
            Employee1.printRecord();
            system("pause");
            system("CLS");
            goto menu;
        }


        else if (answer == 4)
        {
            EmployeeRecord Employee1 = EmployeeRecord(employee_id, firstname, lastname, dept_id, *salary);
            system("CLS");
            cout << "--------------------------------------------------------------------------------" << endl;
            cout << "                               EMPLOYEE RECORD" << endl;
            cout << "                 Creating and Modifying an Employee Record" << endl << endl;
            cout << "--------------------------------------------------------------------------------" << endl;
            cout << "                            What would you like to do?" << endl << endl;
            cout << " 1. Create a new Employee Record" << endl << endl;
            cout << " 2. Obtain the Employee ID of the current Employee Record" << endl << endl;
            cout << " 3. Enter the Employee ID into the current Employee Record" << endl << endl;
            cout << " 4. Enter the Employee's Name into the current Employee Record" << endl << endl;
            Employee1.getName(firstname, lastname);
            cout << "          Enter the Employee's First Name: ";
            cin >> firstname;
            cout << "                            and Last Name: ";
            cin >> lastname;
            Employee1.setName(firstname, lastname);
            Employee1.printRecord();
            system("pause");
            system("CLS");
            goto menu;
        }


        else if (answer == 5)
        {
            EmployeeRecord Employee1 = EmployeeRecord(employee_id, firstname, lastname, dept_id, *salary);
            system("CLS");
            cout << "--------------------------------------------------------------------------------" << endl;
            cout << "                               EMPLOYEE RECORD" << endl;
            cout << "                 Creating and Modifying an Employee Record" << endl << endl;
            cout << "--------------------------------------------------------------------------------" << endl;
            cout << "                            What would you like to do?" << endl << endl;
            cout << " 1. Create a new Employee Record" << endl << endl;
            cout << " 2. Obtain the Employee ID of the current Employee Record" << endl << endl;
            cout << " 3. Enter the Employee ID into the current Employee Record" << endl << endl;
            cout << " 4. Enter the Employee's Name into the current Employee Record" << endl << endl;
            cout << " 5. Enter the Department ID into the current Employee Record" << endl << endl;
            Employee1.getDept(dept_id);
            cout << "          Enter the Department ID: ";
            cin >> dept_id;
            Employee1.setDept(dept_id);
            Employee1.printRecord();
            system("pause");
            system("CLS");
            goto menu;
        }


        else if (answer == 6)
        {
            EmployeeRecord Employee1 = EmployeeRecord(employee_id, firstname, lastname, dept_id, *salary);
            system("CLS");
            cout << "--------------------------------------------------------------------------------" << endl;
            cout << "                               EMPLOYEE RECORD" << endl;
            cout << "                 Creating and Modifying an Employee Record" << endl << endl;
            cout << "--------------------------------------------------------------------------------" << endl;
            cout << "                            What would you like to do?" << endl << endl;
            cout << " 1. Create a new Employee Record" << endl << endl;
            cout << " 2. Obtain the Employee ID of the current Employee Record" << endl << endl;
            cout << " 3. Enter the Employee ID into the current Employee Record" << endl << endl;
            cout << " 4. Enter the Employee's Name into the current Employee Record" << endl << endl;
            cout << " 5. Enter the Department ID into the current Employee Record" << endl << endl;
            cout << " 6. Enter the Employee's Annual Salary into the current Employee Record" << endl << endl;
            Employee1.getSalary(salary);
            cout << "          Enter the Employee's Annual Salary: ";
            cin >> *salary;
            Employee1.setSalary(*salary);
            Employee1.printRecord();
            system("pause");
            system("CLS");
            goto menu;
        }


        else if (answer == 7)
        {
            EmployeeRecord Employee1 = EmployeeRecord(employee_id, firstname, lastname, dept_id, *salary);
            system("CLS");
            cout << "--------------------------------------------------------------------------------" << endl;
            cout << "                               EMPLOYEE RECORD" << endl;
            cout << "                 Creating and Modifying an Employee Record" << endl << endl;
            cout << "--------------------------------------------------------------------------------" << endl;
            cout << "                            What would you like to do?" << endl << endl;
            cout << " 1. Create a new Employee Record" << endl << endl;
            cout << " 2. Obtain the Employee ID of the current Employee Record" << endl << endl;
            cout << " 3. Enter the Employee ID into the current Employee Record" << endl << endl;
            cout << " 4. Enter the Employee's Name into the current Employee Record" << endl << endl;
            cout << " 5. Enter the Department ID into the current Employee Record" << endl << endl;
            cout << " 6. Enter the Employee's Annual Salary into the current Employee Record" << endl << endl;
            cout << " 7. Print the current Employee Record" << endl << endl;
            Employee1.printRecord();
            system("pause");
            system("CLS");
            goto menu;
        }
    } while (answer == 1 || answer == 2 || answer == 3 || answer == 4 || answer == 5 || answer == 6 || answer == 7);

    if (answer != 8)
    {
        system("CLS");
        cout << "Invalid input! Please Choose one of the 8 options below, then press [Enter]." << endl << endl;
        cout << "--------------------------------------------------------------------------------" << endl;
        cout << "                               EMPLOYEE RECORD" << endl;
        cout << "                 Creating and Modifying an Employee Record" << endl << endl;
        cout << "--------------------------------------------------------------------------------" << endl;
        cout << "                            What would you like to do?" << endl << endl;
        cout << " 1. Create a new Employee Record" << endl << endl;
        cout << " 2. Obtain the Employee ID of the current Employee Record" << endl << endl;
        cout << " 3. Enter the Employee ID into the current Employee Record" << endl << endl;
        cout << " 4. Enter the Employee's Name into the current Employee Record" << endl << endl;
        cout << " 5. Enter the Department ID into the current Employee Record" << endl << endl;
        cout << " 6. Enter the Employee's Annual Salary into the current Employee Record" << endl << endl;
        cout << " 7. Print the current Employee Record" << endl << endl;
        cout << " 8. Quit" << endl << endl;
        cin >> answer;
    }

    else if (answer == 8)
    {
        system("CLS");
        cout << endl << endl << endl << endl << "                 THANKS FOR USING THE EMPLOYEE RECORD PROGRAM" << endl << endl;
        cout << "Closing program in... 5 s";
        Sleep(1000);

        system("CLS");
        cout << endl << endl << endl << endl << "                 THANKS FOR USING THE EMPLOYEE RECORD PROGRAM" << endl << endl;
        cout << "Closing program in... 4 s";
        Sleep(1000);

        system("CLS");
        cout << endl << endl << endl << endl << "                 THANKS FOR USING THE EMPLOYEE RECORD PROGRAM" << endl << endl;
        cout << "Closing program in... 3 s";
        Sleep(1000);

        system("CLS");
        cout << endl << endl << endl << endl << "                 THANKS FOR USING THE EMPLOYEE RECORD PROGRAM" << endl << endl;
        cout << "Closing program in... 2 s";
        Sleep(1000);

        system("CLS");
        cout << endl << endl << endl << endl << "                 THANKS FOR USING THE EMPLOYEE RECORD PROGRAM" << endl << endl;
        cout << "Closing program in... 1 s";
        Sleep(1000);

        system("CLS");
        cout << endl << endl << endl << endl << "                                    GOODBYE!" << endl << endl;
        Sleep(1000);
    }
}

So basically, I have these three files, two of them (object and header) are used in the third file (main) to test that the functions are doing their job as described by the commented code in the object file. I can't post images yet, so here is my best attempt at showing you my Solution Explorer:

Solution 'CS 221' (1 project)
 Solution Items
  EmployeeRecord.cpp
 **CS 221**
  External Dependencies
  Header Files
   EmployeeRecord.h
  Resource Files
  Source Files
   EmployeeRecord_main.cpp

It's important to know that I don't have to turn in the main file, just the object and the header... I am VERY new to object-oriented programming, so I think my mistake is just a technical one, not really in the code... But it also might be the fact that I included the destructor...

Anyways, please help me resolve my error using very very dumbed-down rhetoric, because, like I stated in the previous paragraph, this is my first attempt at object oriented programming.

EDIT:

Many of you asked me to include my other source code (which I have been calling the object file) into the Solution Items, then give you the exact error messages, so here they are:

Error 1 error LNK2019: unresolved external symbol "public: __thiscall EmployeeRecord::EmployeeRecord(int,char *,char *,int,double)" (??0EmployeeRecord@@QAE@HPAD0HN@Z) referenced in function _main C:\Users\Tom\Desktop\CS 221\EmployeeRecord_main.obj

Error 2 error LNK2019: unresolved external symbol "public: __thiscall EmployeeRecord::~EmployeeRecord(void)" (??1EmployeeRecord@@QAE@XZ) referenced in function _main C:\Users\Tom\Desktop\CS 221\EmployeeRecord_main.obj

Error 3 error LNK2019: unresolved external symbol "public: int __thiscall EmployeeRecord::getID(void)" (?getID@EmployeeRecord@@QAEHXZ) referenced in function _main C:\Users\Tom\Desktop\CS 221\EmployeeRecord_main.obj

Error 4 error LNK2019: unresolved external symbol "public: void __thiscall EmployeeRecord::setID(int)" (?setID@EmployeeRecord@@QAEXH@Z) referenced in function _main C:\Users\Tom\Desktop\CS 221\EmployeeRecord_main.obj

Error 5 error LNK2019: unresolved external symbol "public: void __thiscall EmployeeRecord::getName(char *,char *)" (?getName@EmployeeRecord@@QAEXPAD0@Z) referenced in function _main C:\Users\Tom\Desktop\CS 221\EmployeeRecord_main.obj

Error 6 error LNK2019: unresolved external symbol "public: void __thiscall EmployeeRecord::setName(char *,char *)" (?setName@EmployeeRecord@@QAEXPAD0@Z) referenced in function _main C:\Users\Tom\Desktop\CS 221\EmployeeRecord_main.obj

Error 7 error LNK2019: unresolved external symbol "public: void __thiscall EmployeeRecord::getDept(int &)" (?getDept@EmployeeRecord@@QAEXAAH@Z) referenced in function _main C:\Users\Tom\Desktop\CS 221\EmployeeRecord_main.obj

Error 8 error LNK2019: unresolved external symbol "public: void __thiscall EmployeeRecord::setDept(int)" (?setDept@EmployeeRecord@@QAEXH@Z) referenced in function _main C:\Users\Tom\Desktop\CS 221\EmployeeRecord_main.obj

Error 9 error LNK2019: unresolved external symbol "public: void __thiscall EmployeeRecord::getSalary(double *)" (?getSalary@EmployeeRecord@@QAEXPAN@Z) referenced in function _main C:\Users\Tom\Desktop\CS 221\EmployeeRecord_main.obj

Error 10 error LNK2019: unresolved external symbol "public: void __thiscall EmployeeRecord::setSalary(double)" (?setSalary@EmployeeRecord@@QAEXN@Z) referenced in function _main C:\Users\Tom\Desktop\CS 221\EmployeeRecord_main.obj

Error 11 error LNK2019: unresolved external symbol "public: void __thiscall EmployeeRecord::printRecord(void)" (?printRecord@EmployeeRecord@@QAEXXZ) referenced in function _main C:\Users\Tom\Desktop\CS 221\EmployeeRecord_main.obj

Error 12 error LNK1120: 11 unresolved externals C:\Users\Tom\Desktop\CS 221\Debug\CS 221.exe

j0hnnyb0y
  • 67
  • 1
  • 1
  • 7
  • can you post the error log for more information. Check this link and see if it fixes your issue https://msdn.microsoft.com/en-us/library/799kze2z.aspx – GingerJack Feb 08 '15 at 17:06
  • Show the errors. And the second file is not an ["object file"](https://en.wikipedia.org/wiki/Object_file). I also don't see `EmployeeRecord.cpp` in your solution structure. If it's not there, you need to add it. – T.C. Feb 08 '15 at 17:07
  • You forgot to include one of the source files in the solution. Note adding it will reveal more compilation errors. – n. m. could be an AI Feb 08 '15 at 17:37
  • I included one of the source files in the solution, and I included the error messages. Also, I'm sorry for calling it an "object file", what is it supposed to be called? – j0hnnyb0y Feb 08 '15 at 17:57
  • The other .cpp file is a source file too. It's no different from the firtst one. Both should be under the "source files" section. – n. m. could be an AI Feb 08 '15 at 21:12

1 Answers1

4

Whenever you declare the destructor (or generally any method) in the .h file, you have to define it somewhere. So:

// a.h
class A {
   A();
   ~A();
}

and:

// a.cpp
A::A() {
   // Do Init Stuff here.
}

A::~A() {
   // Do Destructor Stuff here.
}

Your compiler can and will create a default constructor for you (how much does the default destructor do, see here for what it can do for you) as well as a copyconstructor and a default constructor. It will not do that if you declare them on your own or as other non-default destructors.

So in short: If you put a Destructor Declaration in the .h-file, you must define it in the .cpp-file!

Otherwise, the compiler reads your declaration and thinks "Oh well, it's gotta be declared in some cpp-file, I'll link it later", and then will not find it. If you do not have any Members in your class that are Pointers, no custom destructor should be necessary (unless you want any side effects). In your case, you therefore can use a default destructor.

Community
  • 1
  • 1
  • I think I did both of those. I declared the constructor/destructor in the header file, then defined them both in the .cpp file (although I just put ~EmployeeRecord(){} instead of actually giving it anything in the block of code) – j0hnnyb0y Feb 08 '15 at 17:59
  • I think you had it commented out. There should not be a semi colon after the method body, then try recompiling. – Yannick Schrödel Feb 09 '15 at 16:15