Answer:
Following are the code to the given question:
#include<iostream>//including the header file
using namespace std;
int count_Characters(char ch, string s)//defining a method count_Characters that holds two variable as a parameter
{
int c=0,i;//defining integer variable
for(i=0;i<s.size();i++)//using for loop to check value
{
if(s[i]==ch)//use if block to check string and char value
{
c=c+1;//incrementing c value
}
}
return c;//return c value
}
int main() //defining main method
{
char ch;//defining char variable
cin>>ch;//input char value
string s;//defining string variable
cin>>s;//input string value
cout<<count_Characters(ch,s);//calling method count_Characters
return 0;
}
Output:
n Nobody
0
n Monday
1
Step-by-step explanation:
In this code, a method "count_Characters" is declared that accepts one sting and one char variable as a parameter "s, ch", and inside the method a two integer variable and for loop is declared that uses the if block to match string and char value and increments the c variable value.
In the main method two-variable "s, ch" is declared that inputs the value from the user-end and pass the value into the method, and prints its values.