-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharray in cpp
120 lines (99 loc) · 2.42 KB
/
array in 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#include <iostream>
#include <string.h>
using namespace std;
class array{
//int size;
//int arr[size]={};
public:
int size;
array(){
size =10;
}
array(int x){
size = x;
}
int arr[size]={};
void input(){
for (int i = 0; i < size; i++)
{
cout << endl;
cout << "Enter " << i << " element ";
cin >> arr[i];
}
}
void traversal(){
for (int i = 0; i < size; i++)
{
cout << arr[i] << " ";
}
}
void insert(int pos, int element){
for (int i = size; i < size-pos; i--)
{
arr[i]=arr[i+1];
}
arr[pos]=element;
}
void del(int pos){
for (int i = pos; i < size-1; i++)
{
arr[i]= arr[i+1];
}
}
};
int func(){
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){
int a;
//cout << "Do you want to perform operations so enter 9";
cin >> a;
array g(a);
while (true)
{
int n;
n = func();
if (n==1)
{
g.input();
continue;
}
if (n==2)
{
g.traversal();
cout << endl;
}
if (n==3)
{
int pos,element;
cout << "Enter position : ";
cin >> pos;
cout << "Enter element : ";
cin >> element;
g.insert(pos,element);
}
if (n==4)
{
/* code */
int poss;
cout << "Enter position : ";
g.del(poss);
}
if(n==0)break;
}
}
//problem
/*fix output after traversel
enter documentation
use a string comparison*/