Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Alg 4: Insert \'x\' before element at position 3 of the list stored within the a

ID: 3664497 • Letter: A

Question

Alg 4: Insert 'x' before element at position 3 of the list stored within the array a. Assume the following declarations: char a[100]; int aSize=24; char ch; Assume also that the first 24 elements have been initialized to some values and the remaining elements have garbage in them. In the question below the term list stored within the array a means the elements found from position 0 to position 23. The phrase last element in the list refers to the element found in 'a[23]'. The phrase element at position n, refers to the n-th element of a list, which is stored in 'a[n-1]'. If you add or delete anything from the array, make sure you adjustaSize approriately. Alg 4: Insert 'x' before element at position 3 of the list stored within the array a. USE C++

Explanation / Answer

#include<iostream.h>

#include<conio.h>

void main()

{

char a[100];

int aSize=24;

char ch;

int i;

cout<<”enter the elements of array”;

for(i=0;i<=aSize;i++)

{

cin>>a[i];

}

cout<<”enter the element to insert”;

cin>>ch;

a[2]=x;

for(i=3;i<=aSize;i++)

{

a[i]=a[i-1];

}

for(i=0; i<=aSize;i++)

{

Cout<<” “<<a[i];

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote