Quiz 3 (Pointers)
1)
Given the following declaration;
int aNumber;
a)
declare an integer pointer
b)
set the integer pointer to point to aNumber
c)
set the value of aNumber to fifteen by using the pointer
d)
print out the value of aNumber and the address of aNumber
using the pointer
2)
Given the following declaration:
int number = 0;
int *ptr = &number;
Assume that number resides at address 00214C10 in memory and ptr resides at 001BFE20.
Describe the effects of
the following statements. Explain which variable
changes, and how.
a)
ptr++;
b)
number++;
c)
(*ptr)++;
3)
a) Declare a two dimensional dynamic array with 4 rows and 5 columns.
b) Give an real world example of when you
would use a two dimensional dynamic array.
4)
Given:
float a[5] = {0.0, 1.1, 2.2, 3.3, 4.4};
float *b = &a[1];
Use the pointer b to set the value of the last element of the array to be equal
to zero.
5)
Given the following
class:
class movieInfo
{
private:
int numActors;
string
* actorList;
string
director;
public:
void printActors() const;
void readActors();
void setDirector(string);
string
getDirector() const;
movieInfo();
};
a)
Write the constructor
(prototype and definition) that will take one int parameter that indicates the number of actors
that will be stored in this movie.
(REMEMBER TO ALLOCATE SPACE FOR THE ACTOR NAMES).
b)
Write the destructor
prototype and definition.
c)
Write the definition
of the member function isInMovie that takes one string parameter that hold
the name of an actor and returns true if that actor is in
the movie and false otherwise.