-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArray All Operations.cpp
More file actions
74 lines (74 loc) · 1.55 KB
/
Array All Operations.cpp
File metadata and controls
74 lines (74 loc) · 1.55 KB
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
74
#include <iostream>
using namespace std;
int *arr,s; //declaring array globally so every function can use it without passing parameters
void update(){
int i,n;
cout<<"\nEnter element to be updated in array : ";cin>>n;
for(i=0;i<s;i++)
{
if(arr[i]==n)
{
cout<<"\nEnter New Value to update : ";cin>>arr[i];
cout<<"\nUpdate Complete ";
break;
}
}
if(i==s)
cout<<"\n"<<n<<" not found !!!";
}
void Delete(){//func will search for element and then assign 0 value at its position
int n,i;
cout<<"\nEnter element to be deleted in array : ";cin>>n;
for( i=0;i<s;i++)
{
if(arr[i]==n)
{
arr[i]=0;
cout<<"\nElement deleted ";
break;
}
}
if(i==s)
cout<<"\n"<<n<<" not found !!!";
}
void search(){
int i,n;
cout<<"\nEnter element to search in array : ";cin>>n;
for(i=0;i<s;i++)
{
if(arr[i]==n)
{
cout<<"\n"<<arr[i]<<" Found at "<<i<<"th index. ";
break;
}
}
if(i==s)
cout<<"\n"<<n<<" not found !!!";
}
void display(){
cout<<"\nArray : ";
for(int i=0;i<s;i++)
cout<<arr[i]<<" ";
}
int main() {
int ch; //ch-take user's choice
cout<<"\nEnter Array Size : ";cin>>s;
arr=new int(s);
cout<<"\nEnter Array Elements : ";
for(int i=0;i<s;i++){
cin>>arr[i];
}
do{
cout<<"\n~~~\tMENU\t~~~\n1.Update\t2.Delete\t3.Search\t4.Display\t5.Exit\nEnter your choice";
cin>>ch;
switch(ch){
case 1:update();break;
case 2:Delete();break;
case 3:search();break;
case 4:display();break;
case 5:cout<<"\n~~~ THANK YOU ~~~";break;
defult:cout<<"\nInvalid Choice !!! Re-Enter Choice ";break;
}
}while(ch!=5);
return 0;
}