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

what is template and type convertion

1999


What are the symptoms of stl?

607


What is a standard template library (stl)? What are the various types of stl containers?

674


Who created stl?

656


What is stl stack?

665






Why should a c++ programmer be interested in stl?

647


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

1885


Do you like to Submit Questions in Bulk under Same Category?? Then use our Bulk ListerDo you like to Submit Questions in Bulk under Same Category?? Then use our Bulk Lister

1664


How connect plc and pc through software

1923


What is the stl, standard template library?

600


What is meant by stl in c++?

657


How stl is different from the c++ standard library?

643


Describe how to safeguard a system through acquisition of an antivirus Program and systematic backup.

1646


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

1896


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

2097