-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
277 lines (252 loc) · 7.36 KB
/
main.cpp
File metadata and controls
277 lines (252 loc) · 7.36 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
/******************************************************************************
//
// NAME: Blake Larson
//
// HOMEWORK: Project2
//
// CLASS: ICS 212
//
// INSTRUCTOR: Ravi Narayan
//
// DATE: November 29, 2016
//
// FILE: main.c
//
// DESCRIPTION: This is the main function that uses a user-interface
// for a bank database application. All functions are
// in seperate files, but this is strictly menu based.
//
*****************************************************************************/
#include "header.h"
int main(int argc, char* argv[])
{
int option, optionRev, accnum, nameloop, birthyear;
char accname[100], address[100], nextline[2];
// Make an instance of the llist class
llist mylist("proj2.txt");
option = 0;
optionRev = 0;
accnum = 0;
nameloop = 0;
birthyear = 0;
// Next two lines needed because cin.getline doesn't take in the newline.
// So we need to apend them after each call to the function.
nextline[0] = '\n';
nextline[1] = '\0';
cout << "------------------------------------------" << endl;
cout << "-Welcome to the Bank Database Application-" << endl;
cout << "------------------------------------------" << endl;
#ifdef DEBUGMODE
{
cout << "******************************************" << endl;
cout << "***************DEBUG MODE*****************" << endl;
cout << "******************************************" << endl;
cout << "" << endl;
}
#endif
while (option == 0)
{
cout << "------------------------------------------" << endl;
cout << "------------------MENU--------------------" << endl;
cout << "+----------------------------------------+" << endl;
cout << "| 1) Add a new record |" << endl;
cout << "| 2) Modify a record |" << endl;
cout << "| 3) Print a record |" << endl;
cout << "| 4) Print all the records |" << endl;
cout << "| 5) Delete a record |" << endl;
cout << "| 6) Reverse all records |" << endl;
cout << "| 7) Quit Program |" << endl;
cout << "+----------------------------------------+" << endl;
cout << "" << endl;
cout << "Please enter an option" << endl;
// Set of commands and assignment statements.
// 1) Clear the buffer after taking in input.
// 2) Resetting the value of common variable, for security purposes.
cin >> option;
cin.clear();
cin.ignore(100000, '\n');
accnum = 0;
memset(accname, 0, 100);
memset(address, 0, 100);
birthyear = 0;
nameloop = 0;
switch (option)
{
case 1 :
cout << "------------Option 1 selected-------------" << endl;
while(accnum <= 0)
{
cout << "What is the account number you want to add?" << endl;
if(!(cin >> accnum)) //String or char inpu
{
cout << "***Please enter an integer***" << endl;
cin.clear();
cin.ignore(100000, '\n');
accnum = 0;
}
else if(accnum <= 0) //Negative or zero
{
cout << "***Only positive integers***" << endl;
accnum = 0;
}
}
while(nameloop == 0)
{
cin.clear();
cin.ignore(100000, '\n');
cout << "What is the full name you want to add?" << endl;
cin.getline(accname, 100);
if(strlen(accname) > 1 && strlen(accname) <= 30)
{
nameloop = 1;
}
if(accname[strlen(accname)-1] == '\n')
{
accname[strlen(accname)-1] = '\0';
}
}
getAddress(address, 100);
if(address[strlen(address)-1] == '\n')
{
address[strlen(address)-1] = '\0';
}
while(birthyear <= 999 || birthyear > 9999)
{
cout << "What is the birth year you want to add?" << endl;
cout << "Please format: YYYY" << endl;
if(!(cin >> birthyear))
{
cout << "***Please enter an integer***" << endl;
cin.clear();
cin.ignore(100000, '\n');
accnum = 0;
}
else
{
if(birthyear <= 999 || birthyear > 9999)
{
cout << "***Birth years can only be 4 digits***" << endl;
}
}
}
cin.clear();
cin.ignore(100000, '\n');
mylist.addRecord(accnum, accname, address, birthyear);
break;
case 2 :
cout << "------------Option 2 selected-------------" << endl;
while(accnum <= 0)
{
cout << "What is the account number you want to modify?" << endl;
if(!(cin >> accnum))
{
cout << "***Please enter an integer***" << endl;
cin.clear();
cin.ignore(100000, '\n');
accnum = 0;
}
else if(accnum <= 0)
{
cout << "***Only positive integers***" << endl;
accnum = 0;
}
}
cin.clear();
cin.ignore(100000, '\n');
getAddress(address, 100);
if(address[strlen(address)-1] == '\n')
{
address[strlen(address)-1] = '\0';
}
mylist.modifyRecord(accnum, address);
cout << "Press ENTER to continue" << endl;
break;
case 3 :
cout << "------------Option 3 selected-------------" << endl;
while(accnum <= 0)
{
cout << "What is the account number you want to print?" << endl;
if(!(cin >> accnum))
{
cout << "***Please enter an integer***" << endl;
cin.clear();
cin.ignore(100000, '\n');
accnum = 0;
}
else if(accnum <= 0)
{
cout << "***Only positive integers***" << endl;
accnum = 0;
}
}
mylist.printRecord(accnum);
break;
case 4 :
cout << "------------Option 4 selected-------------" << endl;
cout << mylist;
break;
case 5 :
cout << "------------Option 5 selected-------------" << endl;
while(accnum <= 0)
{
cout << "What is the account number you want to delete?" << endl;
if(!(cin >> accnum))
{
cout << "***Please enter an integer***" << endl;
cin.clear();
cin.ignore(100000, '\n');
accnum = 0;
}
else if(accnum <= 0)
{
cout << "***Only positive integers***" << endl;
accnum = 0;
}
}
mylist.deleteRecord(accnum);
break;
case 6 :
cout << "------------Option 6 selected-------------" << endl;
mylist.reverse();
while(optionRev == 0)
{
cout << "-----------------------------------------" << endl;
cout << "--------------Reverse Menu---------------" << endl;
cout << "+---------------------------------------+" << endl;
cout << "| 8) Print all records |" << endl;
cout << "| 9) Reverse all records |" << endl;
cout << "+---------------------------------------+" << endl;
cout << "" << endl;
cout << "Please enter an option" << endl;
cin >> optionRev;
if (optionRev == 8)
{
cout << mylist;
optionRev = 0;
}
else if(optionRev == 9)
{
mylist.reverse();
}
else
{
cout << "*******Please enter a valid option!*******" << endl;
cin.clear();
cin.ignore(100000, '\n');
optionRev = 0;
}
}
option = 0;
break;
case 7 :
cout << "------------Option 7 selected-------------" << endl;
cout << "----Exitting Bank Database Application----" << endl;
mylist.~llist();
exit(1);
default :
cout << "*******Please enter a valid option!*******" << endl;
}
option = 0;
}
return 0;
}