Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1) a) The following code was written to declare a dynamic two-dimensional array

ID: 3842119 • Letter: 1

Question

1)

a) The following code was written to declare a dynamic two-dimensional array with 10 rows and 4 columns, but it is incorrect!  Correct it below.

int **matrix = new int matrix[10];

int i;

for (i = 0; i < 4; i++)

matrix[i] = new int[10];

b) Write the code to free (deallocate) the two-dimensional array from part a) above.

2)

Here is a class

class movieInfo

{

private:

     int numActors; //number of Actors on the list

     string * actorList; //holds all the actor names

     string director;

public:

     void printActors() const; //prints all the actors

     void readActors(); //gets actor names from cin

     void setDirector(string); //sets the director name

     string getDirector() const; //returns the director name

     movieInfo(); //sets empty actorList

     movieInfo(int); //sets numActors to int parameter

a ) Write the prototype and defintion for a member function called sharesDirector.  This function returns true if two movies have the same director and returns false otherwise.

prototype:____________________________________________________________

definition:

b) Write the prototype and defintion for a member function calles sharesActors.  This function returns the number of shared actors (i.e. the count of actors that are in both movies.)  If there are no actors that are in both movies, then the function returns a zero.

prototype:____________________________________________________________

definition:

Explanation / Answer

1) a)  int **matrix = new int matrix[10];
int i;
for (i = 0; i < 10; i++)
matrix[i] = new int[4];

b)

2)

a)

prototype: bool sharesDirector(movieInfo a, movieInfo b);

defination: bool movieInfo :: sharesDirector(movieInfo a, movieInfo b){
   if(a.getDirector().compare(b.getDirector())==0)
       return true;
   else
       return false;
}