Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a JavaScript program that displays the following menu: 1. Fill array 2. Add a number 3.Find the index of a number 4. Remove number

Write a JavaScript program that displays the following menu:

1. Fill array

2. Add a number

3.Find the index

of a number

4. Remove number at index

5. Remove number

6. Quit

Use an int array of size 10. There should be no global variables at all, only constants are allowed. Use a variable to store the number of items the array contains (not all 10 elements will hold user data).

For each menu item 0-6, write a method that takes the array name, the number of items in addition to other arguments (eg: the size of the array) if/when needed.

  1. Fill array: Asks user how many numbers to fill (the length of the partially filled array). Validate the user entered number (1-10 inclusive). Fill the sorted array with random numbers 1-99 inclusive. The number of elements should be equal to the value specified by the user. Must use the provided insertSorted method. You may not add a number then sort the array.

  2. Add a number: If array is full displays a message indicating that, otherwise add a random number in the correct position to the sorted array. You may not add a number then sort the array.

  3. Find index of a number: Displays the index of a number specified by the user f it exists otherwise a message saying that the number is not found.

  4. Remove number at index: Ask the user to enter the index. Remove the number at the specified index or display error message if the specified index is outside the current partially filled array size.

  5. Remove number: Ask the user to enter a number, remove it if it exists otherwise display a message to indicate that it does not exist. Must use the provided deleteElement method.

For searching, you must use the provided binarySearch method. The provided methods may not be modified.

Display the sorted array every time the menu is displayed.

Should look like this

image text in transcribed

Example: 1. Fill array 2. Add a number 3. Find the index of a number 4. Remove number at index 5. Remove number 6. Quit 1 Enter your choice 1-6: 8 Please re-enter 1-6:2 42 1. Fill array 2. Add a number 3. Find the index of a number 4. Remove number at index 5. Remove number 6. Quit 1 Enter your choice 1-6: 2 42 54 1. Fill array 2. Add a number 3. Find the index of a number 4. Remove number at index 5. Remove number 6. Quit Enter your choice 1-6: 1 Enter number of elements 1-10:5 63 68 83 94 98 1. Fill array 2. Add a number 3. Find the index of a number 4. Remove number at index 5. Remove number 6. Quit Enter your choice 1-6:5 Enter number to remove: 99 99 is not found. 63 68 83 94 98 1. Fill array 2. Add a number 3. Find the index of a number 4. Remove number at index 5. Remove number 6. Quit Enter your choice 1-6:5 Enter number to remove: 68

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database 101

Authors: Guy Kawasaki

1st Edition

0938151525, 978-0938151524

More Books

Students also viewed these Databases questions

Question

Plan, facilitate, and participate in a business meeting.

Answered: 1 week ago

Question

Understand how environmental scanning is practised.

Answered: 1 week ago