Hey folks - i am working on an assignment for school and would like some input if possible.
I am trying to declare a class object in the form of an array so that i can read info from file and then manipulate the data.
I need 3 seperate c++ files for this assignment. One is a header file, which contains the class definition etc. The other cpp file contains the class methods, while the third contains the main part of the program. Both the main cpp file and the methods cpp file have the header file included
#include "Employee.h"
Within the main.cpp file i am trying to do this:
#include "Employee.h"
#include <iostream>
using namespace std;
int buildEmployeeList(Employee []);
int main()
{
int array_size = 0;
// Declare Employee object array for employees
Employee employee_list[100];
array_size = buildEmployeeList(employee_list); //Builds the employee array object
system("PAUSE");
return 0;
}
int buildEmployeeList(Employee employee_list[])
{
//DOES STUFF
int count = 1;
return count;
}
I get a linker error with the above code. My header file is:
#ifndef EMPLOYEE_H
#define EMPLOYEE_H
#include <fstream>
#include <istream>
using namespace std;
class Employee
{
private:
char firstName[11];
char lastName[16];
char department[16];
double salary;
public:
Employee();
char *getDepartment();
double getSalary();
void print();
};
#endif /* EMPLOYEE_H */
And my method cpp file is:
#include "Employee.h"
#include <iostream>
/****************************************************************
FUNCTION: Employee:Employee()
ARGUMENTS: none
RETURNS: none
NOTES: This is the class Employee constructor
****************************************************************/
Employee::Employee()
{
firstName[0] = '\0'; //Sets null char to firstName
lastName[0] = '\0'; //Sets null char to lastName
salary = 0; //Sets salary to 0
}
/****************************************************************
FUNCTION: Employee::getDepartment()
ARGUMENTS: none
RETURNS: Department name
NOTES: Returns the name of the department for the individual
****************************************************************/
char * Employee::getDepartment()
{
return department;
}
/****************************************************************
FUNCTION: Employee::getSalary()
ARGUMENTS: none
RETURNS: Salary amount
NOTES: Returns the salary for an individual
****************************************************************/
double Employee::getSalary()
{
return salary;
}
/****************************************************************
FUNCTION: Employee::print()
ARGUMENTS: none
RETURNS: none
NOTES: Prints the values of the data members
****************************************************************/
void Employee::print()
{
cout << "Name ---- Department ---- Salary";
}
int main()
{
return 0;
}
So why cant i declare my Employee employee_list[100] in the main.cpp file? Am i not referencing the Class Employee correctly? Sorry if my code is awful, i havent coded anything in 3 months and forgot half of it!
Please any answers or questions to help me would be awesome. Just point me in the right direction, throw me a link so i can learn, anything would be great.