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

Consider the following code that checks to see if adjacent elements in an array

ID: 3867579 • Letter: C

Question

Consider the following code that checks to see if adjacent elements in an array of structs are similar, where similar means they have one or Create both an anonymous function cases that responds with true if the two elements are similar. Finally show how to invoke isSimilar to answer the requests that follow: (a) Compare two locations with fields continent, country, and capital. Example: loc1.contient = 'North America', loc1.country = 'Mexico', loc1.capital = 'Mexico City': loc2.contient = 'North America', loc2.country = 'USA', loc2.capital = 'Washington D.C.': In the example, loc1 and loc2 are similar, because they are on the same continent. Don't forget that to compare two strings, you must use strcmp(). Function s = isSimilar(a, cFun) s = true: for ii = 2: length(a) id ^-cFun(ii - 1), a(ii)) s = false: end end

Explanation / Answer

The program to compare the two strings are as follows:

void func(){
char s1[15]="North America";
char s2[15]="Mexico";
char s3[15]=new String("Mexico");
char s4[15]="North America";
char s5[15]="USA";
char s6[15]="Washington D.C.";
strcmp(s1,s4);
strcmp(s2,s5);
strcmp(s3,s6);
}

Please rate the answer if it helped.......Thankyou

Hope it helps.....

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