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
Who developed the Great Compromise ​
Nostrana [21]

Answer:

Roger Sherman

The solution came in the form of a compromise proposed by statesmen Roger Sherman and Oliver Ellsworth of Connecticut. The Great Compromise created two legislative bodies in Congress.

Explanation:

comment how it helps

7 0
2 years ago
A___________is a collection of computer software, typically malicious, designed to enable access to a computer or an area of its
Molodets [167]

Answer: rootkit

Explanation:

Hi, A rootkit is a collection of computer software, typically malicious, designed to enable access to a computer or an area of its software that is not otherwise allowed (for example, to an unauthorized user) and often masks its existence or the existence of other software.

A rootkit provides continued privileged access to a computer while hiding its presence. Because of this hiding characteristic it is very difficult to detect.

Once a rootkit has been installed, it allows someone to have total remote control of a computer and do things such as files executions and system changes.

4 0
3 years ago
Given that it takes 0.08 ms to travel from one track to the next of a hard drive; that the arm is originally positioned at Track
daser333 [38]

Answer:

Time taken to travel from one track to the next = 0.08ms

Initial track= 15     0

4      (15-4)*(0.08)= 0.88

40     (40-4)*(0.08)= 2.88

35      (40-35)*(0.08)= 0.4

11       (35-11)*(0.08)= 1.92

14       (14-11)*(0.08)= 0.24

7         (14-7)*(0.08)= 0.56

----------------------------------------------

Total seek time=0.88+2.88+0.4+1.92+0.24+0.56=6.88ms

Explanation:

We caculate the seek time for each request, and then add them together to find the total seek time. The final track number for the current request becomes the current track of next request, and this process is repeated till the last request is processed.

4 0
3 years ago
Write a program in C++ to Find the Average of the sum of prime numbers between 1 to any given number
mixas84 [53]

Using the knowledge in computational language in C++ it is possible to write a code that Find the Average of the sum of prime numbers between 1 to any given number

<h3>Writting in C++ code:</h3>

<em />

<em>#include <iostream></em>

<em>using namespace std;</em>

<em>bool isPrime(int n){</em>

<em>   for(int i = 2; i < n/2; i++){</em>

<em>      if(n%i == 0){</em>

<em>         return false;</em>

<em>      }</em>

<em>   }</em>

<em>   return true;</em>

<em>}</em>

<em>int findPrimeSum(int n){</em>

<em>   int sumVal = 0;</em>

<em>   for(float i = 2; i <= n; i++){</em>

<em>      if(isPrime(i))</em>

<em>         sumVal += i;</em>

<em>   }</em>

<em>   return sumVal;</em>

<em>}</em>

<em>int main(){</em>

<em>   int n = 15;</em>

<em>   cout<<"The sum of prime number between 1 to "<<n<<" is "<<findPrimeSum(n);</em>

<em>   return 0;</em>

<em>}</em>

See more about C++ code at brainly.com/question/19705654

#SPJ1

8 0
1 year ago
Which term is used to describe a network security device or host software that filters communications, usually network traffic,
morpeh [17]

Answer:

The correct answer is option (D).

Explanation:

According to the scenario, the most appropriate answer is option (D) because the firewall can be defined as the software program which checks through the network for incoming and outgoing communication on predefined rules.

while the other options are wrong because of the following reasons :

  • A sniffer can be defined as the program which is used to check the network traffic but it didn't work on predefined rules.
  • An auditor can be defined as a program that is used to analyze the network.
  • The hacker can be a person who hacks the system to gain access or gather information.
4 0
3 years ago
Other questions:
  • How many buttons does a gamecube controller have?
    7·1 answer
  • List and describe three options in the autocad object snap toolbar
    8·1 answer
  • _______ view focuses on the text and content of a document, without much information on the page layout.
    7·1 answer
  • ________ is a dedicated device designed to manage encrypted connections established over an untrusted network such as the Intern
    12·1 answer
  • IF YOU PLAY SURVIV&gt;IO WITH ME RIGHT NOW I WILL GIVE YOU BRAINLIEST<br> AND IM NOT KAPPING
    5·1 answer
  • Ana is a music lover. She loves to download songs and videos on her computer every time she hears a new song. One day, her compu
    14·1 answer
  • Jenn wants to assign a value to the favorite car variable: favoriteCar = Toyota but gets an error message. What does she need to
    11·1 answer
  • "Rights and duties are two sides of the same coin." Explain with examples​
    5·1 answer
  • Disadvantages assembly level language for programming ​
    10·2 answers
  • he primary purpose of a database query is to a. find and retrieve specific information. b. correct information in the database.
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!