Write a C++ function implode that receives a vector of strings and a delimiter s
ID: 3800697 • Letter: W
Question
Write a C++ function implode that receives a vector of strings and a delimiter string. This function returns a single string that is the elements of the vector together with the delimiter string between each element. For example, suppose vector v contains elements {"Mary", "Bob", "Joe"}, then implode (v, ", ") will return string "Mary. Bob, Joe". Write a function filter.odd that receives a source vector of integer values and returns a vector containing the odd values from the source vector (in the same order as in the source vector). For example, if the source vector is {12, 19, 13, 16, 7}, the returned result vector would contain {19, 13, 7}. Note that the source must not be modified by this function.Explanation / Answer
(b)
string implode(vector<string> v,string s)
{
string temp = "";
for(int i=0;i<v.size();i++)
{
temp += v[i];
if(i != v.size()-1)
{
temp += s;
}
}
return temp;
}
Open the below link for complete code i have written incase you have any doubts, u can run it in that link.
http://ideone.com/90W1vt
------------------------------------------------------------------------
(c)
vector<int> filter_odd(const vector<int> v)
{
vector<int> result;
for(int i=0;i<v.size();i++)
{
if(v[i]%2 != 0 ) // checking if it is an odd or even element
{
result.push_back(v[i]);
}
}
return result;
}
Open the below link for complete code i have written incase you have any doubts, u can run it in that link.
http://ideone.com/kpF0yX
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.