Need help with the following: Complete the function to replace any period by an
ID: 3689112 • Letter: N
Question
Need help with the following: Complete the function to replace any period by an exclamation point. Ex: "Hello. I'm Miley. Nice to meet you." becomes: "Hello! I'm Miley! Nice to meet you!" #include #include using namespace std; void MakeSentenceExcited(char* sentenceText) { /* Your solution goes here */ } int main() { const int TEST_STR_SIZE = 50; char testStr[TEST_STR_SIZE]; strcpy(testStr, "Hello. I'm Miley. Nice to meet you."); MakeSentenceExcited(testStr); cout << testStr << endl; return 0; }
Explanation / Answer
#include <iostream>
#include <cstring>
using namespace std;
void MakeSentenceExcited(char* sentenceText)
{
for(int i=0;sentenceText[i]!='';i++)
{
if(sentenceText[i]=='.')
{
sentenceText[i]='!';
}
}
return;
}
int main()
{
const int TEST_STR_SIZE = 50;
char testStr[TEST_STR_SIZE];
strcpy(testStr, "Hello. I'm Miley. Nice to meet you.");
MakeSentenceExcited(testStr);
cout << testStr << endl;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.