-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
230 lines (211 loc) · 6 KB
/
main.cpp
File metadata and controls
230 lines (211 loc) · 6 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
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
#include <iostream>
#include "database.h"
using std::string;
using std::cout;
using std::endl;
using std::cin;
Array* makeArray(Array* array)
{
string array_type;
int size;
cout << "value: type (int, double, string, array): ";
cin >> array_type;
cout << "size: ";
cin >> size;
if (array_type == "int")
{
int* arr = new int[size];
for(int i = 0; i < size; i++)
{
int item;
cout << "item[" << i << "]: ";
cin >> item;
*(arr + i) = item;
}
cout << endl;
array->size = size;
array->type = Type::INT;
array->items = arr;
}
else if (array_type == "double")
{
double* arr = new double[size];
for(int i = 0; i < size; i++)
{
double item;
cout << "item[" << i << "]: ";
cin >> item;
*(arr + i) = item;
}
cout << endl;
array->size = size;
array->type = Type::DOUBLE;
array->items = arr;
}
else if (array_type == "string")
{
cin.ignore();
string* arr = new string[size];
for(int i = 0; i < size; i++)
{
string item;
cout << "item[" << i << "]: ";
getline(cin, item);
*(arr + i) = item;
}
cout << endl;
array->size = size;
array->type = Type::STRING;
array->items = arr;
}
else if (array_type == "array")
{
Array* arr = new Array[size];
array->size = size;
array->type = Type::ARRAY;
for(int i = 0; i < size; i++)
{
Array* item = new Array;
cout << "item[" << i << "]: ";
item = makeArray(item);
*(arr + i) = *item;
}
array->items = arr;
}
return array;
}
// ** 중요 ** 수정해야할 부분
// 이중배열 출력할 때 첫번째 배열의 값이 마지막 배열의 값으로 출력된다
// 첫번째 배열의 값이 제대로 출력되게끔 수정해야함
int main()
{
Database db;
init(db);
int i = 0;
while(true)
{
string answer;
cout << "command (list, add, get, del, exit): ";
cin >> answer;
if (answer == "exit")
{
destroy(db);
break;
}
else if (answer == "add")
{
Entry* en = new Entry;
string key, type;
cout << "key: ";
cin >> key;
cout << "type (int, double, string, array): ";
cin >> type;
while (true)
{
if (type == "int")
{
int* i_value = new int;
cout << "value: ";
cin >> *i_value;
cout << endl;
en = create(Type::INT, key, i_value);
break;
}
else if (type == "double")
{
double* d_value = new double;
cout << "value: ";
cin >> *d_value;
cout << endl;
en = create(Type::DOUBLE, key, d_value);
break;
}
else if (type == "string")
{
string* s_value = new string;
cout << "value: ";
cin.ignore();
getline(cin, *s_value);
cout << endl;
en = create(Type::STRING, key, s_value);
break;
}
else if (type == "array")
{
Array* reArray = new Array;
reArray = makeArray(reArray);
en = create(Type::ARRAY, key, reArray);
break;
}
else
{
cout << endl;
cout << "Error: no such your command :(" << endl;
cout << endl;
}
}
add(db, en);
}
else if (answer == "list")
{
showAll(db);
cout << endl;
}
else if (answer == "get")
{
Entry* getting;
string whatGet;
cout << "key: ";
cin >> whatGet;
getting = get(db, whatGet);
while (true)
{
if (getting->type == INT)
{
cout << getting->key << ": " << *(int *)getting->value << endl;
break;
}
else if (getting->type == STRING)
{
cout << getting->key << ": \"" << *(string *)getting->value << "\"" << endl;
break;
}
else if (getting->type == DOUBLE)
{
cout << getting->key << ": " << *(double *)getting->value << endl;
break;
}
else if (getting->type == ARRAY)
{
cout << getting->key << ": ";
printArray((Array *)getting->value);
cout << endl;
break;
}
else
{
cout << endl;
cout << "Error: no such your command :(" << endl;
cout << endl;
}
cout << endl;
}
cout << endl;
}
else if (answer == "del")
{
string whatDel;
cout << "key: ";
cin >> whatDel;
remove(db, whatDel);
cout << endl;
}
// if (answer != "exit" && answer != "add" && answer != "list" && answer != "get" && answer != "del")
else
{
cout << endl;
cout << "Error: no such your command :(" << endl;
cout << endl;
}
}
}