-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharray_minimal
95 lines (82 loc) · 2.21 KB
/
array_minimal
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include <iostream>
using namespace std;
#define max 100
class array{
int array[max]={};
int p;
public:
int input(){
cout << "Enter the size of the array : ";
cin >> p;
return p;
}
//inputs
void inputs(int x){
for (int i = 0; i < x; i++)
{
int k;
cout << "Enter the "<<i<<" element."<<endl;
cin >> k;
array[i]=k;
}
}
//traversal
void traversal(){
for (int i = 0; array[i]; i++)
{
cout << array[i]<<endl;
}
}
//delete
void del(int loc){
for (int i = loc; array[i]; i++)
{
/* code */
array[i]=array[i+1];
}
}
void replace(int loc,int element){
array[loc]=element;
}
};
int menu(){
int x;
cout << "*___________________________________________________*"<< endl;
cout << "|choice | description|" << endl;
cout <<"|_____ 1 _____|Input elements in the array. |"<< endl;
cout <<"|_____ 2 _____|Traversal the array. |"<<endl;
cout << "|_____ 3 _____|Insert the element in the array. |"<<endl;
cout << "|_____ 4 _____|Delete an element in the array. |"<<endl;
cout << "|_____ 0 _____|Exit the program. |"<<endl;
cout << "*---------------------------------------------------*"<< endl;
cout <<" CHOICE: ";
cin >> x;
return x;
}
int main(void){
array a;
int g = a.input();
while (true)
{
int n = menu();
if(n==1){
a.inputs(g);
}
if(n==2)a.traversal();
if(n==3){
int loc,el;
cout << "Enter loc : " ;
cin >>loc;
cout <<endl<< "Enter element : " ;
cin >> el;
a.replace(loc,el);
}
if(n==4){
int lo;
cout << "Enter the location ";
cin >> lo;
a.del(lo);
}
if(n==0)break;
}
}