Answered! # include # include using namespace std: int main () { string secondVerse = "Banana -fana fo -f(Name)!": string…

e song verse dy change, suc as. Banana-land lo Nall 1 ilinclude Kiostrean 2 include <string> 3 using name space std; 5 int main() 6 string secondverse Banana-fana fo-f(Name) string userName Katie 9 user Name erase (userName-begin()); Removes first char from userName 10 11 12 string replacestring Name 13 Verse secondverse.replace(secondverse.find (replacestring) replace string-length() 14 char last Char secondverselsecondverse.length()-1] 15 Second Verse secondverse substr(e,secondverse.lengthO-1) 16 Second Verse Second Verse user Name lastChar 17 cout Second Verse endl. 19 20 return e; 21 Run v Testing Katie Your output Banana-fana fo-fatie Testing Walter Banana-fana fo-falter Your output. x Testing Katie and ending with instead of Expected output Banana-fana fo-fatie Your output Banana-fana fo-f atie

Using C++. What am I missing???

# include # include using namespace std: int main () { string secondVerse = “Banana -fana fo -f(Name)!”: string username = ” Katie”: username. Erase (username = “(Name)”: secondverse = secondverse .replace(secondVerse. Find (replaceString), replaceString. Length(),” “): char lastchar = secondVerse.[secondVerse.length() -1): secondVerse = secondVerse.substr (theta, secondVerse.length ()-1): secondVerse = secondVerse + username + lastChar: cout

Expert Answer

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

int main()
{
string secondVerse = “Banana-fana fo-f(Name)!!!”;
string userName = “Walter”;

userName.erase(userName.begin());

string replaceString = “(Name)”;

int idx = secondVerse.find(“!”); //taking the index of where ‘!’ begins

string symbols = secondVerse.substr(idx, secondVerse.length()-1); //storing the ‘!’ from begin till end

secondVerse = secondVerse.replace(secondVerse.find(replaceString), replaceString.length(), “”);
idx = secondVerse.find(“!”); //again finding index of ‘!’ in updated secondVerse
secondVerse = secondVerse.substr(0, secondVerse.length()-(secondVerse.length()-idx));   //updating secondVerse till it found ‘!’
secondVerse = secondVerse + userName + symbols;

cout << secondVerse << endl;
return 0;
}

Still stressed from student homework?
Get quality assistance from academic writers!