Respuesta :
The Element shifter program illustrates the use of functions and arrays
- Arrays are used to hold multiple values
- Functions are used as subroutines of a program
The Element shifter program
The Element shifter program written in C++, where comments are used to explain each action is as follows:
#include <iostream>
using namespace std;
//This declares the ElementShifter function
int* ElementShifter(int *arr, int size){
//This declares the new array
int *newArr = new int[size * 2];
//The following loop populates the new array
for (int i = 0; i < size * 2; i++) {
if(i == 0){
*(newArr+i) = 0;
}
else if(i < size+1){
*(newArr+i) = *(arr+i-1);
}
else{
*(newArr+i) = 0;
}
}
//This returns a pointer to the new array
return newArr;
}
//The main method begins here
int main(){
//This declares and gets input for N
int N; cin>>N;
int myArr[N];
//If N is between 1 and 50
if(N > 0 && N <=50){
//This populates the array
for(int i = 0; i<N; i++){
cin>>myArr[i];
}
//This calls the Element shifter function
int *ptr = ElementShifter(myArr, N);
//This prints the new array
for (int i = 0; i < N*2; i++) {
cout << ptr[i] << " ";
}
}
return 0;
}
Read more abou C++ programs at:
https://brainly.com/question/27246607