Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In this fourth part of the signature assignment, code is developed for sorting and searching using a binary search algorithm. Write a function named selection
In this fourth part of the signature assignment, code is developed for sorting and searching using a binary search algorithm.
Write a function named selectionsort, which takes two parameters: an integer pointer and an integer size. Search the Internet or consult a textbook for an example of selection sort. Add code to implement a selection sort algorithm. Add any needed functions to support the selection sort. The function should sort the array in place and return nothing.
Write a recursive function named binarysearchrecursive, which takes four parameters from a helper function. The first is an integer pointer representing the array of values, the second is an integer representing the value to be searched for, the third is an integer for the starting index, and the fourth is an integer for the ending index. The function returns a Boolean value representing if the searchedfor value was found.
Write a helper function named binarysearch that takes three parameters: the first is a pointer to an integer array, the second is the array size, and the third is a searchedfor value. This function calls the recursive function and passes the array, the search value, the starting index, and the ending index; remember, the size and the ending index are related but not equivalent. The function returns the Boolean value returned by the recursive search function.
Add a new class named SearchAnalyzer, which subclasses Analyzer and implements the analyze method. Use the override keyword appropriately. The constructor should first initialize the base class by calling the Analyzer constructor, then in the constructor body, call the selectionsort function, passing the instance variable values and the size do not pass the parameter values and size! In the analyze method, generate random integer values from to and use the binarysearch function to see if that value exists in the data. Count the number of found values and return the count in a std::string.
Modify the StatisticsAnalyzer constructor to call the selectionsort function, passing it the correct argument values. Alter the minimum and maximum values computation, considering the array is now sorted. Add functionality to implement the median and mode averages using the sorted data. The median is the exact middle value if there is an odd number of elements, and the mean of the two middle values is if there is an even number of elements. The mode is the most frequently occurring value; if more than one value occurs with this frequency, pick the first one.
The final main function should look like this:
const int SIZE ;
int main
createBinaryFilebinarydat", SIZE;
BinaryReader brbinarydat";
StatisticsAnalyzer sabrgetValues brgetSize;
std::cout saanalyze
;
DuplicateAnalyzer dabrgetValues brgetSize;
std::cout daanalyze
;
MissingAnalyzer mabrgetValues brgetSize;
std::cout maanalyze
;
SearchAnalyzer rabrgetValues brgetSize;
std::cout raanalyze
;
return ;
Use these function and class headers:
class SearchAnalyzer : public Analyzer
SearchAnalyzerint values, int size
std::string analyze override
void selectionsortint values, int size
bool binarysearchrecursiveint values, int key, int start, int end
bool binarysearchint values, int size, int key
Example output:
The minimum value is
The maximum value is
The mean value is
The median value is
The mode value is which occurred times
There were duplicated values
There were missing values
There were random values found
Step 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