1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
melomori [17]
3 years ago
7

Write a program that sorts a vector of names alphabetically using the selection sort and then searches the vector for a specific

name using binary search. To do that, you need to write three functions: 1. void selSort (vector & v): sorts the vector using selection sort 2. void display (const vector & v): displays the vector contents 3. int binSearch (const vector & v, string key): searches the vector for a key, returns the index of the key if found and -1 if the index is not found
Computers and Technology
1 answer:
Natalka [10]3 years ago
7 0

Answer:

See Explaination

Explanation:

#include <iostream>

#include <iomanip>

#include <vector>

using namespace std;

// Function Declarations

void display(vector<string> names);

void selectionSort(vector<string>& names);

int binarySearch(vector<string> names, string name);

int main()

{

string search;

vector<string> names{ "Joe Garcia", "Amelia Perez", "Bob Haynes", "Tim Ducrest", "Kevin Garcia", "Suzy Walter", "Fang Yi", "Robert James", "Mary Andres" };

cout << "__Displaying names before sort__" << endl;

display(names);

selectionSort(names);

cout << "__Displaying names after sort__" << endl;

display(names);

search = "Kevin Garcia";

int b1 = binarySearch(names, search);

if (b1 != -1) {

cout << search << " is found in the vector" << endl;

}

else {

cout << search << " is not found in the vector" << endl;

}

search = "Joe James";

b1 = binarySearch(names, search);

if (b1 != -1) {

cout << search << " is found in the vector" << endl;

}

else {

cout << search << " is not found in the vector" << endl;

}

return 0;

}

//This function will the Vector elements

void display(vector<string> names)

{

for (int i = 0; i < names.size(); i++) {

cout << names[i] << endl;

}

}

//This function will sort the Vector in ascending order

void selectionSort(vector<string>& names)

{

int start;

string temp;

for (int i = names.size() - 1; i > 0; --i) {

start = 0;

for (int j = 1; j <= i; ++j) {

if (names[j].compare(names[start]) > 0) {

start = j;

}

temp = names[start];

names[start] = names[i];

names[i] = temp;

}

}

}

//This function will search for a string in vector

int binarySearch(vector<string> names, string name)

{

int first = 0,

last = names.size() - 1,

middle,

position = -1;

bool found = false;

while (!found && first <= last)

{

middle = (first + last) / 2;

if (names[middle] == name)

{

found = true;

position = middle;

}

else if (names[middle] > name)

last = middle - 1;

else

first = middle + 1;

}

return position;

}

You might be interested in
your teacher has accidentally put the wrong names of the students on her excel science results sheet. What method can be used to
Shtirlitz [24]

Answer:

Explanation:

Excel has a built-in function that allows you to type in a word, letter, or number and it will automatically find every one of that entry and replace it with whatever you want. To do this you simply click on Home > Find & Select > Replace and fill out the information. Once the info is completed click Replace All. This shows exactly why it is way better to do these result sheets on the computer as opposed to on a piece of paper, it allows you to automate everything and fix multiple mistakes with a simple button click.

6 0
2 years ago
A computer record is used to store all the information about one transaction, but several such records must be used to store the
never [62]

Answer:

True

Explanation:

A single file can be used to record/ store all the information regarding a transaction because in a transaction there are less complexities. a  simple transaction involves an exchange/communication between a buyer and a seller which involves exchange in finances between the buyer and the seller.  

An employee can be involved in several activities like work activities and multiple transactions while a single inventory part record is different from an employee's record and  any other form of transaction. hence separate files have to be created for each of these activities.

To have an easy access to this information when needed a master file is created to store all the individual files.

7 0
2 years ago
It needs to be as simple as possible. Each question is slightly different.1. An arithmetic progression is a sequence of numbers
madam [21]

Answer

can we get a picture of the problem ?

Explanation:

4 0
2 years ago
What is communication barriers?​
SSSSS [86.1K]

Answer:

A communication barrier is anything that prevents us from receiving and understanding the messages others use to convey their information, ideas and thoughts.They can interfere with or block the message you are trying to send.

7 0
2 years ago
Read 2 more answers
Jakob is stuck in the airport on a long layover while traveling for work. He sees two Wi-Fi’s he can log onto: one says Airport
Andrei [34K]
You should pick Free Airport Wifi bc its free
3 0
3 years ago
Read 2 more answers
Other questions:
  • (011001111)2=(?)10 can anyone solve this urgent <br><br> Hurry
    11·2 answers
  • Which of the following is an example of a consumer service? computer builder motorcycle manufacturer cabinet maker air condition
    15·2 answers
  • A short-circuit evaluation is where each part of an expression is evaluated only as far as necessary to determine whether the en
    14·1 answer
  • Given two Generic variables, A with value "123" and B with value 456, what would the Write Line output of A + B be? 123456 579 A
    5·1 answer
  • When subjects are given two drinks but not told what they are drinking in order to get accurate results on which is the better t
    6·1 answer
  • Complete the second clause of the following Prolog program for member/2 where member(X, Y) checks whether X is an element (a mem
    7·1 answer
  • List all the steps used to search for 25 in the sequence given below. Use both (a) linear search and (b) binary search. 2, 7, 13
    7·1 answer
  • You can't cite Wikipedia, what are three ways that you can use it for your research?
    5·1 answer
  • Your friends are having difficulties with their computer setups. Can you suggest a way to help each friend?
    5·1 answer
  • Complete the following sentence.
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!