Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

*Please utilize C++ format when answering questions 17. Write a function named h

ID: 3626489 • Letter: #

Question

*Please utilize C++ format when answering questions

17. Write a function named how_many_subs that has a single vector parameter (vector of strings) and a single string parameter. The function should return the number of times a string in the vector parameter starts with the exact characters in the string parameter (the 2nd parameter).

For example, when the function is called, if the vector argument holds the 5 string values, "woops", "wood", "wildwooly", "woo", "wonder"
and the string argument passed in has the value
"woo" then the function should return the count 3 because 3 strings in the vector started with the substring "woo". ("woops", "wood", "woo")
Recall that the string class has a member function named substr that takes 2 arguments, the start position and the length of a substring within the string, and returns that substring.
18. Write a test harness that tests the how_many_subs function you wrote for the previous question. This must be a complete program, including all necessary include directives and using statements.
To get all 10 points for this question, your test harness (main function) must be thorough.
This test harness must be capable of finding ALL potential errors in the logic of the
how_many_subs function (regardless of whether you actually have the logic errors in your definition). A good strategy would be to write a test harness for testing someone else's implementation of the how_many_subs function.

Explanation / Answer

#include<iostream>
#include<string>
#include<vector>
using namespace std;
int count(vector<string>& v,string& st)
{
int temp=0;
for(int i=0; i<v.size(); i++)
{
if(v[i].find(st)) temp++;
}
return temp;
}
int main()
{
string st="woo";
string a[] = {"woops", "wood", "wildwooly", "woo", "wonder"};
vector<string> v(a,a+5);
cout<< count(v,st);
return 0;
}