csci 20 :: book learning challenge 7 (due tues, mar 8)
Submitting your work: Complete this exercise on your own.

Fill in all of the "Answer" boxes, then print the answer grid that you see after you press "Prepare for printing".

Staple all pages together and submit to the instructor on the date listed above.

Questions:

Read and answer the following:

Your name:
  1. Write the code to concatenate the string variables greeting and name below and store the new, larger string into the string variable message.
    string greeting = "Good morning, ";
    string name = "Jill";
    string message;
    Answer:

  2. What is the C++ term for describing the value of the string variable message below? In other words, does message have any contents?
    string message;
    Answer:
  3. What will be the output of the following C++ code?
    string message = "Hello World!";
    cout << message.length();
    Answer:
  4. What will be the output of the following C++ code?
    string message = "Hello World!";
    cout << message[0] << '-' << message[6];

    Answer:
  5. What will be the output of the following C++ code?
    string input = "Good Morning";
    string uppercaseInput;
    string lowercaseInput;
    for (int i=0; i<input.length(); i++) {
         uppercaseInput += toupper(input[i]);
         lowercaseInput += tolower(input[i]);
    }
    cout << uppercaseInput << ", " << lowercaseInput;
    Answer:
  6. What will be the output of the following C++ code?
    string message = "grapefruit";
    for (int i=0; i<message.length(); i++) {
         message[i] = '-';
    }
    cout << message;
    Answer:
  7. What will be the output of the following C++ code?
    string realMessage = "hello";
    string hiddenMessage = "-----";
    for (int i=0; i<realMessage.length(); i++) {
         if (realMessage[i] == 'e')
              hiddenMessage[i] = 'e';
    }
    cout << hiddenMessage;
    Answer:
  8. What C++ library do you include in your program if you want to use the char testing and transformation functions?
    Answer:
  9. Write the name of the function to perform each of the following char tests:
    • is an alphabetic character
    • is a numeric character
    • is an alphabetic or numeric character
    • is a punctuation symbol

    Answer:
  10. Write the code to loop through the string message below, displaying each character in the string on a separate line, in all capital letters.
    string message = "See you later!";

    Answer:

Total points for this book learning challenge:

150 points