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

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.

1470


How is stl different from c++ standard library?

847


i wanted to know about questions about c,c++ , which is required for placements.... im a fresher

1796


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; }

2002


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

1867






What is stl in oop?

810


Write a C/C++ program to add a user to MySQL. The user should be permitted to only "INSERT" into the given database.

2202


help me i need a c++ program which takes sequesnce of characters and outputed sequence of their token taypes, work same compiler in lexical analysis phase

1985


What is the stl, standard template library?

678


Is string part of stl?

783


To modify an, existing worksheet. What steps are involved for: 1. Inserting and deleting rows and columns. 2. Printing cell formulas 3Jld displayed values 3. Using the page setup command

1867


What are the different types of stl containers?

746


what is template and type convertion

2094


Define stl.

878


Explain stl.

984