subject

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?

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 03:40
Hello my name is mihai and i need your : )i have to do a python project in computer science and i’m really busy with my mocks this period of time besides this i’m not good at coding so could someone pls pls pls sort me out ? i actually beg ; ))
Answers: 1
question
Computers and Technology, 23.06.2019 18:30
This program should be a short piece of code that prints all of the positive integers from 1 to 100 as described more fully below. the program may contain multiple methods, and if using an oo language, should be contained within a single class or object. the program should be designed so that it begins execution when invoked through whichever mechanism is most common for the implementation language. â–ş print out all positive integers from 1 to 100, inclusive and in order. â–ş print messages to standard output, matching the sample output below. â–ş in the output, state whether the each integer is 'odd' or 'even' in the output. â–ş if the number is divisible by three, instead of stating that the number is odd or even, state that the number is 'divisible by three'. â–ş if the number is divisible by both two and three, instead of saying that the number is odd, even or divisible by three; state that the number is 'divisible by two and three'. â–ş design the logic of the loop to be as efficient as possible, using the minimal number of operations to perform the required logic. sample output the number '1' is odd. the number '2' is even. the number '3' is divisible by three. the number '6' is divisible by two and three.
Answers: 1
question
Computers and Technology, 24.06.2019 17:40
Anewly established internet company with 40 employees needs your advice. they are looking for a collaboration tool and have narrowed their choices to gotomeeting, webex, and my web conferences. after reading the information presented in this chapter and other sources, prepare a two- page document ( double spaced) that includes two advantages and two disadvantages of each tool. which one is your final recommendation? why did you choose that tool over the other two?
Answers: 3
question
Computers and Technology, 25.06.2019 12:00
Fill in the blank; "as well as their traditional role of computing data, computers are also extensively used "
Answers: 3
You know the right answer?
INSTRUCTIONS ARE: Write a function that accepts an int array and the array’s size as arguments.
Questions
Questions on the website: 13722361