-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproj2.cpp
More file actions
340 lines (255 loc) · 9.82 KB
/
proj2.cpp
File metadata and controls
340 lines (255 loc) · 9.82 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
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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
/*
NAME: BRIAN MAYESHIRO
HOMEWORK: PROJECT 2
CLASS: ICS212
INTRUCTOR: RAVI NARAYAN
DATE: November 21 2015
FILE: proj2.cpp
DESCRIPTION: This file contatins the main function along with the user
interface and debug mode which aids in debugging this program.
*/
#include <iostream>
#include <string>
using namespace std;
#include "record.h"
#include "llist.h"
/* prototypes */
void getfield(char[], char[], int*, char[]);
void modifyfield(char[], char[], char[]);
/*
Function name: getfield
DESCRIPTION: This function obtains the information from the user. Gets the
Name, address, year of
birth, and tel number.
Parameters: name[] (char): The name being entered in from the user
address[] (char): the address being entered in from the user
*yobba(int pointer): integer for yearofbirth entered from user
that modifies yearorbirth in main.
telNumber[] (char): the telNumber being entered in from the user
Return values: void
*/
void getfield(char name[], char address[], int *yobba, char telNumber[])
{
char yearofbirth[5];
char buffer[50];
#ifdef DEBUG
cout << "**DEBUG**Entering name" << endl;
#endif
cout << "Please enter the Name: " << endl;
cin.getline(name, 25, '\n');
#ifdef DEBUG
cout << "**DEBUG**The name is: " << name << endl;
cout << "**DEBUG**Entering yob" << endl;
#endif
cout << "Please enter the year of birth: " << endl;
cin.getline(yearofbirth, 5, '\n');
*yobba = atoi(yearofbirth);
#ifdef DEBUG
cout << "**DEBUG**the yob is: " << *yobba << "\n\n";
cout << "**DEBUG**Entering Address" << endl;
#endif
cout << "Please Enter the address (Press TAB and ENTER when done): \n";
cin.getline(address, 80, '\t');
#ifdef DEBUG
cout << "**DEBUG**The Address is: " << endl;
cout << address;
cout << "\n";
cout << "**DEBUG**Entering phone number " << endl;
#endif
cout << "Please Enter the telephone number: " << endl;
cin.getline(buffer, 50);
cin.getline(telNumber, 15);
#ifdef DEBUG
cout << "**DEBUG**The telNumber is: " << telNumber << "\n" << endl;
#endif
}
/*
Function name: modifyfield
DESCRIPTION: This function obtains the information from the user. Gets the
Name, address, and tel number for modification of the record in modifyRecord.
Parameters: name[] (char): The name being entered in from the user
address[] (char): the address being entered in from the user
telNumber[] (char): the telNumber being entered in from the user
Return values: void
*/
void modifyfield(char name[], char address[], char telNumber[])
{
char yearofbirth[5];
char buffer[50];
#ifdef DEBUG
cout << "**DEBUG**Entering name" << endl;
#endif
cout << "Please enter the Name: " << endl;
cin.getline(name, 25, '\n');
#ifdef DEBUG
cout << "**DEBUG**The name is: " << name << endl;
#endif
cout << "Please Enter the address (Press TAB and ENTER when done): " << endl;
cin.getline(address, 80, '\t');
#ifdef DEBUG
cout << "**DEBUG**The Address is: ";
cout << address;
cout << "\n";
cout << "**DEBUG**Entering phone number " << endl;
#endif
cout << "Please Enter the telephone number: " << endl;
cin.getline(buffer, 50);
cin.getline(telNumber, 15);
#ifdef DEBUG
cout << "**DEBUG**The telNumber is: " << telNumber << "\n" << endl;
#endif
}
/*
FUNCTION NAME: main
DESCRIPTION: My main function for the user interface, to be used by the
user
PARAMETERS: argc (int): contains the number of arguments to be passed.
*argv[] (char): contains the array of arguments
RETURN VALUES: void
*/
int main()
{
llist mylist;
int yearofbirth = 0;
char name[25];
char address[80];
char telNumber[15];
char command[20];
int status = 0, result = 0;
#ifdef DEBUG
cout << "**DEBUG**Readfile was called on 'readtest.txt'\n";
#endif
cout << "Hello!\n";
cout << "This program is a Record Database for Addresses. \n";
do
{
cout << "\nPlease enter a Command: \n";
cin.getline(command, sizeof(command));
cout << "\n";
if(strcmp(command, "add") == 0)
{
cout << "Please add an address (Include Name, Year of Birth, Address, and Phone Number): " << endl;
getfield(name, address, &yearofbirth, telNumber);
mylist.addRecord(name, address, yearofbirth, telNumber);
cout << "Record has been added" << endl;
#ifdef DEBUG
cout << "******** DEBUG ************\n";
cout << "**DEBUG**addRecord function was called with the parameters: \n\t" << name << " \n\t" << address << " \n\t" << yearofbirth << " \n\t" << telNumber << endl;
cout << "**DEBUG**The year of birth is: " << yearofbirth << endl;
#endif
cout << "\n";
}
else if(strcmp(command, "modify") == 0)
{
cout << "Please enter the name of the record you wnat to modify: " << endl;
modifyfield(name, address, telNumber);
result = mylist.modifyRecord(name, address, telNumber);
if(result == -1)
{
cout << "The list is empty" << endl;
}
else if(result == 1)
{
cout << "Record does not exist, nothing to modify" << endl;
}
else
{
cout << "Record has been modified" << endl;
}
#ifdef DEBUG
cout << "******** DEBUG ************\n";
cout << "**DEBUG**modifyRecord function was called with the parameters: " << name << " " << address << " " << telNumber;
#endif
cout << "\n";
}
else if(strcmp(command, "print") == 0)
{
cout << "Please enter the name of the record you want to print: ";
cin.getline(name, sizeof(name));
result = mylist.printRecord(name);
if(result == -1)
{
cout << "The list is empty " << endl;
}
else if(result == 1)
{
cout << "Name not found" << endl;
}
#ifdef DEBUG
cout << "******DEBUG********\n";
cout << "**DEBUG**print function was called with the parameter: " << name << endl;
#endif
}
else if(strcmp(command, "printall") == 0)
{
cout << "Printing all information in the database..." << endl;
cout << mylist;
cout << endl;
#ifdef DEBUG
cout << "******** DEBUG ************\n";
cout << "**DEBUG**printAllRecords was executed" << endl;
cout << "**DEBUG**printAllRecords function was called" << endl;
#endif
}
else if(strcmp(command, "delete") == 0)
{
cout << "Please enter the name of the record you would like to delete: ";
cin.getline(name, sizeof(name));
result = mylist.deleteRecord(name);
if(result == -1)
{
cout << "List is empty, nothing to delete " << endl;
}
else if(result == 1)
{
cout << "Name not found" << endl;
}
else
{
cout << "Record(s) deleted" << endl;
}
#ifdef DEBUG
cout << "******** DEBUG ************\n";
cout << "**DEBUG**deleteRecord function was called with the parameter: " << name << endl;
#endif
cout << "\n";
}
else if(strcmp(command, "reverse") == 0)
{
#ifdef DEBUG
cout << "**DEBUG**" << endl;
cout << "**DEBUG**reversing the list" << endl;
#endif
mylist.reverse();
cout << "List has been reversed" << endl;
}
else if(strcmp(command, "quit") == 0)
{
cout << "BYE! \n";
#ifdef DEBUG
cout << "**DEBUG**writefile called" << endl;
cout << "**DEBUG**Cleaning up the linked list" << endl;
#endif
status = 1;
#ifdef DEBUG
cout << "******** DEBUG ************\n";
cout << "**DEBUG**EXITING THE PROGRAM\n";
#endif
}
else
{
cout << "Please enter an appropriate command:\n\n";
cout << "add\n";
cout << "print\n";
cout << "modify\n";
cout << "printall\n";
cout << "delete\n";
cout << "reverse\n";
cout << "quit (to exit out of the program)\n\n";
}
}while(!status);
#ifdef DEBUG
cout << "**END OF DEBUG**\n";
#endif
return 0;
}