-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathArray Update Delete.cpp
88 lines (65 loc) · 1.35 KB
/
Array Update Delete.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main() {
int i, size;
int* arrAge;
cout<<"Enter the size of the array: "<<endl;
cin>>size;
arrAge = new int[size];
srand(time (0));
for (i=0; i<size; i++)
{
cout<<"Enter the"<<i<<" Age:"<<endl;
cin>>arrAge[i];
cout<<arrAge[i]<<" girilen "<<endl;
}
cout<<"if you want to delete the index of the element = 1 "<<endl;
cout<<"else updated the array= 2"<<endl;
int control=0;
cin>>control;
if(control==1)
{
cout<<"How many elements to be deleted=";
int control2;
cin>>control2;
int size2=size-control2;
int* arrAge2;
arrAge2 = new int[size2]; // new array created
int i=0;
if(control2<size)
{
arrAge2 = new int[size2];
for(int j=0;j<size2;j++)
{
arrAge2[j]=arrAge[j];
}
for(int k=0;k<size2;k++)
{
cout<<"New Array: "<<arrAge2[k]<<endl;
}
}
}else if(control==2)
{
cout<<"How many elements to be updated=";
int control2;
cin>>control2;
int size2=size+control2;
int* arrAge2;
arrAge2 = new int[size2]; // new array created
for(int k=control2;k=0;k--)
{
cout<<"Enter the new array elements= ";
int neweleman;
cin>>neweleman;
arrAge2[size2-k]=neweleman;
}
for(int k=0;k<size2;k++)
{
cout<<"New Array: "<<arrAge2[k]<<endl;
}
}
delete [] arrAge;
return 0;
}