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

Objectives: More recursive examples Question: Write a ctt recursive functions th

ID: 3738728 • Letter: O

Question

Objectives: More recursive examples Question: Write a ctt recursive functions that performs the following: 1) A method to compute the length of the input string. Prototype: int myStrLen(char* inputString) 2) A method to copy one string to another string Prototype: void myCopyStr(char s1], char s2[], int index) Please use the provided main function(Lab19-Provided.txt) to test your recursive functions Sample output: cluserslhi2suldocumentslvisual studio 2015ProjectslProject14 DebuglProject14.exe The string to be copied is: Recursive copy The copied string str2 is: Recursive copy The input string is: Recursive String Length The length of the string 23

Explanation / Answer

#include<iostream>


using namespace std;

void myCopyStr(char s1[], char s2[], int index);
int myStrlen(char* str);

//Main driver
int main()
{
char str1[100] = "Recursive copy";
char str2[100] = "";
myCopyStr(str1, str2, 0);
cout << "The string to be copied is: " << str1 << endl;
cout << "The copied string str2 is: " << str2 << endl;

char strlen[] = "Recursive String Length";
cout << "The input string is: " << strlen << endl;
cout << "The length of the string : " << myStrlen(strlen) << endl;
  
return 0;
}
int myStrlen(char* str) {
if(*str =='') {
return 0;
} else {
return 1 + myStrlen(str+1);
}
}
void myCopyStr(char s1[], char s2[], int index) {
if(s1[index] =='') {
return;
} else {
s2[index]=s1[index];
myCopyStr(s1,s2,index+1);
}
}

Output: