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

Java Programming: Problem 5 (name this Lab11_Problem5) This program will generat

ID: 3767552 • Letter: J

Question

Java Programming:

Problem 5 (name this Lab11_Problem5)

This program will generate some random numbers to populate a one-dimensional array and then, using a method, display the "before" view. You will then ask the user, using another method, to decide how to sort the array in either ascending or descending order. This method will then call one of two additional methods to sort the array as requested. Finally, you will display the "after" view using the display method.

In your main() method, create an array that holds 10 integer values.

Write a method that will be called from main(). The method will populate the array with random numbers. Pass the method the array itself, along with the minimum and maximum values in the random number range you want to be generated. Since arrays are passed by reference, there is nothing to return to main() from this method.

Write a method to display the data in the array. Here is sample output, generated from a minimum and maximum of 1 to 200. Make your method display it like this, although your values will vary:

Native Order: 47 93 108 173 4 38 62 87 19 11

Write a method to prompt the user for either an A or a D. Accept nothing else; see Notes 5-B for ideas on how to implement this. Return the choice the user makes to the main() method. Make the dialog look and work like this:

Enter A for ascending sort, D for descending: X
Error: type A or D
Enter A for ascending sort, D for descending: A

If the user picks A, then write and call a method that sorts the array in ascending order. If the user types D, then call a method that sorts the array in descending order. You will need two methods, but they will be fairly similar.

Display the output after the sort is complete. Make your output look like this; your values will vary, or you may be using Sorted Descending instead:

Sorted Ascending: 4 11 19 38 47 62 87 93 108 173

After you get the sorting working properly, add functionality to your application to display the number of interchanges that were required to accomplish the sort. Display it like this example:

Interchanges required to sort: 24

Explanation / Answer

#include #include #include #define randrange(N) rand() / (RAND_MAX/(N) + 1) #define MAX 100 /* Values will be in the range (1 .. MAX) */ static int vektor[10]; int candidates[MAX]; int main (void) { int i; srand(time(NULL)); /* Seed the random number generator. */ for (i=0; i
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