CS1711 Lab 3 - October 12 and 14, 1999
Exploring Strings and Characters

Introduction

This lab will introduce you to the use of the characters and character strings in C++.
Part A of the lab will explore the differences between the standard input operator cin >> and the cin.get() operator.
Part B of the lab will perform experiments with Strings.

PART A: Investigating characters (char)

  1. Create a project called Testchar on your M: drive (in the folder CS1711Labs\Lab3)
  2. Obtain the file testchar.cpp from the T: drive folder for Lab 3, and save it on your M: drive in the folder CS1711Labs\Lab3 Add it to your project. It contains a program called TestChar that you may need to modify in order to  experiment with the C++ char data type.
  3. Compile and build the program. Answer the questions below before running the program and check your predictions against the actual results
  4. Show the results of the following character operations on the lab sheet:

  5. a. If the user inputs '<4 spaces>A, what will be displayed as the cin >> result ?  ..as the cin.get (ch) result ?
    b. If the user presses the <Enter> key when prompted for cin.get (ch), what character is "grabbed" ?
    d. If the user enters 'A' for the ASCII  character ch and chooses shift = 25, then ch + 25 =
    e. If the user enters 'A' for the ASCII  character ch and chooses shift =  32 then ch + 32 =
    d. What happens if you use 256 as the shift value for a character ? Can  you modify the program to deal with this ?

PART B: Investigating Strings

Be sure to take into account the fact that tstring.h is located on the T: drive in the T:\......\include directory .
    1. Create a project called Teststrg on your M: drive (in the folder CS1711Labs\Lab3 )
    2. Obtain the file teststrg.cpp from the T: drive folder for Lab 3, and save it on your M: drive in the folder CS1711Labs\Lab3 Add it to your project. It contains a program called TestStrg that you may need to modify in order to  experiment with the String data type.
    3. Compile and build the program. Run it and use it to answer the questions listed below. To get the maximum benefit from this lab, think about each question and the answers you obtain as you proceed. When possible, try to predict the answers before using the program.
    4. Show the results of the following character operations on the lab sheet:

    5. a. If the user inputs 'Hello         Fred' , what will be displayed as string1?
      b. If the user inputs 'Hello Fred'  what will be displayed as string1 + string2?
      c. If the user inputs 'Hello Fred'  what will be displayed as reversal ?
      d. How would you modify the teststrg.cpp program in order to display 'Hello         Fred' in response to the input in 4 a)?

End of Lab

Make sure you have shown your report to the lab assistant so that you receive credit for the lab.