-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDriver.c
105 lines (81 loc) · 3.33 KB
/
Driver.c
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
/****************************************************************************
Ryan Bridges
February 29, 2014
File Name: Driver.c
Description: Driver for the binary tree
****************************************************************************/
#include <iostream>
#include <cstdio>
#include <string>
#include <getopt.h>
#include "Driver.h"
#include "SymTab.h"
using namespace std;
#ifdef NULL
#undef NULL
#define NULL 0
#endif
ostream & operator << (ostream & stream, const UCSDStudent & stu) {
return stream << "name: " << stu.name
<< " with studentnum: " << stu.studentnum;
}
int main (int argc, char * const * argv) {
char buffer[BUFSIZ];
char command;
long number;
char option;
SymTab<UCSDStudent>::Set_Debug_Off ();
while ((option = getopt (argc, argv, "x")) != EOF) {
switch (option) {
case 'x': SymTab<UCSDStudent>::Set_Debug_On ();
break;
}
}
SymTab<UCSDStudent> ST;
ST.Write (cout << "Initial Symbol Table:\n" );
while (cin) {
command = NULL; // reset command each time in loop
cout << "Please enter a command ((i)nsert, "
<< "(l)ookup, (r)emove, (w)rite): ";
cin >> command;
switch (command) {
case 'i': {
cout << "Please enter UCSD student name to insert: ";
cin >> buffer; // formatted input
cout << "Please enter UCSD student number: ";
cin >> number;
UCSDStudent stu (buffer, number);
// create student and place in symbol table
ST.Insert (stu);
break;
}
case 'l': {
unsigned long found; // whether found or not
cout << "Please enter UCSD student name to lookup: ";
cin >> buffer; // formatted input
UCSDStudent stu (buffer, 0);
found = ST.Lookup (stu);
if (found)
cout << "Student found!!!\n" << stu << "\n";
else
cout << "student " << buffer << " not there!\n";
break;
}
case 'r': {
unsigned long removed;
cout << "Please enter UCSD student name to remove: ";
cin >> buffer; // formatted input
UCSDStudent stu (buffer, 0);
removed = ST.Remove(stu);
if (removed)
cout << "Student removed!!!\n" << stu << "\n";
else
cout << "student " << buffer << " not there!\n";
break;
}
case 'w':
ST.Write (cout << "The Symbol Table contains:\n");
}
}
ST.Write (cout << "\nFinal Symbol Table:\n");
}