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

Implement the stringifyArray(int[],int) used in the code below. #include <iostre

ID: 3542428 • Letter: I

Question

Implement the stringifyArray(int[],int) used in the code below.

#include <iostream>
#include <cstdlib>

using namespace std;

/* Prints the given integer array to the screen.
*
* Require: size >= 0 &&
*           size == array[last+1];
* Ensure:  Only array memory location are traversed &&
*           output format: "{ x,y,z }"
*/
void stringifyArray(int array[], int size);

int main() {
  int integers_one[3] = { 0,1,3 };
  int integers_two[2][3] = {{ 0,1,2 },{2,3,4}};

  cout << "Integer array: " << endl;
  stringifyArray(integers_one, 3);

  exit(EXIT_SUCCESS);
}

Lines are not to excede 80 characters in length. Do not use cryptic names for variables, functions, etc. Do not use do-while loops (unless told otherwise). Do not use breaks (unless told otherwise). Do not use continues (unless told otherwise). Do not use switch-cases (unless told otherwise).

Explanation / Answer

void stringifyArray(int array[], int size)

{

if (size>=0 && size==sizeof(array)/sizeof(*array))

{

cout<<"{";

for(int i=0;i<size;i++)

{

cout<<array[i];

if (i!=size-1)

cout<<",";

}

cout<<"}"<<endl;

}

}