Computers and Technology

// 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

answer
Answers: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 10:30, dreyes439
You are almost finished updating a web site. as part of the update, you have converted all pages from html 4.0 to html5. the project is currently on schedule. however, your project manager has been asked by the marketing team manager to justify a day of time spent validating the site's html5 pages. the marketing team manager does not have technical knowledge of the internet or the web. which is the most appropriate explanation to provide to the marketing team manager?
Answers: 1
image
Computers and Technology, 22.06.2019 23:00, brooklynmikestovgphx
Suppose s, t, and w are strings that have already been created inside main. write a statement or statements, to be added to main, that will determine if the lengths of the three strings are in order by length, smallest to largest. that is, your code should determine if s is strictly shorter than t, and if t is strictly shorter than w. if these conditions hold your code should print (the boolean value) true. if not, your code should print false. (strictly means: no ties) example: if s, t, and w are "cat", "hats", and "skies" your code should print true - their lengths are 3-4-5; but if s, t, and w are "cats" "shirt", and "trust", then print false - their lengths are 4-5-5 enter your code in the box below
Answers: 2
image
Computers and Technology, 23.06.2019 22:40, azariah7
22. sata3 allows for data transfer rates of 600 mb/s. explain why you would likely not be able to copy data from one hard drive to another at anywhere close to this speed. also, what could be upgraded on the computer to achieve transfer speeds closer to 600 mb/s
Answers: 1
image
Computers and Technology, 24.06.2019 02:10, ttangelique
Which sentences describe the things you need to ensure while creating a sketch and a drawing? while an artistic or creative drawing is a creative expression, a technical drawing is an informative expression. you need to create accurate and neat drawings to convey accurate information. a technical drawing clearly conveys its meaning or information, and does not leave room for interpretation maintain a good speed while creating drawings
Answers: 1
Do you know the correct answer?
// Binary String Search and Selection Sort #include
#include
using namespace std;

Questions in other subjects:

Konu
Mathematics, 01.07.2019 09:00