#include #include #include const int MAXNAME = 30; // maximum no. of characters in a name const int ARRAYSIZE = 5; // maximum no. of records in the array struct PayRecord // construct a global structure type { long id; char name[MAXNAME]; float rate; }; // function prototypes needed by main() void selsort(PayRecord [], int); // 1st parameter is an array of records void display( Payrecord [], int); void linsearch(PayRecord [], int, float); int main() { Pay_rec employee[ARRAYSIZE] = { { 34145, "Donaldson, S.", 5.56}, { 33623, "Bohm, P.", 7.54}, { 36203, "Gwodz, K.", 8.72 }, { 32479, "Abrams, B.", 6.72 }, { 35987, "Ernst, T.", 5.43 } }; float cutrate; selsort(employee, ARRAYSIZE); display(employee, ARRAYSIZE); cout << "\nEnter the cutoff pay rate: "; cin >> cutrate; linsearch(employee, ARRAYSIZE, cutrate); return 0; } void selsort(PayRecord array[], int numel) { int i, j, minidx; char minstrng[MAXNAME]; PayRecord temp; for(i = 0; i < (numel - 1); i++) { strcpy(minstrng, array[i].name); //assume minimum is first name in list minidx = i; for(j = i + 1; j < numel; j++) { if ( strcmp(array[j].name, minstrng) < 0 ) // if we've located a { // lower name, capture it strcpy(minstrng, array[j].name); minidx = j; } } if ( strcmp(minstrng, array[i].name) < 0 ) // check for a new minimum { temp = array[i]; array[i] = array[minidx]; array[minidx] = temp; } } } void linsearch(PayRecord array[], int numel, float minrate) { int i; cout << "\nThe employees making less than this rate are:"; for (i = 0; i < numel; ++i) if (array[i].rate < minrate) cout << "\n " << array[i].id << " " << setw(20) << setiosflags(ios::left) << array[i].name; cout << endl; return; } void display(struct PayRecord array[], int numel) { int i; cout << "\nThe sorted array of structures is:"; for (i = 0; i < numel; i++) cout << "\n " << array[i].id << " " << setw(20) << setiosflags(ios::left) << array[i].name << setw(8) << setprecision(2) << array[i].rate; cout << endl; return; }