Assignment 6B: Forwards and Backwards. Up to this point, we have sorted array values from smallest to largest. However, there are times when we need to do the reverse and sort from largest to smallest. We will implement a way to do this using Insertion Sort and Selection Sort. Take in an initial array size value from the user (C++ students: Check the Appendix for more information on how to do this) and a value for the highest possible value in the sequence. Fill the array with random values between 0 and that highest value. Then provide the user with the following options: Change the array's elements with new random values • Use the numbers entered by the user initially for this; do not prompt the user for new numbers • Sort from smallest to largest • Use Insertion Sort to sort the array so that the smallest value is at index 0, and the largest value is at the end of the array. Sort from largest to smallest • Use Selection Sort to sort the array so that the largest value is at index 0, and the smallest value is at the end of the array. Quit to end the program After an option is picked (except for Quit), print the array out and provide the choices to the user once again. The sample output shows the format of your program's output – however, the values will be different since the numbers are generated randomly.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

C++ please. 

**Sample Output:**

**How large should the array be?** 10  
**What should be the highest number in the sequence?** 6  

Initial array: `5, 2, 2, 2, 3, 0, 1, 6, 2, 1,`

**[Options]**  
1) Reset the array  
2) Sort (Smallest to Largest)  
3) Sort (Largest to Smallest)  
4) Quit  

**Choice?** 2  

Using Insertion Sort:  
`0, 1, 1, 2, 2, 2, 2, 3, 5, 6,`

**[Options]**  
1) Reset the array  
2) Sort (Smallest to Largest)  
3) Sort (Largest to Smallest)  
4) Quit  

**Choice?** 3  

Using Selection Sort:  
`6, 5, 3, 2, 2, 2, 2, 1, 1, 0,`

---

**Explanation:**

This text demonstrates sorting algorithms with user input. The array initially has 10 elements with a maximum value of 6. The user chooses from menu options to sort the array:

- **Insertion Sort** arranges numbers from smallest to largest.
- **Selection Sort** arranges numbers from largest to smallest. 

The array is reset between operations to demonstrate different sorting techniques.
Transcribed Image Text:**Sample Output:** **How large should the array be?** 10 **What should be the highest number in the sequence?** 6 Initial array: `5, 2, 2, 2, 3, 0, 1, 6, 2, 1,` **[Options]** 1) Reset the array 2) Sort (Smallest to Largest) 3) Sort (Largest to Smallest) 4) Quit **Choice?** 2 Using Insertion Sort: `0, 1, 1, 2, 2, 2, 2, 3, 5, 6,` **[Options]** 1) Reset the array 2) Sort (Smallest to Largest) 3) Sort (Largest to Smallest) 4) Quit **Choice?** 3 Using Selection Sort: `6, 5, 3, 2, 2, 2, 2, 1, 1, 0,` --- **Explanation:** This text demonstrates sorting algorithms with user input. The array initially has 10 elements with a maximum value of 6. The user chooses from menu options to sort the array: - **Insertion Sort** arranges numbers from smallest to largest. - **Selection Sort** arranges numbers from largest to smallest. The array is reset between operations to demonstrate different sorting techniques.
**Assignment 6B: Forwards and Backwards**

Up to this point, we have sorted array values from smallest to largest. However, there are times when we need to do the reverse and sort from largest to smallest. We will implement a way to do this using Insertion Sort and Selection Sort.

Take in an initial array size value from the user (**C++ students:** Check the Appendix for more information on how to do this) and a value for the highest possible value in the sequence. Fill the array with random values between 0 and that highest value. Then provide the user with the following options:

- **Change the array’s elements with new random values**
  - Use the numbers entered by the user initially for this; do not prompt the user for new numbers
- **Sort from smallest to largest**
  - Use **Insertion Sort** to sort the array so that the smallest value is at index 0, and the largest value is at the end of the array.
- **Sort from largest to smallest**
  - Use **Selection Sort** to sort the array so that the largest value is at index 0, and the smallest value is at the end of the array.
- **Quit to end the program**

After an option is picked (except for Quit), print the array out and provide the choices to the user once again. The sample output shows the format of your program’s output – however, the values will be different since the numbers are generated randomly.
Transcribed Image Text:**Assignment 6B: Forwards and Backwards** Up to this point, we have sorted array values from smallest to largest. However, there are times when we need to do the reverse and sort from largest to smallest. We will implement a way to do this using Insertion Sort and Selection Sort. Take in an initial array size value from the user (**C++ students:** Check the Appendix for more information on how to do this) and a value for the highest possible value in the sequence. Fill the array with random values between 0 and that highest value. Then provide the user with the following options: - **Change the array’s elements with new random values** - Use the numbers entered by the user initially for this; do not prompt the user for new numbers - **Sort from smallest to largest** - Use **Insertion Sort** to sort the array so that the smallest value is at index 0, and the largest value is at the end of the array. - **Sort from largest to smallest** - Use **Selection Sort** to sort the array so that the largest value is at index 0, and the smallest value is at the end of the array. - **Quit to end the program** After an option is picked (except for Quit), print the array out and provide the choices to the user once again. The sample output shows the format of your program’s output – however, the values will be different since the numbers are generated randomly.
Expert Solution
Step 1

Below program implements functions resetArr() to set random values to the array, printArr() method to print the array, insertionSort() and selectionSort() method to sort the array and utility function swap() for selectionSort()

 

Further comments are included in the program for better understanding, proram screenshot and OUTPUT screenshot is added at the bottom as well.

steps

Step by step

Solved in 3 steps with 3 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY