Question: ****C++*****CODE IS C++*************** ***************************************************** *****C++*****C-PLUS-PLUS*****C++**** ************************************************************* ****THANK****YOU************************ We provide a driver below, Preview the document, Note: please insert one line: #include right between line: #include
****C++*****CODE IS C++***************
*****************************************************
*****C++*****C-PLUS-PLUS*****C++****
*************************************************************
****THANK****YOU************************



We provide a driver below, Preview the document, Note: please insert one line: #include
***Driver File****
#include "mystring.h"
#include
#include
using namespace std;
#define MAX_STRING_LENGTH 256
#define ASSURE(b) assure(b, __LINE__)
void assure(bool bSuccessful, int iLineNum)
{
if (! bSuccessful)
printf("Test at line %d failed. ", iLineNum);
}
void testmystrlen(void)
{
size_t uiResult;
uiResult = mystrlen("Ruth");
ASSURE(uiResult == 4);
uiResult = mystrlen("Gehrig");
ASSURE(uiResult == 6);
uiResult = mystrlen("");
ASSURE(uiResult == 0);
}
void testmystrcmp(void)
{
int iResult;
iResult = mystrcmp("Ruth", "Ruth");
ASSURE(iResult == 0);
iResult = mystrcmp("Gehrig", "Ruth");
ASSURE(iResult
iResult = mystrcmp("Ruth", "Gehrig");
ASSURE(iResult > 0);
iResult = mystrcmp("", "Ruth");
ASSURE(iResult
iResult = mystrcmp("Ruth", "");
ASSURE(iResult > 0);
iResult = mystrcmp("", "");
ASSURE(iResult == 0);
}
void testmystrcpy(void)
{
char pc[MAX_STRING_LENGTH];
char *pcResult;
pcResult = mystrcpy(pc, "Ruth");
ASSURE(pcResult != NULL);
ASSURE(pcResult == pc);
ASSURE((pcResult != NULL) && (strcmp(pc, "Ruth") == 0));
pcResult = mystrcpy(pc, "");
ASSURE(pcResult != NULL);
ASSURE(pcResult == pc);
ASSURE((pcResult != NULL) && (strcmp(pc, "") == 0));
}
void testmystrcat(void)
{
char pc[MAX_STRING_LENGTH];
char *pcResult;
strcpy(pc, "Ruth");
pcResult = mystrcat(pc, "Gehrig");
ASSURE(pcResult != NULL);
ASSURE(pcResult == pc);
ASSURE((pcResult != NULL) && (strcmp(pcResult, "RuthGehrig") == 0));
strcpy(pc, "Ruth");
pcResult = mystrcat(pc, "");
ASSURE(pcResult != NULL);
ASSURE(pcResult == pc);
ASSURE((pcResult != NULL) && (strcmp(pcResult, "Ruth") == 0));
strcpy(pc, "");
pcResult = mystrcat(pc, "Ruth");
ASSURE(pcResult != NULL);
ASSURE(pcResult == pc);
ASSURE((pcResult != NULL) && (strcmp(pcResult, "Ruth") == 0));
strcpy(pc, "");
pcResult = mystrcat(pc, "");
ASSURE(pcResult != NULL);
ASSURE(pcResult == pc);
ASSURE((pcResult != NULL) && (strcmp(pcResult, "") == 0));
}
/*
void testmystrstr()
{
char pc[] = "llama";
char pcEmpty[] = "";
char *pcResult;
pcResult = mystrstr(pc, "am");
ASSURE(pcResult == pc + 2);
pcResult = mystrstr(pc, "m");
ASSURE(pcResult == pc + 3);
pcResult = mystrstr(pc, "ll");
ASSURE(pcResult == pc);
pcResult = mystrstr(pc, "l");
ASSURE(pcResult == pc);
pcResult = mystrstr(pc, "llama");
ASSURE(pcResult == pc);
pcResult = mystrstr(pc, "lamal");
ASSURE(pcResult == NULL);
pcResult = mystrstr(pc, "");
ASSURE(pcResult == pc);
pcResult = mystrstr(pcEmpty, "llama");
ASSURE(pcResult == NULL);
pcResult = mystrstr(pcEmpty, "");
ASSURE(pcResult == pcEmpty);
}
*/
int main()
{
testmystrlen();
testmystrcmp();
testmystrcpy();
testmystrcat();
// testmystrstr();
printf("If no any error outputs, your program passes all the tests. The
End. ");
return 0;
}
****END********
Your task in this assignment is to complete your own versions of these four most commonly used standard string functions. Your version: int mystrlen( const char s) int mystrcmp( const char 's1, const char 's2) int strcmp( const char 's1, const char s2) char "mystrcpy( char "s1, const char "s2) char "strcpy( char 's1, const char s2) char "mystrcat( char s1, const char "s2) char "strcat char 's1, const char "s2) C standard string library functions: int strlen( const char 's) Each of your functions should have the same behavior as the corresponding above C standard string function. For example, your mystrlen function should have the same behavior as the C standard strlen function. Your functions should not call any of the standard string functions. In the context of this assignment, you should pretend that the standard string functions do not exist. You should pay special attention to boundary cases. In particular, make sure that your functions work when given empty strings as arguments. For example, make sure that the function call mystrlen() returns 0 First create a header file named mystring.h containing the interface to your functions. The interface should consist of a set of function declarations. Then create a file named mystring.cpp containing the implementation of your functions, that is, a set of function definitions. It should ""include" the interface file to insure that each function definition is consistent with its declaration. You may use array notation to define your functions. For example, this is an acceptable version of the mystrlen function
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
