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 05:00
This program will store roster and rating information for a soccer team. coaches rate players during tryouts to ensure a balanced team. (1) prompt the user to input five pairs of numbers: a player's jersey number (0 - 99) and the player's rating (1 - 9). store the jersey numbers in one int vector and the ratings in another int vector. output these vectors (i.e., output the roster). (3 pts) ex: enter player 1's jersey number: 84 enter player 1's rating: 7 enter player 2's jersey number: 23 enter player 2's rating: 4 enter player 3's jersey number: 4 enter player 3's rating: 5 enter player 4's jersey number: 30 enter player 4's rating: 2
Answers: 1
question
Computers and Technology, 22.06.2019 11:20
The kurt vonnegut commencement speech, the neiman-marcus chocolate chip cookie recipe, and the get-well emails to the dying boy are examples of select one: a. social engineering b. hoax emails c. email viruses d. worms
Answers: 1
question
Computers and Technology, 22.06.2019 14:40
For this assignment you have to write a c program that will take an infix expression as input and display the postfix expression of the input. after converting to the postfix expression, the program should evaluate the expression from the postfix and display the result. what should you submit? write all the code in a single file and upload the .c file. compliance with rules: ucf golden rules apply towards this assignment and submission. assignment rules mentioned in syllabus, are also applied in this submission. the ta and instructor can call any students for explaining any part of the code in order to better assess your authorship and for further clarification if needed. problem: we as humans write math expression in infix notation, e.g. 5 + 2 (the operators are written in-between the operands). in computer's language, however, it is preferred to have the operators on the right side of the operands, ie. 5 2 +. for more complex expressions that include parenthesis and multiple operators, a compiler has to convert the expression into postfix first and then evaluate the resulting postfix write a program that takes an "infix" expression as input, uses stacks to convert it into postfix expression, and finally evaluates it. it must support the following operations: + - / * ^ % ( example infix expression: (7-3)/(2+2) postfix expression: 7 3 2 2 result: rubric: 1) if code does not compile in eustis server: 0. 2) checking the balance of the parenthesis: 2 points 3) incorrect postfix expression per test case: -2 points 4) correct postfix but incorrect evaluation per test case: -i points 5) handling single digit inputs: maximum 11 points 6) handling two-digit inputs: 100 percent (if pass all test cases)
Answers: 3
question
Computers and Technology, 24.06.2019 10:00
Which feature of a blog to restore and retrieve older post
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
question
Mathematics, 09.11.2020 07:10
question
History, 09.11.2020 07:10
Questions on the website: 13722363