CMPSC 101 - Strings Worksheet #2 Name -

1. (True/False) The string literal "abc" is considered to be less than the string literal "xyz".
2. (True/False) The string literal "abc" is considered to be less than the string literal "ABC".
3. (True/False) The string literal "John" is considered to be equal to the expression ("Jo" + "hn").
4. (True/False) If the string variable firstName contained the value "Jane" then the statement     cout << firstName.length();    would display the value 4.

5. Write an if statement that displays the message "greater than" if the string variable player1 is greater than the string variable player2 .

6. Write a statement displays the sum of the length of the string variable firstName plus the length of the string variable lastName.

 

7. Write a statement that concatenates the string variables firstName and lastName with an added blank space between them and stores the resulting string value into the string variable wholeName.


8. Write a program that allows the user to input his first name and then uses a loop to display each letter of the name on a separate line of output.


 

 

 

 

 

 

 

 

9. Write a program that allows 3 people to input their first names and then displays the name that is least alphabetically (e.g. Alice is less than Bill). Use the back of the paper if necessary.