C++ How To Program Plus Mylab Programming With Pearson Etext -- Access Card Package (10th Edition)
Question
Book Icon
Chapter 22, Problem 22.31E
Program Plan Intro

Program Plan:

  • Include header files.
  • Start “main()” function.
  • Accept two strings “s1” and “s2” to compare.
  • Use “strlen()” to compare length of string “s1” with length of “s2”. If length of string “s1” is greater, put length of “s1” in “len”, else put length of string “s2” in “len”. It is required for strncmp function which has following syntax:
  • strncmp(,string2>,n); where n is number of characters to be compared.

  • Use strncmp function to compare s1, s2, and using “len” as n and store the result in variable “compare”.
  • Use if construct to check if “compare” is equal to 0, then display “Both strings are equal.".
  • else check if compare> 0, which will display “First string is greater than second.". Else display “First string is less than second."
  • Return and exit.

Blurred answer
Students have asked these similar questions
Using the code and the function above
State whether each of the following is true or false. If false, explain why h) All arguments following the format control string in a printf function must be preceded by an ampersand (&).
-Convert SES variable to a factor and assign the value labels “low”, ”middle” and “high” to the 3 levels of thevariable. Then -Define the variables complic, comorb, depressi, diabetes as factors. For all these factors, a zero means “no” and a 1 means “yes”. Assign these value labels through the function factor() and check the change using str()

Chapter 22 Solutions

C++ How To Program Plus Mylab Programming With Pearson Etext -- Access Card Package (10th Edition)

Knowledge Booster
Background pattern image
Recommended textbooks for you
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning