Write a C++ function compStr(s1,s2) which takes two strings, s1 and s2, and compares them. If s1 and s2 are of differen

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

Write a C++ function compStr(s1,s2) which takes two strings, s1 and s2, and compares them. If s1 and s2 are of differen

Post by answerhappygod »

Write a C++
function compStr(s1,s2) which takes two
strings, s1 and s2, and compares them.
If s1 and s2 are of different lengths, the
function returns –1 if s1 is shorter than s2, or 1
if s2 is shorter than s1.
If s1 and s2 are the same length, the function
returns –1 if s1 comes
before s2 alphabetically, 1 if s2 comes
before s1 alphabetically.
If s1 and s2 are the same string, the function
returns 0. Note: A character value ch1 is alphabetically
before a character value ch2 provided ch1 <
ch2.
Requirements:
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply