Question: C++ PROGRAM create the function: int differ(const string a1[], int n1, const string a2[], int n2); the functions you must write take 4 parameters. array
C++ PROGRAM
create the function: int differ(const string a1[], int n1, const string a2[], int n2);
the functions you must write take 4 parameters. array of strings a1[] and a2[] , and the number of items function will consider in the arrays n1 and n2, starting from the beginning. Return the position of the first corresponding elements of a1 and a2 that are not equal. n1 is the number of interesting elements in a1, and n2 is the number of interesting elements in a2. If the arrays are equal up to the point where one or both runs out, return whichever value of n1 and n2 is less than or equal to the other. all functions that return an int must return 1 if they are passed a negative array size. passing 0 to the function as the array size is not itself an error; it merely indicates the function should examine no elements of the array. Also when we say "the array", we mean the n elements that the function is aware of. The one error your function implementations doesn't have to handle is when the caller of the function lies and says the array is bigger than it really is.
string folks[6] = { "bruce", "steve", "", "tony", "sue", "clark" }; string group[5] = { "bruce", "steve", "clark", "", "tony" }; int r = differ(folks, 6, group, 5); // returns 2 int s = differ(folks, 2, group, 1); // returns 1 int t = differ(folks, 4, group, -7); // returns -1
int u = differ(folks, 6, group, 0); // returns 0
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
