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



5. Write c++ function that would intake a string and return the number of occurrences of a given ch..

Answer / 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

More STL Interview Questions

write a piece of c++ code which allocate memory to the 50 object of type CObj

2 Answers  


What are stl algorithms?

1 Answers  


How is stl different from c++ standard library?

1 Answers  


If P is the population on the first day of the year, B is the birth rate, and D is the death rate, the estimated population at the end of the year is given by the formula: The population growth rate is given by the formula: B – D Write a program that prompts the user to enter the starting population, birth and death rates, and n, the number of years. The program should then calculate and print the estimated population after n years. Your program must have at least the following functions: 1. growthRate: This function takes its parameters the birth and death rates, and it returns the population growth rate. 2. estimatedPopulation: This function takes its parameters the current population, population growth rate, and n, the number of years. It returns the estimated population after n years Your program should not accept a negative birth rate, negative death rate, or a population less than 2. please answer my question ....

1 Answers   Microsoft,


Write a program in C/C++ to implement reader- writer problem

1 Answers   Wipro,


What Is Operator Overloading in C++?

3 Answers  


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

1 Answers  


Write a program to print the swapping in two no and using three variable.

5 Answers   Broadridge,


write a c++ program to create an object of a class called employee containing the employee code name designation basic salarry HRA Da gross salary as data 10 such objects "members process "

1 Answers  


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

1 Answers  


how to get the sum of two integers?

2 Answers  


differentiate between private, public and protected data members of the class using example.

1 Answers  


Categories