subject

// Binary String Search and Selection Sort #include
#include
using namespace std;
// Function prototypes
void selectionSort(string[], int);
void displayArray(string[], int);
int binarySearch(string[], int, string);
int main()
{
const int NUM_NAMES = 20;
string search;
string names[NUM_NAMES] = { "Collins, Bill", "Smith, Bart", "Allen, Jim",
"Griffin, Jim", "Stamey, Marty", "Rose, Geri",
"Taylor, Terri", "Johnson, Jill",
"Allison, Jeff", "Looney, Joe", "Wolfe, Bill",
"James, Jean", "Weaver, Jim", "Pore, Bob",
"Rutherford, Greg", "Javens, Renee",
"Harrison, Rose", "Setzer, Cathy",
"Pike, Gordon", "Holland, Beth" };
// Sort the array.
selectionSort(names, NUM_NAMES);
// Display the sorted array.
cout << "Here are the names sorted:\n";
cout << "\n";
displayArray(names, NUM_NAMES);
// Get a name to search for.
cout << "Enter a name to search for: ";
getline(cin, search);
// Search for the name.
int results = binarySearch(names, NUM_NAMES, search);
// If results contains -1 the string was not found.
if (results == -1)
cout << "That names does not exist in the array.\n";
else
{
// Otherwise results contains the subscript of
// the specified name in the array.
cout << "That name is found at element " << results;
cout << " in the array.\n";
}

return 0;
}
//
// The selectionSort function performs an ascending order *
// selection sort on an array of strings. The size *
// parameter is the number of elements in the array. *
//
void selectionSort(string values[], int size)
{
int startScan;
int minIndex;
string minValue;
for (startScan = 0; startScan < (size - 1); startScan++)
{
minIndex = startScan;
minValue = values[minIndex];
// key fill in the index bounds
for (int index = key; index < key; index++)
{
// key what operator?
if (values[index] key minValue)
{
minValue = values[index];
minIndex = index;
}
}

values[minIndex] = values[startScan];
values[startScan] = minValue;
}
}
//
// The displayArray function displays the contents of *
// the array. *
//
void displayArray(string values[], int size)
{
for (int i = 0; i < size; i++)
cout << values[i] << endl;
}
//
// The binarySearch function performs a binary search on *
// an array of strings. array, which has a maximum of *
// size elements, is searched for the string stored in *
// value. If the string is found, its array subscript is *
// returned. Otherwise, -1 is returned indicating the *
// string was not in the array. *
//
int binarySearch(string values[], int size, string value)
{
bool found = false; // Flag, initialized to false.
int first = 0; // To hold the first array element
int middle; // To hold the mid point of search
int last = size - 1; // To hold the last array element
int position = -1; // To hold the position of search value
while (!found && first <= last)
{
// Calculate the mid point.
// key
middle = key
// Determine if the value is found at the mid point.
if (values[middle] == value)
{
position = middle;
found = true;
}
// Determine if the value is in the lower half.
// key add the comparison operator here
else if (values[middle] key value)
// key
last = key
// Determine if the value is in the upper half.
else
// key
first = key
}
return position;
}
complete the marked key

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 21.06.2019 13:30
What are the main arguments/points presented in the video about consciousness? present your opinion about the arguments. do you agree with all points? feel free to offer you personal reflections about the video?
Answers: 1
question
Computers and Technology, 23.06.2019 00:30
Which one of the following is the most accurate definition of technology? a electronic tools that improve functionality b electronic tools that provide entertainment or practical value c any type of tool that serves a practical function d any type of tool that enhances communication
Answers: 1
question
Computers and Technology, 23.06.2019 03:30
Hashtags serve to identify the topic of a given tweet true false
Answers: 2
question
Computers and Technology, 23.06.2019 08:30
All of these are true about using adhesive except: a. dissimilar materials can be joined. b. mixing tips are product and material specific. c. a specific application gun may be required. d. two-part adhesives are dispensed using two mixing tips
Answers: 3
You know the right answer?
// Binary String Search and Selection Sort #include
#include
using namespace std;
Questions
question
Mathematics, 22.01.2020 04:31
question
Chemistry, 22.01.2020 04:31