Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I have the directions and code from the previous part here. Change isprime::operator to use a binary search instead of the linear search implemented by
I have the directions and code from the previous part here.
Change "isprime::operator" to use a binary search instead of the linear search implemented by "findO" to determine if input N is a prime number. You are encouraged to use "binary searchO" from STL to do the job. Note that this algorithm returns a boolean that indicates whether the number N was found or not. Now change the driver code in the main program. First, have it use an optional command line argument to set the number of integers to test. Call this number N. If no command line argument is present, use N-10 as the default. Seed the random number generator with N. See the "clibstd" family of functions for "srandO". Second, generate a list of N random numbers in the range 1-100. As a suggestion, write a function object for producing each random number using "randO" while letting "generate" from STL fill in the list. Feel free to represent the list using a "vector" which you may recall is an array-based sequence container. Third, use "transformO" from STL along with function object "isprime" to obtain a boolean array that indicates which random number is prime. Feed this array to "count" from STL to determine how many prime numbers there are. Print the result to stdout as shown belowStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started