Question

C++ programming language Write a program that contains following function: A function that receives a string...

C++ programming language

Write a program that contains following function:

A function that receives a string of character, the function returns the number of letter c's or C's in the string the function receives

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Program:

#include<iostream>
#include<string>
using namespace std;

int numberOfLetter_c_C(string str);

int main()
{
int count;
string str;
cout<<"Enter a string: ";
cin>>str;
count=numberOfLetter_c_C(str);
cout<<"The number of letter c or C in the string: "<<count;
return 0;
}

int numberOfLetter_c_C(string str)
{
int count=0;
for(int i=0;i<str.length();i++)
{
if(str[i]=='c' || str[i]=='C')
{
count++;
}
}
return count;
}

Output:

Add a comment
Know the answer?
Add Answer to:
C++ programming language Write a program that contains following function: A function that receives a string...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT