![lucywood2024](/avatars/15723.jpg)
lucywood2024
10.01.2021 •
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?
Solved
Show answers
More tips
- L Leisure and Entertainment How to Solve a Rubik s Cube Easily and Quickly...
- H Health and Medicine Want to Lose Weight? Gain Muscle without Damaging Your Health!...
- F Family and Home Parquet or laminate, which is better?...
- L Leisure and Entertainment How to Properly Wind Fishing Line onto a Reel?...
- L Leisure and Entertainment How to Make a Paper Boat in Simple Steps...
- T Travel and tourism Maldives Adventures: What is the Best Season to Visit the Luxurious Beaches?...
- H Health and Medicine Kinesiology: What is it and How Does it Work?...
- O Other How to Choose the Best Answer to Your Question on The Grand Question ?...
- L Leisure and Entertainment History of International Women s Day: When Did the Celebration of March 8th Begin?...
- S Style and Beauty Intimate Haircut: The Reasons, Popularity, and Risks...
Answers on questions: Computers and Technology
- C Computers and Technology Is this correct just need somebody to check my answer plz and use your honest answer...
- C Computers and Technology Which number is equivalent to 72.5e-2? 0.725 72.5 7.25 7250...
- S SAT What is the slope of line PQ? What is the slope of line MN? How are the two lines related?...
- A Advanced Placement (AP) A student plans to build a model roller coaster for a science fair. The only energy for the car is the potential energy it contains. The student wants the car to...
- M Mathematics 7(7a-9) is greater then or equal to 84...
- E English What is one object that exists that you believe could have multiple meanings the same way Atwood shapes the different meanings of bread? Explain your reasoning....
- M Mathematics For a ride on a rental scooter, Deshaun pald a $7 fee to start the scooter plus 7 cents per minute of the ride. The total bill for Deshaun s ride was $14.14. For...
- C Chemistry What is the ground state electron configuration for arsenic? a 1s22s22p63s23p64s24p 3 b 1s22s22p63s23p64s24p34d10 c 1s22s22p63s23p63d104s24p 6 d 1s22s22p63s23p63d104s24p3...
- B Biology 50 POINTS PLS HELP Chemicals like polybrominated diphenyl ethers (PBDE) are present in the water in the Great Lakes. These chemicals are toxic when absorbed by the...
- C Computers and Technology Information that s been collected to help solve a problem is called?...
Ответ: