9.12: Element Shifter C++Write a function that accepts an int array and the array’s size as arguments. The function should create a new array that is one element larger than the argument array. The first element of the new array should be set to 0. Element 0 of the argument array should be copied to element 1 of the new array, element 1 of the argument array should be copied to element 2 of the new array, and so forth. 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 element shifter function, and prints the values of the new expanded and shifted array on standard output, one value per line. You may assume that the file data  has at least N  values. Prompts And Output Labels. There are no prompts for the integer and no labels for the reversed array that is printed out. Input Validation. If the integer read in from standard input exceeds 50 or is less than 0 the program terminates silently.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter12: Points, Classes, Virtual Functions And Abstract Classes
Section: Chapter Questions
Problem 23SA
icon
Related questions
Question

9.12: Element Shifter C++
Write a function that accepts an int array and the array’s size as arguments. The function should create a new array that is one element larger than the argument array. The first element of the new array should be set to 0. Element 0 of the argument array should be copied to element 1 of the new array, element 1 of the argument array should be copied to element 2 of the new array, and so forth. 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 element shifter function, and prints the values of the new expanded and shifted array on standard output, one value per line. You may assume that the file data  has at least N  values.

Prompts And Output Labels. There are no prompts for the integer and no labels for the reversed array that is printed out.

Input Validation. If the integer read in from standard input exceeds 50 or is less than 0 the program terminates silently.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 4 images

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question
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 displays the values of the new expanded array, 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.
Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
Functions
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning