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

Assume that s is a string. Write an expression whose value is true if and only i

ID: 3653750 • Letter: A

Question

Assume that s is a string. Write an expression whose value is true if and only if the value of s would come between "mortage and "mortuary" in the dictionary.

Explanation / Answer

(strcmp(s, "mortgage") > 0) && (strcmp(s, mortuary) < 0) The pattern for comparing C strings in C or C++ is to convert the string1 string2 ...comparison that you'd like to do into strcmp(string1,string2) 0, ...where is any comparison operator, =, !=, etc. You need to include to get the prototype for strcmp (or include in C). For C++ string variables (std::string class), use: (s.compare("mortgage") > 0) && (s.compare("mortuary") < 0)