Alg 11: Delete all instances of \'g\' from a list stored within the array a. Ass
ID: 3664494 • Letter: A
Question
Alg 11: Delete all instances of 'g' from a list stored within the array a.
Assume the following declarations:
char a[100]; int aSize=32; char ch;
Assume also that the first 32 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 31. The phrase last element in the list refers to the element found in 'a[31]'. 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 11: Delete all instances of 'g' from a list stored within the array a.
use c++
Explanation / Answer
#include<iostream>
using namespace std;
int main()
{
char a[100]={'s','a','n','d','e','e','p','g','s','a','n','d','e','e','p','g','s','a','n','d','e','e','p','g','s','a','n','d','e','e','p','g'};
int aSize=32;
char ch;
for(int i=0;i<aSize;i++){
ch=a[i];
if(ch == 'g'){
for(int j=i;j<32;j++){
a[j]=a[j+1];
}
}
}
cout << a << ' ';
}
output -
sandeepsandeepsandeepsandeep
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.