#include <iostream>
#include <string>
using namespace std;
int main()
{
int* originalArray;
int* copyArray;
int size;
int index=0;
int copyArrayCounter=0;
//ge size of the aray
cout<<"Enter size: ";
cin>>size;
originalArray=new int[size];
copyArray=new int[size];
for(int i=0;i<size;i++){
cout<<"Enter the element "<<i<<": ";
cin>>originalArray[i];
}
while(index!=-1 && size!=0){
index=-1;
cout<<"Enter index of the element to copy [0-"<<(size-1)<<"]: ";
cin>>index;
if(index>=0 && index<size){
copyArray[copyArrayCounter]=originalArray[index];
copyArrayCounter++;
cout<<"The element "<<originalArray[index]<<" has been deleted from the original array\n";
for(int i=index;i<size-1;i++){
originalArray[i]=originalArray[i+1];
}
size--;
cout<<"\nAll elements in the original array:\n";
for(int i=0;i<size;i++){
cout<<originalArray[i]<<" ";
}
cout<<"\n";
}
}
cout<<"All elements in the copy array:\n";
for(int i=0;i<copyArrayCounter;i++){
cout<<copyArray[i]<<" ";
}
//Free memory
delete[] originalArray;
delete[] copyArray;
cin>>index;
return 0;
}
Comments
Leave a comment