3. Function One: spliceString Specification The first function you will write sh
ID: 3736225 • Letter: 3
Question
3. Function One: spliceString Specification The first function you will write should be called 'splicestring'. Your function should take three (3) arguments. The first argument is a string (string one). The second argument is a string (string two). The third argument is an integer (n). The function should return one (1) string. The returned string should be the nth character from string one concatenated with the nth to final characters of string two. Remember, we start counting at 0! For this function, you may assume that both string one and string two have at least n+2 characters. Example Test Case spliceString ('Caitlen', The Builder', 3) returns t Builder Page 2 of 4Explanation / Answer
The below code exactly gives you the return as "t Builder"
#include <iostream>
#include <string>
using namespace std;
string SpliceString(string str1, string str2, int nth)
{
std::string str4 = str1.substr(nth,1);
std::string str3 = str2.substr(nth, str2.length());
return str4 + ' ' + str3;
}
int main()
{
string str5 = SpliceString("Caitlen", "The Builder", 3);
cout<<str5;
return 0;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.