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 return true if the string contains letter c or C, otherwise, return false.

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

c++ code:

#include <iostream>
#include <string>

using namespace std;

//function returns true, if c/C found
bool characterFound(string str)
{
//check all characters in the string
for(int i=0;i<str.length();i++){
if(str[i]=='c' || str[i]=='C')
return true; //true if found
}
//false if no c/C found
return false;
}

int main()
{
string str;

//prompt for string
cout<<"Enter string: ";
cin>>str;

//call function and print the result
if(characterFound(str))
cout << "string contains letter c or C." << endl;
else
cout << "string does not contain letter c or C" << endl;

return 0;
}

output:

LIPUUalu l laye TUUIS Jilapes CUIUIS - O X C:\Users\NIROSHINI\Documents\CPPFiles\characterFound\bin\Debug\characterFound.exe

//for any clarification please do comments. if you found this solution useful, please give me thumbs up

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