68 774
Assignments Done
98,8%
Successfully Done
In January 2019

# Answer to Question #63742 in C++ for William CE Clark

Question #63742
2. Write a printVector function which takes a vector and prints the contents of the vector.
3. Write a main function that create a vector of integers called grades with contents {100, 95, 87, 92, 79}. Then it prompts the user to enter a number and searches the array for that number. If the number is in the vector, it prints out to the user the position it found it at. If the number is not in the vector, it prints out that it did not find it and prints the contents of the vector using printVector.
#include <vector>
#include <iostream>

void printVector(std::vector<int> input_vector)
{
for (int i = 0; i < input_vector.size(); i++) {
std::cout << input_vector[i] << " ";
}
std::cout << std::endl;
}

int main()
{
std::vector<int> grades = { 100, 95, 87, 92, 79 };
int searching_number;
std::cout << "Please, enter a number to search:\n";
std::cin >> searching_number;
bool in_vector = false;
int i;
for (i = 0; i < grades.size(); i++) {
if (grades[i] == searching_number) { in_vector = true; break; }
}
if (in_vector) std::cout << "Searching number position: " << i << std::endl;
else {
std::cout << "Serching number isn't found.\n";
}
system("pause");
return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!