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

You will write 2 functions: int cstrcat(char dst[], char src[]) which concatenat

ID: 3607617 • Letter: Y

Question

You will write 2 functions:

int cstrcat(char dst[], char src[])
which concatenates the char array src[] to char array dst[], and returns the new length of the dst[], not counting the null terminator character.
You may assume dst[] was declared large enough to handle the combined length.
Write the loop to do the copy, do NOT make calls to C-string library functions.

bool cstrcmp(char s[], char t[])
which compares the char array s[] to char array t[], and returns true if the strings are identical.
Write the loop to do the compare, do NOT make calls to C-string library functions. Be sure you don't compare past the end of either string.

Your main() program should:

(1) Prompt the user to enter 2 strings, and save into 2 char[80] arrays using cin.getline(). Assume the user will enter less than 30 characters for each string.(1 pt)

Ex:

(2) Use the cstrcmp() function to determine if they are equal, and print out a statement (1pt):
Ex:

(3) Call the cstrcat() function to append the 2nd string to the first, then print out the new longer string and its length (1 pt):
Ex:

This is C++ Pease check for using Visual studio

Explanation / Answer

#include <iostream>
#include <cmath>
#include <cstring>
using namespace std;
int cstrcat(char dst[], char src[]) {
int i=0;
for(i=0;dst[i]!='';i++) {
}
for(int j=0;src[j]!='';j++) {
dst[i++]=src[j];
}
dst[i]='';
return i-1;
}
bool cstrcmp(char s[], char t[]) {
for(int i=0;s[i]!='';i++) {
if(s[i] != t[i]) {
return false;
}
}
return true;
}
int main()
{
char s1[100], s2[100];
cout << "Enter 2 strings:" << endl;
cin.getline(s1, 100);
cin.getline(s2, 100);
if(cstrcmp(s1,s2)) {
cout<<"The strings are equal."<<endl;
} else {
cout<<"The strings are NOT equal."<<endl;
}
int count = cstrcat(s1,s2);
cout<<"Concatenated string: "<<s1<<endl;
cout<<"Length: "<<count<<endl;
return 0;

}

Output:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote