CSCI 200 - Foundational Programming Concepts & Design - Fall 2022

Lab 5C - A Needle in the Haystack

This lab is due by Tuesday, November 22, 2022 11:59 PM.
As with all labs you may, and are encouraged, to pair program a solution to this lab. If you choose to pair program a solution, be sure that you individually understand how to generate the correct solution.


Instructions


We will now see the benefit of all our sorting work.

To get started, prompt the user to enter the number of integers to store in a list. Then generate n random integers. Finally, sort the list into ascending order.

Now we'll have the user give us a target value to search for. Implement the binary search algorithm discussed in class using an iterative solution - not the recursive solution provided.

To test your implementations, perform the following steps:

  1. Ask the user how many integers to enter
  2. Ask the user for the smallest value to generate
  3. Ask the user for the largest value to generate
  4. Create a list of 10n integers (that is, if the user enters 3, then generate 30 values)
  5. Assign each element a random value within the range provided (inclusive)
  6. Print the list forwards
  7. Sort the list ascending
  8. Print the list forwards
  9. Ask the user how many target values they wish to search for
  10. For each target value entered by the user, perform an iterative binary search to find the target. If the target is found, then print the position the target first appears at. If the target is not found, then print -1.

Lab Submission


Submit your main.cpp, Makefile, *.h, *.hpp, *.cpp file(s).

You will submit your solution to this lab with the rest of Set5. Detailed instructions for doing this are posted in Assignment 5.


This lab is due by Tuesday, November 22, 2022 11:59 PM.
As with all labs you may, and are encouraged, to pair program a solution to this lab. If you choose to pair program a solution, be sure that you individually understand how to generate the correct solution.