Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Instead of counting the number of spaces in a string, it might be more useful to generalize a function so that it counts any character.
Instead of counting the number of spaces in a string, it might be more useful to generalize a function so that it counts any character. Write the function countchar.
#include
#include
using namespace std;
Gets the number of times the character c appears in the string.
@param str any string
@param c the singlecharacter string to search for
@return the number of times c appears in str
Your code goes here
int count ;
for int i ; i strlength; i
if Your code goes here count;
return count;
int main
string str;
string c;
getlinecin str;
cin c;
cout countcharstr c endl;
return ;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started