Write a program with a generic function that will sort array of integer, float value. The program should have a menu with appropriate options and accept the values from the user
Question
Write a program with a generic function that will sort array of integer, float value. The program should have a menu with appropriate options and accept the values from the user
Solution
Sure! Here is a step-by-step guide to writing a program that sorts an array of integer and float values using a generic function:
-
Start by defining the main function of your program. This function will serve as the entry point for your program and will contain the menu and user input logic.
-
Inside the main function, create an empty array to store the user input values. This array will be used for sorting later.
-
Display a menu to the user with appropriate options. For example, you can provide options to add values, sort the array, or exit the program.
-
Implement the logic to handle user input based on the selected menu option. For example, if the user chooses to add values, prompt the user to enter the values and store them in the array.
-
Create a generic function that takes the array as a parameter and sorts it. This function should be able to handle both integer and float values.
-
Inside the generic sorting function, use a sorting algorithm such as bubble sort, insertion sort, or quicksort to sort the array in ascending order.
-
After sorting the array, display the sorted values to the user.
-
Repeat steps 3 to 7 until the user chooses to exit the program.
-
Test your program by running it and verifying that it correctly sorts the array of integer and float values.
Remember to handle any potential errors or edge cases, such as invalid user input or empty arrays.
I hope this helps you get started on writing your program! Let me know if you have any further questions.
Similar Questions
Write a functional program that sorts 10 input integers (signed) using either bubble sort orselection sort algorithm. The output window must show both unsorted array of integers andsorted array of integers.
Develop a Java program for sorting an integer array, floating-point array and character array. Use Generic method for the implementation. Finally print the sorted array. Note: consider the size of the array to be 5.
Design a Java program that allows users to input a series of integers into an array and then sorts the array in ascending order. Implement the sorting algorithm using the bubble sort technique.Write a Java code that accomplishes the following tasks:Prompt the user to enter the number of elements in the array.Prompt the user to input each element of the array.Sort the array in ascending order using the bubble sort algorithm.Display the sorted array.Demonstrate the functionality of your program with a sample input/output scenario.Sample Input12 // No of elements 23 // Elements to store in an array674512900260725434129865Sample Output12 12 23 34 45 54 65 67 72 98 260 900
Write a class to sort the given set of integers in descending order. Include a try block tolocate the array index out of bounds exception and catch it.
Problem StatementDr. Smith manages a chemistry laboratory where he regularly analyzes the concentration values of various samples. He needs a quick and efficient program to sort the concentration values of 5 different lab samples where each sample is uniquely identified by its floating-point concentration value.To assist Dr. Smith in accomplishing the above task, implement a call-by-reference function called sort for sorting the samples in descending order and display the result.Input format :The input consists of five space-separated floating-point values, representing the concentration of lab samples.Output format :The output prints the sorted concentration values in descending order with two decimal places, separated by spaces.Refer to the sample output for formatting specifications.Code constraints :In the given scenario, the test cases fall under the following constraints:1.00 ≤ Each concentration value ≤ 40.00Sample test cases :Input 1 :34.1 3.4 23.54 1.01 40.0Output 1 :40.00 34.10 23.54 3.40 1.01Input 2 :4.78 5.47 7.42 8.94 7.83Output 2 :8.94 7.83 7.42 5.47 4.78
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.