Homework Solution: I need help with this C++ program. I need to implement the following functions, but I'm having prob…

    I need help with this C++ program. I need to implement the following functions, but I'm having problemds usinf the necessary a and b arrays. #include <iostream> // // Copies the C string pointed by source into the array pointed by destination, // including the terminating character (and stopping at that point). // To avoid overflows, the size of the array pointed by destination shall be long enough to contain // the same C string as source (including the terminating null character), and should not overlap // in memory w/ source. char* strcpy_(char* q, const char* p) {   // fill in code here   unsigned i; for ( i=0; p[i] != ''; ++i ) q[i] = p[i];   return q;     } // Copies the first num characters of source to destination. If the end of the source C string (which is signaled // by a null-character) is found before num characters have been copied, destination is padded with zeros char* strncpy_(char* q, const char* p, size_t n) { // fill in code here } // Returns the length of the C string str. // The length of a C string is determined by the terminating null-character: A C string is as long as the number of characters // between the beginning of the string and the terminating null character (without including the terminating null character itself). // size_t strlen_(const char* p) { // fill in code here } // Appends a copy of the source string to the destination string. The terminating null character in destination // is overwritten by the first character of source, and a null-character is included at the end of the new string formed // by the concatenation of both in destination. destination and source shall not overlap. char* strcat_(char* s, const char* ct) { // fill in code here } // Compares the C string str1 to the C string str2. // This function starts comparing the first character of each string. If they are equal to each other, // it continues with the following pairs until the characters differ or until a terminating null-character is reached. // int strcmp_(const char* p, const char* q) { // fill in code here } void dstAndSrc(const char* msg, const char* q, const char* p) { std::cout << msg << "... dst is: '" << q << "', 'src is: '" << p << "'n"; } #define BUFFER_SIZE 100 int compare(const char* p, const char* q) { // utility function – optional int cmp; // fill in code here return cmp; } #define BUFFER_SIZE = 100; int main(int argc, const char * argv[]) {     std::cout << "C++/C string functions to implement...nn" << "tstrcpy_(char* dst, const char* src);n" << "tstrncpy(char* dst, const char* src, size_t n);" << "tstrlen_(const char* str);n" << "tstrcat(char* dst, const char* src);n" << "tstrcmp(const char* lhs, const char* rhs);n";   char a[BUFFER_SIZE], b[BUFFER_SIZE];   memset(a, 0, sizeof(a)); memset(b, 0, sizeof(b));   char fname[] = "Aaron"; char lname[] = " Rodgerstein";   // fill in code here   std::cout << "before strcpy_... dst is: " << a << "." << " src is: " << fname;     strcpy(*a, *fname);               return 0; } //------------------------------------------------------------------------------------------------------ OUTPUT C++/C string functions to implement... strcpy_(char* dst, const char* src); strncpy(char* dst, const char* src, size_t n); strlen_(const char* str); strcat(char* dst, const char* src); strcmp(const char* lhs, const char* rhs); before strcpy_... dst is: '', 'src is: 'Aaron' after strcpy_... dst is: 'Aaron', 'src is: 'Aaron' before strncpy_ (8 chars incl. ' ')... dst is: '', 'src is: ' Rodgerstein' after strncpy_ (8 chars incl. ' ')... dst is: ' Rodgers', 'src is: ' Rodgerstein' 'Aaron' concatenated with ' Rodgers' = 'Aaron Rodgers' ................................. Aaron Rodgers 01234567890123456 strlen is: 13 philosopher is greater than than philosophy momently is greater than than momentarily

    Expert Answer

     
    #include<iostream> #include<string.h>

    I insufficiency succor with this C++ program. I insufficiency to appliance the aftercited administrations, still I’m having problemds usinf the expedient a and b places.

    #include <iostream>

    //

    // Copies the C string telling by rise into the place telling by aim,

    // including the terminating nature (and pause at that subject-matter).

    // To elude overflows, the bulk of the place telling by aim shall be crave ample to contain

    // the corresponding C string as rise (including the terminating ineffectual nature), and should referable attributable attributable attributable attributable attributable attributable attributable attributable attributable overlap

    // in fame w/ rise.

    char* strcpy_(char* q, const char* p) {

     

    // content in jurisprudence here

     

    unsigned i;

    for ( i=0; p[i] != ‘’; ++i )

    q[i] = p[i];

     

    return q;

     

     

    }

    // Copies the pristine num natures of rise to aim. If the purpose of the rise C string (which is signaled

    // by a ineffectual-character) is establish precedently num natures own been copied, aim is padded with zeros

    char* strncpy_(char* q, const char* p, bulk_t n) {

    // content in jurisprudence here

    }

    // Returns the tediousness of the C string str.

    // The tediousness of a C string is fast by the terminating ineffectual-character: A C string is as crave as the enumerate of natures

    // among the preparation of the string and the terminating ineffectual nature (extraneously including the terminating ineffectual nature itself).

    //

    size_t strlen_(const char* p) {

    // content in jurisprudence here

    }

    // Appends a portraiture of the rise string to the aim string. The terminating ineffectual nature in aim

    // is overwritten by the pristine nature of rise, and a ineffectual-nature is interjacent at the purpose of the upstartlightlight string formed

    // by the stringing of twain in aim. aim and rise shall referable attributable attributable attributable attributable attributable attributable attributable attributable attributable overlap.

    char* strcat_(char* s, const char* ct) {

    // content in jurisprudence here

    }

    // Parallels the C string str1 to the C string str2.

    // This administration starts comparing the pristine nature of each string. If they are resembling to each other,

    // it continues with the aftercited pairs until the natures be-unlike or until a terminating ineffectual-nature is reached.

    //

    int strcmp_(const char* p, const char* q) {

    // content in jurisprudence here

    }

    void dstAndSrc(const char* msg, const char* q, const char* p) {

    std::cout << msg << “… dst is: ‘” << q << “‘, ‘src is: ‘” << p << “‘n”;

    }

    #define BUFFER_SIZE 100

    int parallel(const char* p, const char* q) { // benefit administration – optional

    int cmp;

    // content in jurisprudence here

    return cmp;

    }

    #define BUFFER_SIZE = 100;

    int deep(int argc, const char * argv[]) {

     

     

    std::cout << “C++/C string administrations to appliance…nn”

    << “tstrcpy_(char* dst, const char* src);n”

    << “tstrncpy(char* dst, const char* src, bulk_t n);”

    << “tstrlen_(const char* str);n”

    << “tstrcat(char* dst, const char* src);n”

    << “tstrcmp(const char* lhs, const char* rhs);n”;

     

    char a[BUFFER_SIZE], b[BUFFER_SIZE];

     

    memset(a, 0, bulkof(a));

    memset(b, 0, bulkof(b));

     

    char fname[] = “Aaron”;

    char lname[] = ” Rodgerstein”;

     

    // content in jurisprudence here

     

    std::cout << “precedently strcpy_… dst is: ” << a << “.” << ” src is: ” << fname;

     

     

    strcpy(*a, *fname);

     

     

     

     

     

     

     

    return 0;

    }

    //——————————————————————————————————

    OUTPUT

    C++/C string administrations to appliance…

    strcpy_(char* dst, const char* src);

    strncpy(char* dst, const char* src, bulk_t n);

    strlen_(const char* str);

    strcat(char* dst, const char* src);

    strcmp(const char* lhs, const char* rhs);

    precedently strcpy_… dst is: ”, ‘src is: ‘Aaron’

    after strcpy_… dst is: ‘Aaron’, ‘src is: ‘Aaron’

    precedently strncpy_ (8 chars incl. ‘ ‘)… dst is: ”, ‘src is: ‘ Rodgerstein’

    after strncpy_ (8 chars incl. ‘ ‘)… dst is: ‘ Rodgers’, ‘src is: ‘ Rodgerstein’

    ‘Aaron’ concatenated with ‘ Rodgers’ = ‘Aaron Rodgers’

    ……………………………

    Aaron Rodgers

    01234567890123456

    strlen is: 13

    philosopher is important than than philosophy

    momently is important than than momentarily

    Expert Solution

     

    #include<iostream>

    #include<string.h>

    #define BUFFER_SIZE 100

    using namespace std;

    // Copies the C string telling by rise into the place telling by aim,

    // including the terminating nature (and pause at that subject-matter).

    // To elude overflows, the bulk of the place telling by aim shall be crave ample to contain

    // the corresponding C string as rise (including the terminating ineffectual nature), and should referable attributable attributable attributable attributable attributable attributable attributable attributable attributable overlap

    // in fame w/ rise.

    char* strcpy_(char* q, const char* p)

    {

    int i;

    for ( i=0; p[i] != ‘’; ++i )

    q[i] = p[i];

    q[i]=’’;

    return q;

    }

    // Copies the pristine num natures of rise to aim. If the purpose of the rise C string (which is signaled

    // by a ineffectual-character) is establish precedently num natures own been copied, aim is padded with zeros

    char* strncpy_(char* q, const char* p, bulk_t n)

    {

    int i;

    for ( i=0; i <=7; ++i )

    q[i] = p[i];

    q[i]=’’;

    return q;

    }

    // Returns the tediousness of the C string str.

    // The tediousness of a C string is fast by the terminating ineffectual-character: A C string is as crave as the enumerate of natures

    // among the preparation of the string and the terminating ineffectual nature (extraneously including the terminating ineffectual nature itself).

    size_t strlen_(const char* p)

    {

    int i,length=0;

    for(i=0;p[i]!=’’;i++)

    length++;

    return tediousness;

    }

    // Appends a portraiture of the rise string to the aim string. The terminating ineffectual nature in aim

    // is overwritten by the pristine nature of rise, and a ineffectual-nature is interjacent at the purpose of the upstartlightlight string formed

    // by the stringing of twain in aim. aim and rise shall referable attributable attributable attributable attributable attributable attributable attributable attributable attributable overlap.

    char* strcat_(char* s, const char* ct)

    {

    int i;

    for(i=0;i<ct[i]!=’’;i++)

    s[strlen_(s)]=ct[i];

    s[strlen_(s)]=’’;

    return s;

    }

    // Parallels the C string str1 to the C string str2.

    // This administration starts comparing the pristine nature of each string. If they are resembling to each other,

    // it continues with the aftercited pairs until the natures be-unlike or until a terminating ineffectual-nature is reached.

    int strcmp_(const char* p, const char* q)

    {

    while(*p)

    {

    if(*p != *q)

    break;

    p++;

    q++;

    }

    return *(const unsigned char*)p-*(const unsigned char*)q;

    }

    int deep(int argc, const char * argv[])

    {

    cout << “C++/C string administrations to appliance…n”

    << “strcpy_(char* dst, const char* src);n”

    << “strncpy(char* dst, const char* src, bulk_t n);n”

    << “strlen_(const char* str);n”

    << “strcat(char* dst, const char* src);n”

    << “strcmp(const char* lhs, const char* rhs);nn”;

     

    char temp1[BUFFER_SIZE], temp2[BUFFER_SIZE];

     

    memset(temp1, 0, bulkof(temp1));

    memset(temp2, 0, bulkof(temp2));

     

    char fname[] = “Aaron”;

    char lname[] = ” Rodgerstein”;

    // content in jurisprudence here

     

    cout << “Precedently strcpy_() Aim is: “” << temp1 << “”, Rise is: “” << fname<<“””;

    strcpy_(temp1,fname);

    cout << “nAfter strcpy_() Aim is: “” << temp1 << “”,” << ” Rise is: ” << fname<<“””;

     

    cout<<“nnPrecedently strncpy_() (8 chars including ‘\0’) aim is: “”<<temp2<<“”, Rise is: “”<<lname<<“””;

    strncpy_(temp2,lname,8);

    cout<<“nnAfter strncpy_() (8 chars including ‘\0’) aim is: “”<<temp2<<“”, Rise is: “”<<lname<<“””;

     

    strcat_(temp1,temp2);

    cout<<“nn”Aaron” concatenated with “Rodgers” is: “”<<temp1<<“””;

     

    cout<<“nnTediousness of temp1 is: “<<strlen_(temp1);

     

    int parallel=strcmp_(“momently”,”momentarily”);

    if(compare==0)

    cout<<“nnStrings are resembling”;

    else if(compare<0)

    cout<<“nnString 1 is close than string 2”;

    else

    cout<<“nnString 1 is larger than string 2”;

    compare=strcmp_(“philosopher”,”philosophy”);

    if(compare==0)

    cout<<“nnStrings are resembling”;

    else if(compare<0)

    cout<<“nnString 1 is close than string 2”;

    else

    cout<<“nnString 1 is larger than string 2”;

    compare=strcmp_(“money”,”money”);

    if(compare==0)

    cout<<“nnStrings are resembling”;

    else if(compare<0)

    cout<<“nnString 1 is close than string 2”;

    else

    cout<<“nnString 1 is larger than string 2”;

    return 0;

    }

    OUTPUT: