Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program in which you read 10 names from a file and store them into an ar

ID: 3636356 • Letter: W

Question

Write a program in which you read 10 names from a file and store them into an array of Strings, and then sort that array using bubble sort, and prompt the user to enter a name to look for in that array of String.

Explanation / Answer

#include #include #include /* qsort int comparison function */ int int_cmp(const void *a, const void *b) { const int *ia = (const int *)a; // casting pointer types const int *ib = (const int *)b; return *ia - *ib; /* integer comparison: returns negative if b > a and positive if a > b */ } /* integer array printing function */ void print_int_array(const int *array, size_t len) { size_t i; for(i=0; iprice); /* float comparison: returns negative if b > a and positive if a > b. We multiplied result by 100.0 to preserve decimal fraction */ } /* qsort struct comparision function (product C-string field) */ int struct_cmp_by_product(const void *a, const void *b) { struct st_ex *ia = (struct st_ex *)a; struct st_ex *ib = (struct st_ex *)b; return strcmp(ia->product, ib->product); /* strcmp functions works exactly as expected from comparison function */ } /* Example struct array printing function */ void print_struct_array(struct st_ex *array, size_t len) { size_t i; for(i=0; i Execution result: *** Integer sorting... 7 | 3 | 4 | 1 | -1 | 23 | 12 | 43 | 2 | -4 | 5 | -4 | -1 | 1 | 2 | 3 | 4 | 5 | 7 | 12 | 23 | 43 | *** String sorting... Zorro | Alex | Celine | Bill | Forest | Dexter | Alex | Bill | Celine | Dexter | Forest | Zorro | *** Struct sorting (price)... [ product: mp3 player price: $299.00 ] [ product: plasma tv price: $2200.00 ] [ product: notebook price: $1300.00 ] [ product: smartphone price: $499.99 ] [ product: dvd player price: $150.00 ] [ product: matches price: $0.20 ] -- [ product: matches price: $0.20 ] [ product: dvd player price: $150.00 ] [ product: mp3 player price: $299.00 ] [ product: smartphone price: $499.99 ] [ product: notebook price: $1300.00 ] [ product: plasma tv price: $2200.00 ] -- *** Struct sorting (product)... [ product: dvd player price: $150.00 ] [ product: matches price: $0.20 ] [ product: mp3 player price: $299.00 ] [ product: notebook price: $1300.00 ] [ product: plasma tv price: $2200.00 ] [ product: smartphone price: $499.99 ] --
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote