new, delete, and char** Exercises
Tom Kelliher, CS18
Apr. 26, 1996
- Quiz on Monday: Linked Lists I.
- We won't cover ``Class Subtleties'' explicitly in class. However,
you are responsible for the material. See the Feb. 29 CS23 lecture
Write a program that:
- Uses new to allocate an array of three char*s.
- Reads three names (using getline()), one by one, into a
char array ( buffer) from cin. Dynamically allocate space
(pointed to by one of the char*s --- one for each name) for each
name. Copy each name from buffer to its dynamically allocated space.
- Swap the first and third names (accomplished by merely swapping the
- Print the names.
- Deallocate, using delete, all dynamically allocated memory (in
the correct order).
Hand-in the program you write.
A few variables you'll need:
const int NAME_LEN = 80;
Thomas P. Kelliher
Thu Apr 25 13:39:49 EDT 1996