Question: Write a c++ recursive functions that performs the following: 1) A meth
ID: 3738741 • Letter: Q
Question
Question: Write a c++ 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 sl[, char s211, int index) Please use the provided main function(Lab19-Provided.txt) to test your recursive functions Sample output: clusers hi2suldocumentslvisual studio 20151ProjectslProject14DebuglProject14.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 string23Explanation / Answer
#include<iostream>
using namespace std;
void myStrcopy(char s1[], char s2[], int index);
int myStrlen(char* str);
//Main driver
int main()
{
char str1[100] = "Recursive copy";
char str2[100] = "";
myStrcopy(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 myStrcopy(char s1[], char s2[], int index) {
if(s1[index] =='') {
return;
} else {
s2[index]=s1[index];
myStrcopy(s1,s2,index+1);
}
}
Output:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.