Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Coding should be in C++ Modify secondVerse to play \"The Name Game\" (a.k.a.\"Th

ID: 3925248 • Letter: C

Question

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

Explanation / Answer

#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!!!

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote