// Matt Kaliszewski
// COMP411 - Lab 06
// October 16, 2002
// KaliszewskiM Hash Table.cpp
#include <iostream>
#include "User.h"
#include "HashTable.h"
using namespace std;
void
main(void)
{
User *newuser; // Container for new users
HashTable Users; // The User Hash Table
int choice; // The users choice
string un; // User Name
string n; // Name
string ph; // Phone nUmber
string priv; // Privilege
bool worked; // Flag to tell if action worked
cout << "/-/-/-/-/-/-/-/-/-/ Computer Center
\\-\\-\\-\\-\\-\\-\\-\\-\\-\\" << endl << endl;
do{
// Clear the variables
un = "";
n = "";
ph = "";
priv = "";
// Display the menu
cout << "What would you like to do?" << endl << endl
<< "1 - Add a new user" << endl
<< "2 - Delete a user" << endl
<< "3 - Print a list of all users" << endl
<< "4 - Print the information for a specific user" << endl
<< "5 - Exit" << endl << endl
<< "Enter your choice: ";
// Get the users choice
_flushall();
cin >> choice;
while(choice < 1 || choice > 5)
{
cout << "Invalid choice..." << endl << endl
<< "Re-enter your choice: ";
cin >> choice;
}
switch(choice)
{
// Add a new user
case 1:
cout << "------------ Add New User ------------" <<
endl << endl
<< "Please enter the following information:"
<< endl
<< "User Name: ";
_flushall();
cin >> un;
cout << "Name: ";
_flushall();
cin >> n;
cout << "Phone Number: ";
_flushall();
cin >> ph;
cout << "Privilege: ";
_flushall();
cin >> priv;
// Try to add the user
newuser = new User(un, n, ph, priv);
worked = Users.insertUser(newuser);
// Tell the user if the add was successful
if(worked)
cout << endl <<
"*******************************"
<< "*** User succesfully added! ***"
<< endl
<< "*******************************"
<< endl << endl;
else
cout << endl <<
"******************************"
<< "*** User already exists!!! ***"
<< endl
<< "******************************"
<< endl << endl;
break;
// Delete a user
case 2:
cout << "------------ Delete User ------------" <<
endl << endl
<< "Please enter the User Name of the user
to be deleted" << endl
<< "--> ";
cin >> un;
// Try to delete the user
worked = Users.deleteUser(un);
// Tell the user if the delete was successful
if(worked)
cout << endl <<
"*********************************"
<< "*** User succesfully deleted!
***" << endl
<<
"*********************************" << endl << endl;
else
cout << endl << "*************************"
<< "*** User not found!!! ***" <<
endl
<< "*************************" <<
endl << endl;
break;
// Print all the users
case 3:
cout << "------------ All Users ------------" <<
endl << endl;
Users.print();
break;
// Display the information for a specific user
case 4:
cout << "------------ Detailed User Info
------------" << endl << endl
<< "Please enter the User Name of the user
you wish to lookup" << endl
<< "--> ";
cin >> un;
Users.printUserInfo(un);
break;
// Exit the program
case 5:
cout << endl << "Exiting Program..." << endl << endl;
break;
}
}while(choice != 5);
}