Write a function to insert a value into an array of 5 integers. The function sho
ID: 3645816 • Letter: W
Question
Write a function to insert a value into an array of 5 integers. The function should have a function header like:void arrayInsert(int theValue, int theOffset, int theArray[], int size)
The function should insert theValue into theArray in the element located at theOffset. However, you must first shuffle the values of the array down to make room for the new value in the array.
Note: The last value, (the one in the last element of the array) will drop off the end, and that is ok.
Your main() function should
intialize the array by setting all of its elements to 0,
print the elements of the array to the console
use a loop to:
prompt the user for positive integer values (-1 to stop) and an offset
call your function to insert it into the array.
print the elements of the array to the console
Example:
0,0,0,0,0
Please enter an integer to insert (0 to quit): 4
Please enter the offset: 2
0,0,4,0,0
Please enter an integer to insert (0 to quit): 8
Please enter the offset: 3
0,0,4,8,0
Please enter an integer to insert (0 to quit): 1
Please enter the offset: 0
1, 0,0,4,8
This is what I have so far:
void arrayInsert(int theValue, int theOffset, int theArray[4])
{
cout<< theArray[4];
int arrayInsert(int theValue, int theOffset, int theArray[4]);
{
}
int main()
{
int theValue = 0;
int theOffset = 0;
int theArray[] = {0,0,0,0,0};
arrayInsert(int theValue, int theOffset, int theArray[4]);
cout<< "Please enter an integer to insert: ";
cin>> theValue;
cout<< "Please enter the offset: ";
cin>> theOffset;
return 0;
}
Please help!
Explanation / Answer
this programme written in visual stodio if u hav tc software then delt the header file using namespace std; and #include "stdafx.h". #include "stdafx.h" #include #include using namespace std; void main () { int a[5]; int num,i,b=0,z; for(z=0;zRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.