-
Notifications
You must be signed in to change notification settings - Fork 1
/
prog4.cpp
executable file
·301 lines (260 loc) · 7.7 KB
/
prog4.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
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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
#ifndef PROG4_CPP
#define PROG4_CPP
#include <iostream>
#include <string.h>
#include "global.h"
#include "binTree.h"
#include "item.h"
#include "binTree.cpp"
#include "store_functions.cpp"
#include "item.cpp"
bool debugRead = false;
void ReadData(Tree *cleanTree);
void instructions();
//void addStore(ItemPtr itPtr, StorePtr newStore);
//use mainly as a driver function
int main () //Author: Alexi
{
Tree *itemTree;
itemTree = new Tree();
/*
int testChoice;
instructions();
cin>>testChoice;
//driver test function
switch (testChoice)
{
case 0:
{
ItemPtr L1 = new Item("L1");
ItemPtr L2 = new Item("L2");
ItemPtr M2 = new Item("M2");
ItemPtr L2_2 = new Item("L2");
cout<<"Compare " << (L1->getName()) << " and " << (L2->getName()) <<": "<< L1->id_compare(L2) << endl; //should return -1
cout<<"Compare M2 and L2: "<< M2->id_compare(L2)<<endl; //should return 1
cout<<"Compare L2 and L2: "<< L2->id_compare(L2_2) <<endl; //should return 0
}
break;
case 1: //Test store_compare
cout << "store_compare test here\n";
{
Store s0 = {0,0,0, 4, NULL};
Store s1 = {1, 1, 1, 3, NULL};
Store s2 = {2, 2, 1, 3, NULL};
Store s3 = {1, 1, 1, 3, NULL};
cout<<"Compare 4 items and 3 items: "<<store_compare(&s0, &s1) << endl;
cout<<"Compare 3 items and 4 items: "<<store_compare(&s1, &s0)<<endl;
cout<<"Compare 3 items and 3 items (diff location): "<<store_compare(&s1, &s2)<<endl;
cout<<"Compare 3 items and 3 items (same location): "<<store_compare(&s1, &s3)<<endl;
}
break;
case 2: //test addItem. Seems to work fine
cout<<"\nTesting addItem\n";
{
ItemPtr L1 = new Item("L1");
ItemPtr L2 = new Item("L2");
ItemPtr M2 = new Item("M2");
ItemPtr L2_2 = new Item("L2");
ItemPtr A7 = new Item("A7");
ItemPtr S2 = new Item("S2");
Store s0 = {0,0,0, 4, NULL};
Store s1 = {1, 1, 1, 3, NULL};
Store s2 = {2, 2, 1, 3, NULL};
Store s3 = {1, 1, 1, 3, NULL};
cout << "Testing item:\n";
L1->printItem();
L2->printItem();
M2->printItem();
cout << "Adding to tree\n";
itemTree->addItem(L2, &s0);
cout<<"Added first successfully\n";
cout << "Printing Tree:\n\n";
itemTree->PrintTree();
itemTree->addItem(M2, &s1);
cout<<"Added second successfully\n";
cout << "Printing Tree:\n\n";
itemTree->PrintTree();
itemTree->addItem(L1, &s2);
cout<<"Added third successfully\n";
cout << "Printing Tree:\n\n";
itemTree->PrintTree();
itemTree->addItem(L2_2, &s3);
cout<<"Added fourth successfully\n";
cout << "Printing Tree:\n\n";
itemTree->PrintTree();
itemTree->addItem(A7, &s2);
cout<<"Added fourth successfully\n";
cout << "Printing Tree:\n\n";
itemTree->PrintTree();
itemTree->addItem(S2, &s2);
cout<<"Added fifth successfully\n";
cout << "Printing Tree:\n\n";
itemTree->PrintTree();
}
break;
case 3: //tests basic addStore
cout << "\nTesting addStore\n";
{
ItemPtr L1 = new Item("L1");
ItemPtr L2 = new Item("L2");
ItemPtr M2 = new Item("M2");
ItemPtr L2_2 = new Item("L2");
Store s0 = {0,0,0, 4, NULL};
Store s1 = {1, 1, 1, 5, NULL};
Store s2 = {2, 2, 1, 6, NULL};
Store s3 = {1, 1, 1, 7, NULL};
cout<<"Printing store list for L1:\n";
printStoreList((L1->getStores()));
cout << "Going to add following store\n";
printStore(&s0);
cout<<endl;
addStore(L1, &s0);
//cout<<"printing store list now"<<endl;
printStoreList(L1->getStores());
cout<<endl;
addStore(L1, &s1);
printStoreList(L1->getStores());
cout<<endl;
addStore(L1, &s2);
cout<<"printed third store"<<endl;
cout<<endl;
addStore(L1, &s3);
cout << "Printing store list\n";
printStoreList(L1->getStores());
}
break;
case 4: //tests addStore on tree
cout << "\nTesting addStore\n";
{
ItemPtr L1 = new Item("L1");
ItemPtr L2 = new Item("L2");
ItemPtr M2 = new Item("M2");
ItemPtr L2_2 = new Item("L2");
Store s0 = {0,0,0, 4, NULL};
Store s1 = {1, 1, 1, 3, NULL};
Store s2 = {2, 2, 1, 3, NULL};
Store s3 = {1, 1, 1, 6, NULL};
cout << "Adding " << L2->getName() << " and store\n";
printStore(&s0);
cout <<endl;
itemTree->addItem(L2, &s0);
cout<<"Added first successfully, item at root is:\n";
itemTree->getRoot()->printItem();
cout<<"Printing store list:\n";
printStoreList(((*itemTree).getRoot())->getStores());
cout<<endl;
cout << "Adding " << M2->getName() << " and store\n";
printStore(&s1);
cout <<endl;
itemTree->addItem(M2, &s1);
cout<<"Added second successfully\n";
cout<<"Printing store list:\n";
printStoreList(((*itemTree).getRoot())->getStores());
cout<<endl;
cout << "Adding " << L1->getName() << " and store\n";
printStore(&s2);
cout <<endl;
itemTree->addItem(L1, &s2);
cout<<"Added third successfully\n";
cout<<"Printing store list:\n";
printStoreList(((*itemTree).getRoot())->getStores());
cout<<endl;
cout << "Adding " << L2_2->getName() << " and store\n";
printStore(&s3);
cout <<endl;
itemTree->addItem(L2_2, &s3);
cout<<"Added fourth successfully\n";
cout<<"Printing store list:\n";
printStoreList(((*itemTree).getRoot())->getStores());
}
break;
case 5: //test readData
cout << "\nTesting ReadData\n";
{
ReadData(*itemTree);
cout << "Read Data completing properly:\n";
itemTree->PrintTree();
}
default:
cout<<"Improper or no test chosen\n";
break;
} */
//code for after testing is complete
ReadData(itemTree);
//cout << "Read Data completing properly:\n";
itemTree->PrintTree();
return 0;
}
void ReadData(Tree *cleanTree) //Author: Alexi
{
Tree tree = *cleanTree;
int Sentinel = 0, counter = 0, itemCount = 0;
string name;
Store tempStore;
while (Sentinel != 2) //Going to represent 16 16 16, need to rework logic slightly
{
int x, y, z, itemNumber;
x = 0;
y = 0;
z = 0;
itemNumber = 0;
//cout << "Reading in data\n";
cin>>x;
if (x==16)
Sentinel++;
cin>>y;
if (y==16)
Sentinel++;
cin>>z;
if (z==16)
Sentinel++;
if (Sentinel==3){
break;
} else {
Sentinel=0;
}
cin>>itemNumber;
for (counter = 0; counter < itemNumber; counter++)
{
name = " ";
itemCount = 0;
cin>>name;
cin>>itemCount;
StorePtr tempStorePtr = new Store();
tempStorePtr->x = x;
tempStorePtr->y = y;
tempStorePtr->z = z;
tempStorePtr->itemCount = itemCount;
tempStorePtr->nextStore = NULL;
//Store tempStore = *tempStorePtr;
ItemPtr tempItem = new Item(name);
if (debugRead){
cout << "\nPrinting temporary item and store\n";
tempItem->printItem();
printStore(tempStorePtr);
}
if (debugRead){
//tree.PrintTree();
cout << "Adding item:\n";
}
tree.addItem(tempItem, tempStorePtr);
//cout << "\n TREE \n";
//tree.PrintTree();
}
if (debugRead)
cout << "Printing tree:\n";
} //end for
//tree.PrintTree();
*cleanTree = tree;
} //end ReadData
void instructions() //Author: Alexi
{
cout <<"Choice of 0 currently tests: id_compare\n";
cout << "Choice of 1 currently tests: store_compare" << endl;
cout << "Choice of 2 currently tests: addItem and PrintTree\n";
cout << "Choice of 3 currently tests: addStore and printStores()\n";
cout << "Choice of 4 currently tests: addItem and addStore on tree\n";
cout << "Choice of 5 currently tests: ReadData()\n";
cout <<"Please enter a test choice:";
}
#endif