Chapter 5:  Pointers & Strings

 

  1. Declare and initialize two ints  yourPlace  and  myPlace.  Make a pointer to each.  Clearly print in table format:

a.       the address of each int and the value of their pointers.

b.      Each pointer, the dereferenced address of each pointer, and the address of each dereferenced pointer.

 

  1. Declare an array, called  squoosh, of ten floats.  In tabular form print the address of each float right next the float itself.  Do you see a pattern?  Then print  squoosh  (without a subscript), and right next to it print  *squoosh.  What exactly is  squoosh?

  2. Calculate the average of a number and its square in two different ways:
    1. Via a regular ole function call
    2. Via a function that accepts a pointer and changes the value of the input

  3. Check out the bubble sort program with pointers on page 300.  Modify it so that the user inputs up to 10 ints and after each a new sorted list is printed.

  4. Create an array of 3 digits numbers and send it to a function.  The function should receive it using pointer notation.   Also using pointer notation print out each number that has an odd middle digit.

  5. Write your own function that reverses a string like this:  “Eanie Meany Miney Moe”  becomes  “eoM yeniM ynaeM einaE”.

  6. Write your own function that reverses a string like this:  “Eanie Meany Miney Moe”  becomes  “einaE ynaeM yeniM eoM”.

  7. Make a madlibs game:  Ask the user to enter five nouns, five verbs, and five adjectives/adverbs.  The words for each grammar category should be stored in their own array of strings.  Write a clever little story with some blanks in it, into which the input words will be inserted at random.

  8. Use  cin.getline  to store a sentence.  (cin  alone will quit recording after a space.)  Create and print a new string that replaces any stars (*) in the original string with the string  Frankenstein.  Creating a new string is required.

  9.  Make a menu-driven interface that can do the following after receiving an input sentence.  You must use function pointers.  You should make use of  string.h  functions.
    1. Find how many words are in the sentence. 
    2. Print a list of the number of letters in each word. 
    3. Check to see if any words are repeated.
    4. Make a string out of every other word.

  10.  Make your own version of  #17  on page 345.