5. Write c++ function that would intake a string and return
the number of occurrences of a given character in that sring
Ex:- if the word is “Colombo” and count the occurrences of
the letter “o” the function would return 3

Answer Posted / qliubrvq

occurrences(string str, char test) {
int len = str.size();
int count = 0;
for (int i = 0; i < len; i++) {
if (str[i] == test) count++;
}
return count;
}

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can we use stl in coding interviews?

1561


Name the different types of stl containers.

910


Is there any error below, its a code to delete all entires from a map #include #include iostream.h int main() { int i =0; map TestMap; while(i<3) { TesMap.insert(TestMap::value_type(i,Test)); i++; } typedef map :: iterator mapIter =TestMap.begin(); if(mapIter!=TestMap.end()) { TestMap.erase(mapItrer); ++mapIter; } return 0; }

2140


a program using one dimensional array that searches a number if it is found on the list of given input numbers given by the user and locate its exact location in the list.

1621


What are stl algorithms?

872


What is stl in oop?

948


sir please send me bpcl previous question papers

2161


Describe the My Computer and My Documents folders; identify the elements that are present in every Window.

2124


how to use C++?

2269


Who created stl?

879


please visit this site you'll find my question this is my homework please answer it if you can http://easyscience.org/ib/lofiversion/index.php/t36168.html

2016


how can u do connectivity in c++ language? plz send me connectivity code in c++ ?

2109


How does an stl file work?

886


write a program to convert a decimal number in to its equivalent binary number?

2284


What is a list in c++ stl?

900