-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharrays.cpp
More file actions
78 lines (78 loc) · 1.35 KB
/
Copy patharrays.cpp
File metadata and controls
78 lines (78 loc) · 1.35 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
75
76
77
78
#include<iostream>
using namespace std;
class array
{
int arr[10],k;
public:
void create();
void display();
void insert();
void remove();
};
void array::create()
{
cout<<"enter the size of array\n";
cin>>k;
for(int i=0;i<k;i++)
{
cin>>arr[i];
}
}
void array::display()
{
for(int i=0;i<k;i++)
{
cout<<"\t"<<arr[i];
}
cout<<"\n";
}
void array::insert()
{
int item1,loc1;
cout<<"enter the element to be inserted with location\n";
cin>>item1>>loc1;
for(int i=k;i>loc1;i--)
{
arr[i]=arr[i-1];
}
for(int i=0;i<k+1;i++)
{
if(i==loc1)
arr[i]=item1;
}
k=k+1;
}
void array::remove()
{
int item2,loc2;
cout<<"enter the element to be deleted with location\n";
cin>>item2>>loc2;
for(int i=loc2;i<k;i++)
{
arr[i]=arr[i+1];
}
k=k-1;
}
int main()
{
array a;
int n;
option: cout<<"enter the number against the menu to avail that service\n1. creating an array\n2. displaying array elements\n3. inserting an element in a particular location\n4. deleting an element in particular location\n5. exit\n";
cin>>n;
switch(n)
{
case 1: a.create();
goto option;
case 2: a.display();
goto option;
case 3: a.insert();
goto option;
case 4: a.remove();
goto option;
case 5: cout<<"exit\n";
break;
default: cout<<"invalid option";
break;
}
return 0;
}