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

#include <iostream> using namespace std; // Prototype int *expandArray(int[], in

ID: 3643010 • Letter: #

Question

#include <iostream>
using namespace std;

// Prototype
int *expandArray(int[], int [], int);
void showArray(int[], int);

void main ()
{
const int size = 5;

int numbers[size] = {1, 2, 3, 4, 5};

int copy[size*2];

//Expand the array
int *newArray = expandArray(numbers, copy, size);

// Display the contents of the original array to prove it wasn't damaged
cout << "The contents of the original array are: ";
showArray(numbers, size);
cout << endl;

// Display the contents of the new array
cout << "The contents of the new array are: ";
showArray(copy, size);
cout << endl;

system ("pause");

}

int *newArray(int numbers[], int copy[], int size)
{
for (int i = 0; i < size; i++);
copy[size*2] = numbers[size];
for (int i = 5; i < size*2; i++)
copy[size*i] = 0;

return copy;
}

void showArray(int numbers[], int size)
{
for (int i = 0; i < size; i++)
cout << numbers[i];
cout << endl;
}

Explanation / Answer

#include <iostream>
using namespace std;

// Prototype
int *expandArray(int[], int [], int);
void showArray(int[], int);

void main ()
{
const int size = 5;

int numbers[size] = {1, 2, 3, 4, 5};

int copy[size*2];

//Expand the array
int *newArray = expandArray(numbers, copy, size);

// Display the contents of the original array to prove it wasn't damaged
cout << "The contents of the original array are: ";
showArray(numbers, size);
cout << endl;

// Display the contents of the new array
cout << "The contents of the new array are: ";
showArray(newArray, size);
cout << endl;

system ("pause");

}

int *newArray(int numbers[], int copy[], int size)
{
for (int i = 0; i < size; i++);
copy[size*2] = numbers[size];
for (int i = 5; i < size*2; i++)
copy[size*i] = 0;

return copy;
}

void showArray(int numbers[], int size)
{
for (int i = 0; i < size; i++)
cout << numbers[i];
cout << endl;
}

int *expandArray(int original[], int copy[], int size)
{
for(int i=0; i<size; i++)
copy[i] = original[i];

return copy;
}