I'm supposed to create an array of 20 employee objects. My instructor told us to create separate source files for the search and sort functions for this array. Um, how is that done? I created two source files and just put

#include "Employee.h"

at the top of both of them.

I'm really not sure where to go from there. I know what the search and sort functions are but how does one call them in main?

Yes, I'm a programming n00b...

The way you would do this is by writing an Employee.h and an Employee.c (which in turn includes Employee.h). In Main.c you would just include the Employee.h file also, so at compile time the compiler would know how to link them together.

I would put the searching and sorting files at the head of the file with main().

so the file with main() would have:

#include "Employee.h"
#include "search.h"
#include "sort.h"

but I need a bit more information to answer your question fully.

How are you comparing the employee's in the searching and sorting methods? are you using templates with overloaded functions?

Here's what I was given:

Function sortEmployee
Write a new function to sort the array of employees in descending order of base pay. This function will be a separate source file.

Function searchEmployee
Write a new function to search the employee array using the employee ID as a key. It returns the index value of the employee object in the array. This function will be a separate source function.

I wrote my functions in two separate source files. Altogether I have, main.cpp, Employee.cpp, Employee.h, SortEmployee.cpp, SearchEmployee.cpp. They all have #include "Employee.h" at the top.

My search function compiles alright. But how to call it in main? I typed in main int searchEmployee (int searchEmployee (employee, size, searchId) . Here's what is at the beginning of my search function: int searchEmployee(Employee employee[], int size, int searchId) .

I try to compile main and I get an error that says, "type 'int' unexpected" on the line with the function call. Am I not calling it right? The function is returning an integer value so it shouldn't be 'unexpected' right?

My sort function is a whole different matter. EDIT: fixed

ok scrap what i said earlier, you need to include search, sort and employee in main.cpp.

get rid of int in front of the call, do something like:

int something = searchEmployee (employee, size, searchId)
This article has been dead for over six months. Start a new discussion instead.