Struct - Array Sorting...this is frustrating...
Alright, I know that this might be really easy for some people, but I am having one heck of a time figuring this out! I was wondering if someone could please help me figure this out...I am in need and this code needs to be done by tomorrow evening, so i was wondering if I could get some straight answers here. :P I am using Dev C++, and here is my code.
Code:
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
using namespace std;
#define ePos 3 // Define the amount of employees
// Create the structure for the employees
struct Employee_t {
string eFName, eLName, eStreetName, eCity, eState;
int eStreetNum, eZip, eID;
}employee [ePos]; // Set a default array to store employees
// Declare the fuctions before main process for use
void printEmployee (Employee_t Employee);
void employeeSort(string array[], int len);
// Start main
int main()
{
// Define the position of the array for employee
int pos;
// Ask for input of employees using a for statement to fill the array
for (pos = 0; pos < ePos; pos++)
{
cout << "\nEnter employee's -\n";
// Ask and store employee's name
cout << "First Name: ";
cin >> employee[pos].eFName;
// Ask and store employee's last name
cout << "Last Name: ";
cin >> employee[pos].eLName;
// Ask and store employee's street number
cout << "Street Number: ";
cin >> employee[pos].eStreetNum;
// Ask and store employee's street number
cout << "Street Name: ";
cin >> employee[pos].eStreetName;
// Ask and store employee's city
cout << "City: ";
cin >> employee[pos].eCity;
// Ask and store employee's state
cout << "State: ";
cin >> employee[pos].eState;
// Ask and store employee's zip code
cout << "Zip Code: ";
cin >> employee[pos].eZip;
// Ask and store employee's customer ID
cout << "Customer ID: ";
cin >> employee[pos].eID;
}
// Display the entered employees
cout << "\nYou have entered these employees: \n";
// Used to display employee's information
for (pos = 0; pos < ePos; pos++)
{
printEmployee (employee[pos]);
}
employeeSort(employee[pos], 4);
// Pause before safe shutdown of program
system("PAUSE");
return EXIT_SUCCESS;
}
// Print the employee's information
void printEmployee (Employee_t Employee)
{
cout << "\n" << Employee.eLName << ", " << Employee.eFName << endl;
cout << Employee.eStreetNum << " " << Employee.eStreetName << endl;
cout << Employee.eCity << ", " << Employee.eState << " " << Employee.eZip << endl;
}
// Sorting function for employees
void employeeSort(string array[], int len) {
int i, j;
string check;
for(i=1; i<len; i++) {
check = array[i];
for(j=i; j>=1 && (check < array[j-1]); j--) {
array[j] = array[j-1];
array[j-1] = check;
}
}
}
If someone could please lead me in the right direction for sorting my employee struct after the data is entered, then I would be so happy!!! Thank you so much in advance!