Question: follow the instruction, write a program in C language (no c++): sortMe.c #include #include #include compareFunctions.h #include compareElements.h int main() { int i = 0;

follow the instruction, write a program in C language (no c++):

follow the instruction, write a program in C language (no c++): sortMe.c

sortMe.c

#include

#include

#include "compareFunctions.h"

#include "compareElements.h"

int main()

{

int i = 0;

int size;

int (*compare_ptr)(const void *a, const void *b);

struct element array[] = { { 10, "Brown", 10000.0 },

{ 1, "White", 20000.0 },

{ 20, "Black", 30000.0 },

{ 5, "Pink", 50000.0 },

{ 3, "Orange", 25000.0 },

{ 2, "Gray", 200000.0 } };

size = 6;

printf ("Original Array: ");

for ( i=0; i

printf ( "%02d. %10s %10.2f ", array[i].id_number, array[i].last_name, array[i].salary );

}

compare_ptr = &compare_id_ascending;

qsort ( array, size, sizeof(struct element), compare_ptr);

printf ("Sorted by ID Number (ascending): ");

for ( i=0; i

printf ( "%02d. %10s %10.2f ", array[i].id_number, array[i].last_name, array[i].salary );

}

compare_ptr = &compare_id_descending;

qsort ( array, size, sizeof(struct element), compare_ptr);

printf ("Sorted by ID Number (descending): ");

for ( i=0; i

printf ( "%02d. %10s %10.2f ", array[i].id_number, array[i].last_name, array[i].salary );

}

compare_ptr = &compare_name_ascending;

qsort ( array, size, sizeof(struct element), compare_ptr);

printf ("Sorted by Last Name (ascending): ");

for ( i=0; i

printf ( "%02d. %10s %10.2f ", array[i].id_number, array[i].last_name, array[i].salary );

}

compare_ptr = &compare_name_descending;

qsort ( array, size, sizeof(struct element), compare_ptr);

printf ("Sorted by Last Name (descending): ");

for ( i=0; i

printf ( "%02d. %10s %10.2f ", array[i].id_number, array[i].last_name, array[i].salary );

}

compare_ptr = &compare_money_ascending;

qsort ( array, size, sizeof(struct element), compare_ptr);

printf ("Sorted by Salary (ascending): ");

for ( i=0; i

printf ( "%02d. %10s %10.2f ", array[i].id_number, array[i].last_name, array[i].salary );

}

compare_ptr = &compare_money_descending;

qsort ( array, size, sizeof(struct element), compare_ptr);

printf ("Sorted by Salary (descending): ");

for ( i=0; i

printf ( "%02d. %10s %10.2f ", array[i].id_number, array[i].last_name, array[i].salary );

}

return 0;

}

compareElements.h

/*

* Structure

*/

struct element {

int id_number;

char last_name[10];

float salary;

};

compareFunctions.h

/*

* Functions to do comparison for qsort

*/

int compare_id_ascending ( const void *, const void * );

int compare_id_descending ( const void *, const void * );

int compare_name_ascending ( const void *, const void * );

int compare_name_descending ( const void *, const void * );

int compare_money_ascending ( const void *, const void * );

int compare_money_descending ( const void *, const void * );

You are given three files: 1. compare Elements h 2. compare Functions.h 3. sort Me.c You are to write the functions declared in compareFunctions.h 1. int compare id ascending const void const void 2. int compare id descending const void const void 3. int compare name ascending const void const void 4. int compare name descending const void const void 5. nt compare money ascending const void const void 6. int compare money descending (const void const void The program sortMe.c uses the gsort function to sort an array of structures (the structure definition is in compareElements.h) n six different ways Write the six comparison functions. Put each function in a separate file and write a makefile that separately compiles them and then links them to the sortMe.c program to produce the executable sort Me

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!