Chapter 5: Pointers
& Strings
- 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.
- 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?
- Calculate
the average of a number and its square in two different ways:
- Via
a regular ole function call
- Via
a function that accepts a pointer and changes the value of the input
- 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.
- 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.
- Write
your own function that reverses a string like this: “Eanie Meany Miney Moe” becomes “eoM yeniM ynaeM einaE”.
- Write
your own function that reverses a string like this: “Eanie Meany Miney Moe” becomes “einaE ynaeM yeniM eoM”.
- 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.
- 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.
- 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.
- Find
how many words are in the sentence.
- Print
a list of the number of letters in each word.
- Check
to see if any words are repeated.
- Make
a string out of every other word.
- Make your own version of #17
on page 345.