Write at least two programs in two different programming languages of your choic
ID: 3594141 • Letter: W
Question
Write at least two programs in two different programming languages of your choice to implement the following string functions that will perform the operations provided in most languages such as C++. Please note that you are to write operations on character arrays/lists or strings and not rely on any built-in string library or function such as string.h or STL. You must duplicate the operations of all five of the string functions in C++ snen ccapats atring or pointer o tring as an argument. Ruthelength of hestring (not nouding thetentoExample strcat: Accepts two C-strings or pointers to two strings as arguments, The function appends the contents of the second string to the first string. Usage: len strlen(name) The first string is altered, the second string is left unchanged.) Example Usage: strcat(string1, string2); stropy: Accepts two C-strings or pointers to two strings as arguments. The function copies the second string to the first string. The second string is left unchanged. Example Usage: strcpy(string1, string2); strncpy: Accepts two C-strings or pointers to two strings characters to copy from the second string to the first string. If the string2 has fewer than n characters, string1 is padded with '10' characters. Example Usage: strncpy/string1, string2, n); stremp: Accepts two C-strings or pointers to two string arguments.If string1 and string2are the same, this function returns O. If string2 is alphabetically greater than string1, it returns a negative number. If string2 is alphabetically less than string1, it returns a positive number. Example Usage: if (strcmp string1, string2) strstr: Accepts two C-strings or pointers to two C-strings as arguments, searches for the first occurrence of string2 in string1. If an occurrence of string2 is found, the function returns a pointer to it. Otherwise, it returns a NULL pointer (address 0). Example Usage: coutExplanation / Answer
STRLEN IN PYTHON
def strLength(string):
strlen=0
for c in string:
strlen+=1
print(strlen)
string = input('Enter string: ')
strLength(string)
STRCAT IN C++
#include<iostream.h>
void strCat(char str1[25],char str2[25])
{
int i=0,j=0;
while(str1[i]!='')
i++;
while(str2[j]!='')
{
str1[i]=str2[j];
j++;
i++;
}
str1[i]='';
cout<<" Concatenated String is "<<str1;
}
int main() {
char str1[25],str2[25];
cout<<"Enter First String:";
cin>>str1;
cout<<" Enter Second String:";
cin>>str2;
strCat(str1,str2);
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.