subject
Computers and Technology, 22.02.2021 19:40 Samzell

As you will solve more complex problems, you will find that searching for values in arrays becomes a crucial operation. In this part of the lab, you will input an array from the user, along with a value to search for. Your job is to write a C++ program that will look for the value, using the linear (sequential) search algorithm. In addition, you should show how many steps it took to find (or not find) the value, and indicate whether this was a best or worst case scenario (... remember the lecture). You may refer to the pseudo-code in the lecture, but remember that the details of the output and error conditions are not specified there. Also, note that in pseudo-code arrays are sometimes defined with indices 1 to N, whereas in C++ the indexes span from 0 to N-1. The program will work as follows. First, you should ask the user to enter the size of the array, by outputting:
"Enter the size of the array: "
to the console. If the user enters an incorrect size, you should output the error message:
"ERROR: you entered an incorrect value for the array size!"
and exit the program. If the input is a valid size for the array, ask the user to enter the data, by outputting
"Enter the numbers in the array, separated by a space, and press enter: "
Let the user enter the numbers of the array and store them into a C++ array. Up to now, this should be exactly the same code as Lab#2. Next, ask the user a value v to search for in the array (called the "key"), by outputting:
"Enter a number to search for in the array: " to the screen, and read the key v.
Search for v by using the linear search algorithm. If your program finds the key, you should output:
"Found value v at index i, which took x checks. "
where i is the index of the array where v is found, and x is the number of search operations taken place.
If you doesn't find the key, then output: "
The value v was not found in the array!"
Then indicate whether you happened to run into a best or worst case scenario. In case you did, output: "
We ran into the best case scenario!" or "We ran into the worst case scenario!"
otherwise, don't output anything.

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 11:30
Write a function so that the main program below can be replaced by the simpler code that calls function original main program: miles_per_hour = float( minutes_traveled = float( hours_traveled = minutes_traveled / 60.0 miles_traveled = hours_traveled * miles_per_hour print('miles: %f' % miles_traveled) sample output with inputs: 70.0 100.0 miles: 116.666667
Answers: 3
question
Computers and Technology, 22.06.2019 16:00
You have inserted new slides based on a word outline. how do you format these new slides to match the powerpoint presentation formatting? a. select all slides in the presentation and click format on the home tab. b. select the new slides and click reset on the home tab. c. select all slides in the presentation and click reset on the home tab. d. select the new slides and click format on the home tab.
Answers: 3
question
Computers and Technology, 22.06.2019 20:00
What side length would you specify if you were required to create a regular hexagonal plate that was composed of 33 cm(squared) of sheet metal? dimension the side length to 0.1 cm
Answers: 2
question
Computers and Technology, 23.06.2019 08:00
The managing director of a company sends a christmas greeting to all his employees through the company email. which type of network does he use? he uses an .
Answers: 3
You know the right answer?
As you will solve more complex problems, you will find that searching for values in arrays becomes a...
Questions
question
Mathematics, 06.07.2019 12:00
question
English, 06.07.2019 12:00
question
Mathematics, 06.07.2019 12:00