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

1. Three of these code blocks result in a syntax error. Three of these code bloc

ID: 639272 • Letter: 1

Question

1. Three of these code blocks result in a syntax error. Three of these code blocks are quite illegal. One of these code blocks is legal unlike the others. Now it's time to play our game. Here's the class definition below.

class AClass
{
//... some other members
  void Print() const;
  void Illuminate();
  AClass & operator=(const AClass &);
}

void DoSomething(const AClass & aclass)
{
  const AClass temp;
  temp = aclass;
}

void Print(const AClass & aclass)
{
  aclass.Print();
}

void GiveMe(const AClass & aclass)
{
  AClass temp;
  aclass = temp;
}

void Illuminate(const AClass & aclass)
{
  aclass.Illuminate();
}

2. Which code block produces a syntax error when compiled?

int a = 10;
int iarray[a];

const int a = 10;
int iarray[a];

const int a = 10;
int * iPtr = new int[a];

int a = 10;
int * iPtr = new int[a];

3. What are the steps to double a dynamic array pointed to by an old pointer when the array size is full?

1. Make an int pointer.

2. Create and point to a new dynamic array of double size.

3. Copy values from old array to new array.

4. Delete old dynamic array.

5. Point old pointer at new array.

1. Copy values from old array to new array.

2. Point at new array.

3. Make an int pointer.

4. Delete old dynamic array.

5. Create and point to a new dynamic array of double size.

1. Copy values from old array to new array.

2. Make an int pointer.

3. Delete old dynamic array.

4. Create and point to a new dynamic array of double size.

5. Point old pointer at new array.

1. Point at new array.

2. Delete old dynamic array.

3. Copy values from old array to new array.

4. Create and point to a new dynamic array of double size.

5. Make an int pointer.

void DoSomething(const AClass & aclass)
{
  const AClass temp;
  temp = aclass;
}

void Print(const AClass & aclass)
{
  aclass.Print();
}

void GiveMe(const AClass & aclass)
{
  AClass temp;
  aclass = temp;
}

void Illuminate(const AClass & aclass)
{
  aclass.Illuminate();
}

Explanation / Answer

1.

void GiveMe(const AClass & aclass)
{
AClass temp;
aclass = temp;
}

2.

int a = 10;
int iarray[a]; //a needs to be a constant

3.

1. Copy values from old array to new array.

2. Point at new array.

3. Make an int pointer.

4. Delete old dynamic array.

5. Create and point to a new dynamic array of double size