You need to write a function named shiftX. The function is described below: shiftX: takes an int array, the array's size, and an integer value (x) as arguments. The function should create a new array that is x elements larger than the argument array. The first x elements of the new array should be set to -1. The remaining elements should contain the elements from the original array in the original order. The function should return a pointer to the new array. Note: If a negative integer is passed as a parameter instead of the array's size, the function should return NULL (or nullptr). Use the main function to demonstrate your function. Assume the input will be a sequence of numbers, the first number will be the size of an array, followed by the elements of the array, and the last number will be integer value (x). Input the values in the array and call shiftX on it. Output the resultant array of the call shiftX. Ex.: If the input is 4 1 2 3 4 3 the output should be -1 -1 -1 1 2 3 4 If the input is 8 4 2 7 1 6 3 8 55 the output should be -1 -1 -1 -1 -1 4 2 7 1 6 3 8 5

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter10: Pointers
Section10.3: Pointer Arithmetic
Problem 3E
icon
Related questions
Question

In C++, please and thank you!

You need to write a function named shiftX. The function is described below:
shiftX: takes an int array, the array's size, and an integer value (x) as arguments. The function should create a new array that is x elements
larger than the argument array. The first x elements of the new array should be set to -1. The remaining elements should contain the
elements from the original array in the original order. The function should return a pointer to the new array.
Note: If a negative integer is passed as a parameter instead of the array's size, the function should return NULL (or nullptr).
Use the main function to demonstrate your function. Assume the input will be a sequence of numbers, the first number will be the size of
an array, followed by the elements of the array, and the last number will be integer value (x). Input the values in the array and call shiftX on it.
Output the resultant array of the call shiftX.
Ex.: If the input is
4 1 2 3 4 3
the output should be
-1 -1 -1 1 2 3 4
If the input is
8 4 2 7 1 6 3 8 5 5
the output should be
-1 -1 -1 -1 -1 4 2 7 1 638
85
Transcribed Image Text:You need to write a function named shiftX. The function is described below: shiftX: takes an int array, the array's size, and an integer value (x) as arguments. The function should create a new array that is x elements larger than the argument array. The first x elements of the new array should be set to -1. The remaining elements should contain the elements from the original array in the original order. The function should return a pointer to the new array. Note: If a negative integer is passed as a parameter instead of the array's size, the function should return NULL (or nullptr). Use the main function to demonstrate your function. Assume the input will be a sequence of numbers, the first number will be the size of an array, followed by the elements of the array, and the last number will be integer value (x). Input the values in the array and call shiftX on it. Output the resultant array of the call shiftX. Ex.: If the input is 4 1 2 3 4 3 the output should be -1 -1 -1 1 2 3 4 If the input is 8 4 2 7 1 6 3 8 5 5 the output should be -1 -1 -1 -1 -1 4 2 7 1 638 85
Expert Solution
steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
Arrays
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++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
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
Programming with Microsoft Visual Basic 2017
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:
9781337102124
Author:
Diane Zak
Publisher:
Cengage Learning
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage