Answered step by step
Verified Expert Solution
Link Copied!

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 count_char.
#include
#include
using namespace std;
/**
Gets the number of times the character c appears in the string.
@param str any string
@param c the single-character string to search for
@return the number of times c appears in str
*/
/* Your code goes here */
{
int count =0;
for (int i =0; i str.length(); i++)
{
if (/* Your code goes here */){ count++; }
}
return count;
}
int main()
{
string str;
string c;
getline(cin, str);
cin >> c;
cout count_char(str, c) endl;
return 0;
}
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

MFDBS 89 2nd Symposium On Mathematical Fundamentals Of Database Systems Visegrad Hungary June 26 30 1989 Proceedings

Authors: Janos Demetrovics ,Bernhard Thalheim

1989th Edition

3540512519, 978-3540512516

More Books

Students also viewed these Databases questions

Question

What is a performance baseline?

Answered: 1 week ago

Question

What are the main objectives of Inventory ?

Answered: 1 week ago

Question

Explain the various inventory management techniques in detail.

Answered: 1 week ago

Question

define the term outplacement

Answered: 1 week ago

Question

describe the services that an outplacement consultancy may provide.

Answered: 1 week ago