Computers and Technology

INSTRUCTIONS ARE: Write a function that accepts an int array and the array’s size as arguments.
1. The function should create a new array that is twice the size of the argument array.
2. The function should copy the contents of the argument array to the new array, and initialize the unused elements of the second array with 0.
3. The function should return a pointer to the new array.

Demonstrate the function by using it in a main program that reads an integer N (that is not more than 50) from standard input and then reads N integers from a file named data into an array.

The program then passes the array to your array expander function, and prints the values of the new expanded array on standard output, one value per line.

You may assume that the file data has at least N values. There are no prompts for the integer and no labels for the expanded reversed array that is printed out. If the integer read in from standard input exceeds 50 or is less than 0 the program terminates silently.

HERES MY CODE:

#include
#include
#include
using namespace std;

int * expand (int [], int);

int main ()
{
int size;

cout > size;

if (size > 50)
return 0;
else if (size > arr[i];
}

for (int i = 0; i < size*2; i++)
{
cout << *(expand (arr, size)+i);
}

return 0;
}

int * expand (int arr[], int size)
{
int * ptr = new int [size*2];

for (int i = 0; i {
*(ptr+i) = arr[i];
}
for (int i = size+1; i {
*(ptr+i) = 0;
}

return ptr;
}

WHAT IS WRONG AND WHAT SHOULD I DO/CHANGE?

answer
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 16:00, sdonachy7
You have inserted new slides based on a word outline. how do you format these new slides to match the powerpoint presentation formatting? a. select all slides in the presentation and click format on the home tab. b. select the new slides and click reset on the home tab. c. select all slides in the presentation and click reset on the home tab. d. select the new slides and click format on the home tab.
Answers: 3
image
Computers and Technology, 22.06.2019 19:00, SoccerHalo
How is the number 110 written when expanded out to place values in the base 2 (binary) number system? options: 2 x 4 + 3 x 2 + 4 x 1 1 x 2 + 1 x 2 + 0 x 2 1 x 100 + 1 x 10 + 0 x 1 1 x 4 + 1 x 2 + 0 x 1
Answers: 1
image
Computers and Technology, 23.06.2019 05:30, savyblue1724707
Sally is editing her science report about living things. she needs to copy a paragraph from her original report. order the steps sally needs to do to copy the text to her new document.
Answers: 1
image
Computers and Technology, 23.06.2019 20:30, maryanapritchak1829
If chris has a car liability insurance, what damage would he be covered for
Answers: 1
Do you know the correct answer?
INSTRUCTIONS ARE: Write a function that accepts an int array and the array’s size as arguments.

Questions in other subjects: