Ok I think I understand what is going on but I still get
" gcc: Compilation of header file requested
gcc: file path prefix `C:\DEV-C_~1\Bin\' never used "
errors when I try to compile.
Here is the actual code. When the Employee class and its functions were in the body of the main program, the program would compile and run. Now that I moved them to a .h and .cpp file I get the fore mentioned errors.
Eventually I would like to remove all of the classes and their functions to separate files.
Any suggestions would be appreciated.
.h file
Code:
#include <iostream>
#include <iomanip>
#include <string>
#ifndef Employee.h
#define Employee.h
class Employee
{ public:
bool operator==(int find);
virtual void getData() = 0;
virtual void dsplyData() = 0;
protected:
string fName; // Employee's first name
string lName; // Employee's last name
int age; // Employee's age
int empId; // Employee's employee ID number
float salary; // Employee's anual salary
string school; // School graduated from
};
#endif
.cpp file
Code:
#include <iostream>
#include <iomanip>
#include <string>
#include "Employee.h"
using namespace std;
void Employee::getData() // Get employee information
{ cout<< " First Name: " << endl
<< "->: ";
cin>> fName;
cout<< " Last Name: " << endl
<< "->: ";
cin>> lName;
cout<< " Age: " << endl
<< "->: ";
cin>> age;
cout<< " Employee ID: " << endl
<< "->: ";
cin>> empId;
cout<< " Anual Salary: " << endl
<< "->: ";
cin>> salary; }
void Employee::dsplyData() // Display employee information
{ cout<< " Name: " << fName << " " << lName << endl;
cout<< " Age: " << age << endl;
cout<< " Employee ID: " << empId << endl;
cout<< " Anual Salary: " << salary << endl;}
bool Employee::operator==(int find)
{ if(empId == find)
return true;
return false;
}
main program
Code:
#include <iostream>
#include <iomanip>
#include <string>
#include "Employee.h"
using namespace std;
/***** GLOBAL VARS & CONSTANTS */
const int arraySize = 50; // The size of the employee data base
/***** CLASS DEFINITOINS *******/
class Engineer : public Employee
{ public:
Engineer(){};
void getData();
void dsplyData();
~Engineer(){};
private:
string discipline; // Engineering disciplin.. Electrical/Chemical/Software/etc.
string certs; // Certifications.. PE/MSCD/MSCE/etc
};
class Manager : public Employee
{ public:
Manager(){}
void getData();
void dsplyData();
~Manager(){};
private:
string deptManages; // Department being managed
int numEmployees; // Number of direct reports
};
class Scientist : public Employee
{ public:
Scientist(){};
void getData();
void dsplyData();
~Scientist(){};
private:
string field; // Field of study.. Chem/Biology/etc..
int numNobel; // Number of Nobel Prizes won
int numPatents; // Number of patents held
};
class Laborer : public Employee
{ public:
Laborer(){};
void getData();
void dsplyData();
~Laborer(){};
private:
string specialty; // Job specialty.. Electrical/sheet metal/back hoe/etc
string unionMembership; // The name of the union that the work belongs to
};
/***** PROGRAM BODY ************/
int main()
{
Employee *database[arraySize];
int index = 0; // Starting field for the employee database
int choice; // Used in conjunctionn with the menu
char exit = 'n'; // Used to exit the program when set to Y'
int find; // Used in the Search Option
do
{ system ("cls");
cout<< "********** EMPLOYEE DATABASE **********" << endl << endl;
cout<< " 1. Enter a new Engineer " << endl;
cout<< " 2. Enter a new Manager " << endl;
cout<< " 3. Enter a new Scientist " << endl;
cout<< " 4. Enter a new Laborer " << endl;
cout<< " 5. View all employees " << endl;
cout<< " 6. Search for a Employee " << endl;
cout<< " 7. Exit " << endl << endl;
cout<< "***************************************" << endl;
cout<< "->: ";
cin>> choice;
switch (choice)
{ case 1: // Enter a new Engineer
system("cls");
if(index < arraySize)
{ cout<< "************* NEW ENGINEER ************" << endl << endl;
database[index] = new Engineer;
database[index] -> getData();
++index;
}
else
{ cout<< "The database is full " << endl << endl;
system("PAUSE");
}
break;
case 2: // Enter a new Manager
system("cls");
if(index < arraySize)
{ cout<< "************* NEW Manager *************" << endl << endl;
database[index] = new Manager;
database[index] -> getData();
++index;
}
else
{ cout<< "The database is full " << endl << endl;
system("PAUSE");
}
break;
case 3: // Enter a new Scientist
system("cls");
if(index < arraySize)
{ cout<< "************* NEW Scientist ***********" << endl << endl;
database[index] = new Scientist;
database[index] -> getData();
++index;
}
else
{ cout<< "The database is full " << endl << endl;
system("PAUSE");
}
break;
case 4: // Enter a new Laborer
system("cls");
if(index < arraySize)
{ cout<< "************* NEW LABORER *************" << endl << endl;
database[index] = new Laborer;
database[index] -> getData();
++index;
}
else
{ cout<< "The database is full " << endl << endl;
system("PAUSE");
}
break;
case 5: // Display all employees
system("cls");
cout<< "************* Employee Data **************" << endl << endl;
for(int i=0; i < index; ++i)
{ database[i] -> dsplyData();
}
if (index == 0)
cout<< "The database is empty " << endl;
system("pause");
break;
case 6: // Search for employee by empId
system("cls");
cout<< "Enter An Employee Number Search for: " << endl
<< "->: ";
cin>> find;
system("cls");
for(int i=0; i<index; i++)
{ if(*database[i]==find)
{ database[i]->dsplyData();
break;
}
}
cout<< "Finished looking for " << find << endl << endl;
system("Pause");
break;
case 7: // Exit the program
exit = 'y';
break;
default: // Default error message
cout<< "Please enter a valid option (1,2,3)" << endl << endl;
choice = '\0';
system("PAUSE");
break;
}
} while(exit == 'n');
return 0;
}
/***** FUNCTION DEFINITIONS ****/
void Engineer::getData() // Get Engineer information
{ Employee::getData();
cout<< " School Graduated From: " << endl
<< "->: ";
cin>> school;
cout<< " Engineering Disipline (Eletrical, Chemical, Software, etc): " << endl
<< "->: ";
cin>> discipline;
cout<< " Certifications (PE, MSCD, MSCE, etc): " << endl
<< "->: ";
cin>> certs;
}
void Engineer::dsplyData() // Display engineer information
{ cout<< "***************** ENGINEER *****************" << endl;
Employee::dsplyData();
cout<< " School Graduated From: " << school << endl;
cout<< " Engineering Disipline: " << discipline << endl;
cout<< " Certificatoins: " << certs << endl << endl;
cout<< "____________________________________________" << endl << endl;
}
void Manager::getData() // Get manager information
{ Employee::getData();
cout<< " School Graduated From: " << endl
<< "->: ";
cin>> school;
cout<< " Department Manages: " << endl
<< "->: ";
cin>> deptManages;
cout<< " Number of Employees: " << endl
<< "->: ";
cin>> numEmployees;
}
void Manager::dsplyData() // Display manager information
{ cout<< "***************** MANAGER ******************" << endl;
Employee::dsplyData();
cout<< " School Graduated From: " << school << endl;
cout<< " Deparment Manages: " << deptManages << endl;
cout<< " Number of Employees" << numEmployees << endl << endl;
cout<< "____________________________________________" << endl << endl;
}
void Scientist::getData() // Get scientist information
{ Employee::getData();
cout<< " School Graduated From: " << endl
<< "->: ";
cin>> school;
cout<< " Field (Chem, Biology, etc): " << endl
<< "->: ";
cin>> field;
cout<< " Number of Nobel Prizes in Technology: " << endl
<< "->: ";
cin>> numNobel;
cout<< " Number of Patents: " << endl
<< "->: ";
cin>> numPatents;
}
void Scientist::dsplyData() // Display scientist information
{ cout<< "***************** SCIENTIST ****************" << endl;
Employee::dsplyData();
cout<< " School Graduated From: " << school << endl;
cout<< " Number of Nobel Prizes: " << numNobel << endl;
cout<< " Number of Patents: " << numPatents << endl << endl;
cout<< "____________________________________________" << endl << endl;
}
void Laborer::getData() // Get laborer information
{ Employee::getData();
cout<< " Specialty (Eletrical, Sheet Metal, Back Hoe, etc): " << endl
<< "->: ";
cin>> specialty;
cout<< " Union (IBEW, AFL-CIO, Teamsters, etc): " << endl
<< "->: ";
cin>> unionMembership;
}
void Laborer::dsplyData() // Display laborer information
{ cout<< "***************** LABORER ******************" << endl;
Employee::dsplyData();
cout<< " Specialty: " << specialty << endl;
cout<< " Union: " << unionMembership << endl << endl;
cout<< "____________________________________________" << endl << endl;
}
Thanks,
Rich