-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestDrivercpp.cpp
More file actions
188 lines (160 loc) · 4.67 KB
/
testDrivercpp.cpp
File metadata and controls
188 lines (160 loc) · 4.67 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
#include<iostream>
#include <string>
#include "armor.h"
#include "Hash.h"
#include "List.h"
#include <fstream>
using namespace std;
void insertHashManager(Hash &H);
void deleteHashManager(Hash &H);
void searchHashManager(Hash &H, void visit(Armors *));
void inputValid(string &returnItem);
void display(Armors *a);
void fileInput(string filename, Hash &H);
//
void display(Armors *a) {
cout << "I am in display func\n";
cout << a->getCodeName() << " " << a->getYear() << endl;
cout << "--------------------------------------------------------------------------" << endl;
cout << a->getCodeName() << ":" << a->getArmorType() << "\nMade by: " << a->getCreator() << " in " << a->getYear()
<< "\nUsers: " << a->getUser() << ", appeared in: " << a->getMovie() << "\nCurrent Status: " << a->getStatus()
<< "\nArmor Capabilities: " << a->getCap() << "\nWeapons: " << a->getWeapon()
<< "\nPrecede: " << a->getPre() << "\tSucceed: " << a->getSuc();
cout << "\n--------------------------------------------------------------------------" << endl;
}
int main() {
/*armor *A= new armor;
Hash H(1);
H.insertItem(A);
armor* A1 = new armor;
H.searchByP("Sneaky", A1);
string del = "Sneaky";
H.deleteItem(del);
H.stat();*/
string fileName = "armors.txt";
Hash H(79);
fileInput(fileName, H);
H.stat();
insertHashManager(H);
searchHashManager(H,display);
deleteHashManager(H);
H.printHash(display);
return 0;
}
void insertHashManager(Hash &H) {
string targetName = "";
Armors *A = new Armors;
Armors *A2 = new Armors;
A2->setCodeName("");
cout << "\n Insert\n";
cout << "=======\n";
while (A2->getCodeName() != "Q")
{
cout << endl << "Enter an armor name to insert (or Q for stop inserting):";
getline(cin, targetName);
A2->setCodeName(targetName);
cout << endl;
if (A2->getCodeName() != "Q")
{
if (H.searchHash(A2, A))
cout << "Armor " << targetName << " is already in this Hash Table.";
else {
cout << "Enter the information of the Armor" << endl;
A->setCodeName(targetName);
getline(cin, A);
if (H.insertItem(A))
cout << "\nInserted" << endl;
}
}
}
cout << endl;
cout << "___________________END INSERT SECTION _____\n";
}
void deleteHashManager(Hash &H) {
string targetName = "";
int n = 0;
cout << "\n Delete\n";
cout << "=======\n";
while (targetName != "Q")
{
cout << endl << "Enter an armor name for delete (or Q for stop searching): ";
getline(cin, targetName);
if (targetName != "Q")
{
if (H.deleteItem(targetName))
cout << "Deleted\n";
else
cout << "Armor " << targetName << " was not found in this Hash Table." << endl;
}
}
cout << "___________________END DELETE SECTION_____\n";
}
void searchHashManager(Hash &H, void visit(Armors *) ){
string key = "";
string sKey = "";
Armors *A;
Armors *A2;
A = new Armors;
A2 = new Armors;
cout << "\n Search\n";
cout << "=======\n";
do
{
cout << "\nEnter a primary key for search (or Q for stop searching): ";
getline(cin, key);
if (!cin.good())
inputValid(key);
A2->setCodeName(key);
cout << endl;
if (A2->getCodeName() != "Q") {
if (!H.searchHash(A2, A))
cout << "Armor " << key << " was not found in this Hash Table.\n";
else
visit(A);
}
} while (key != "Q");
cout << endl;
cout << "___________________END SEARCH SECTION _____\n";
}
void inputValid(string &returnItem) {
string val;
do {
cout << "Your input is invalid\n" << "Please input integer to search\n";
cin.clear();
cin.ignore(INT_MAX, '\n');
getline(cin, val);
} while (!cin.good());
returnItem = val;
}
void fileInput(string filename, Hash &H)
{
ifstream infile(filename);
string codename, type, creator, movie, curstat, precede, succeed, users, capbl, weap,space;
int year = 0;
if (!infile) {
cout << "Error happened to open the input file!" << endl;
exit(EXIT_FAILURE);
}
// READING THE FILE AND DECLARE TO RESPECTICE VARIABLE
//======================================================
while (getline(infile, codename, ';'))
{
getline(infile, type, ';');
getline(infile, creator, ';');
infile >> year;
infile.ignore();
getline(infile, users, ';');
getline(infile, movie, ';');
getline(infile, curstat, ';');
getline(infile, capbl, ';');
getline(infile, weap, ';');
getline(infile, precede, ';');
getline(infile, succeed, ';');
Armors *armors;
armors = new Armors(codename, type, creator, year, users, movie, curstat, capbl, weap, precede, succeed);
H.insertItem(armors);
cout << "Inserted\n";
getline(infile, space);
}
infile.close();
}