Coding should be in C Modify secondVerse to play The Name Ga

Coding should be in C++

Modify secondVerse to play \"The Name Game\" (a.k.a.\"The Banana Song\", see Wikipedia.org), by replacing \"(Name)\" with userName but without the first letter. Ex: if userName = \"Katie\", the program prints: Banana-fana fo-fatie! #include #include using namespace std; int main() {string secondVerse = \"Banana-fana fo-f(Name)!\"; string userName = \"Katie\"; userName.erase(userName.begin());//Removes first char from userName/* Your solution goes here */secondVerse=secondVerse.substr(theta, secondVerse.length()-7); secondVerse += userName += \"!\";| cout

Solution

#include <iostream>

using namespace std;

int main()
{
string secondVerse = \"Banana-fana fo-f(Name)!!!\";
string userName = \"Katie\";
userName.erase(userName.begin());
string replaceString = \"(Name)\";
int index = secondVerse.find(\")\");
string lastChar = secondVerse.substr(index+1,secondVerse.length()-1);
secondVerse = secondVerse.replace(secondVerse.find(\"(\")+1,secondVerse.find(\")\"), \"\");

secondVerse = secondVerse.substr(0,secondVerse.length()-1);
secondVerse = secondVerse + userName+lastChar;
cout<<secondVerse<<endl;
return 0;
}

Output:

sh-4.3$ g++ -std=c++11 -o main *.cpp                                                                                                                                                                                            

sh-4.3$ main                                                                                                                                                                                                                    

Banana-fana fo-fatie!!!

Coding should be in C++ Modify secondVerse to play \

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site