<html>

<head><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- MyFirstUnitAd -->
<ins class="adsbygoogle"
     style="display:inline-block;width:970px;height:250px"
     data-ad-client="ca-pub-5778386704669218"
     data-ad-slot="1503492166"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>

<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>Population</title>
</head>

<body>



<p align="center"><span lang="en-ca"><font size="6" color="#FF0000"><b>Login </b>
</font></span></p>

<div align="left">
  <pre><b><font color="#ff0000" size="5">A.<span lang="en-ca">First</span> Edition</font></b></pre>
</div>
<div align="left">
  <pre><b>This is <span lang="en-ca">third</span> assignment of <span lang="en-ca">comp</span></b><span lang="en-ca"><b>352.</b></span></pre>
</div>
<div align="left">
  <pre><b><font color="#ff0000" size="5"><span lang="en-ca">B</span>.<span lang="en-ca"><a name="problem"></a>The problem</span></font></b></pre>
</div>
<div align="left">
  <pre>กก</pre>
</div>
<div align="left">
  <b><font color="#ff0000" size="5"><span lang="en-ca">C</span>.<span lang="en-ca">The
  </span></font></b><span lang="en-ca"><font size="5" color="#FF0000"><b>idea of 
  program</b></font></span></div>
<div align="left">
  <pre><b><font color="#ff0000" size="5">D.<span lang="en-ca"><a name="Method"></a>The </span>major functions</font></b></pre>
</div>
<div align="left">
  <pre><b><font color="#ff0000" size="5"><span lang="en-ca">C</span>.</font></b><span lang="en-ca"><font size="5" color="#FF0000"><b>Further improvement</b></font></span></pre>
</div>
<div align="left">
  <pre><b><span lang="en-ca"><font size="3" color="#FF0000">//the file name is dictionary.h</font></span></b></pre>
</div>
<pre>// The Dictionary abstract class.  KEComp compares a key
// and an element. EEComp compares two elements.  
template &lt;class Key, class Elem, class KEComp, class EEComp&gt;
class  Dictionary {
public:
  // Reinitialize dictionary
  virtual void clear() = 0;
  // Insert an element.  Return true if insert is
  // successful, false otherwise.
  virtual bool insert(const Elem&amp;) = 0;
  // Remove some element matching Key.  Return true if such
  // exists, false otherwise.  If multiple entries match
  // Key, an arbitrary one is removed.
  virtual bool remove(const Key&amp;, Elem*&amp;) = 0;
  // Remove and return an arbitrary element from dictionary.
  // Return true if some element is found, false otherwise.
  virtual bool removeAny(Elem*&amp;) = 0;
  // Return a copy of some Elem matching Key.  Return true
  // if such exists, false otherwise.  If multiple elements
  // match Key, return an arbitrary one.
  virtual bool find(const Key&amp;, Elem*&amp;) const = 0;
  // Return the number of elements in the dictionary.
  virtual int size() = 0;
};
</pre>
<pre>กก</pre>
<pre>// Binary tree node abstract class
template &lt;class Elem&gt; class BinNode {
public:
  // Return the node's element
  virtual Elem&amp; val() = 0;
  // Set the node's element
  virtual void setVal(const Elem&amp;) = 0;
  // Return the node's left child
  virtual BinNode* left() const = 0;
  // Set the node's left child
  virtual void setLeft(BinNode*) = 0;
  // Return the node's right child
  virtual BinNode* right() const = 0;
  // Set the node's right child
  virtual void setRight(BinNode*) = 0;
  // Return true iff the node is a leaf
  virtual bool isLeaf() = 0;
};
</pre>
<pre><b><font color="#FF0000"><span lang="en-ca">//the file name is BinNode.h</span></font></b></pre>
<pre>
// Binary tree node class
template &lt;class Elem&gt;
class BinNodePtr : public BinNode&lt;Elem&gt; {
private:
  Elem it;                     // The node's value
  BinNodePtr* lc;              // Pointer to left child
  BinNodePtr* rc;              // Pointer to right child
public:
  // Two constructors -- with and without initial values
  BinNodePtr() { lc = rc = NULL; }
  BinNodePtr(const Elem&amp; e, BinNodePtr* l =NULL,
                     BinNodePtr* r =NULL)
    { it = e; lc = l; rc = r; }
  ~BinNodePtr() {}             // Destructor
  Elem&amp; val() { return it; }
  void setVal(const Elem&amp; e) { it = e; }
  inline BinNode&lt;Elem&gt;* left() const { return lc; }
  void setLeft(BinNode&lt;Elem&gt;* b) { lc = (BinNodePtr*)b; }
  inline BinNode&lt;Elem&gt;* right() const { return rc; }
  void setRight(BinNode&lt;Elem&gt;* b) { rc = (BinNodePtr*)b; }
  bool isLeaf() { return (lc == NULL) &amp;&amp; (rc == NULL); }
};
</pre>
<pre><b><font color="#FF0000"><span lang="en-ca">//the file name is BST.h</span></font></b></pre>
<pre>// This file includes all of the pieces of the BST implementation

#include &quot;dictionary.h&quot;

#include &quot;binnode.h&quot;

// Binary Search Tree implementation for the Dictionary ADT
template &lt;class Key, class Elem, class KEComp, class EEComp&gt;
class BST : public Dictionary&lt;Key, Elem, KEComp, EEComp&gt; {
protected:
  BinNode&lt;Elem&gt;* root;   // Root of the BST
  int nodecount;         // Number of nodes in the BST
  // Private &quot;helper&quot; functions
  void clearhelp(BinNode&lt;Elem&gt;*);
  BinNode&lt;Elem&gt;* inserthelp(BinNode&lt;Elem&gt;*, const Elem&amp;);
  BinNode&lt;Elem&gt;* deletemin(BinNode&lt;Elem&gt;*, BinNode&lt;Elem&gt;*&amp;);
  BinNode&lt;Elem&gt;* removehelp(BinNode&lt;Elem&gt;*, const Key&amp;,
                            BinNode&lt;Elem&gt;*&amp;);
  bool findhelp(BinNode&lt;Elem&gt;*, const Key&amp;, Elem*&amp;) const;
  void printhelp(BinNode&lt;Elem&gt;*, int) const;
public:
  BST() { root = NULL; nodecount = 0; }  // Constructor
  ~BST() { clearhelp(root); }            // Destructor
  void clear()
    { clearhelp(root); root = NULL; nodecount = 0; }
  bool insert(const Elem&amp; e) {
    root = inserthelp(root, e);
    nodecount++;
    return true;
  }
  bool remove(const Key&amp; K, Elem*&amp; e) {
    BinNode&lt;Elem&gt;* t = NULL;
    root = removehelp(root, K, t);
    if (t == NULL) return false;  // Nothing found
    e = &amp;(t-&gt;val());
    nodecount--;
    delete t;
    return true;
  }
  bool removeAny(Elem*&amp; e) { // Delete min value
    if (root == NULL) return false; // Empty tree
    BinNode&lt;Elem&gt;* t;
    root = deletemin(root, t);
    e = &amp;(t-&gt;val());
    delete t;
    nodecount--;
    return true;
  }
  bool find(const Key&amp; K, Elem*&amp; e) const
    { return findhelp(root, K, e); }
  int size() { return nodecount; }
  void print() const {
    if (root == NULL) cout &lt;&lt; &quot;The BST is empty.\n&quot;;
    else printhelp(root, 0);
  }
};

template &lt;class Key, class Elem, class KEComp, class EEComp&gt;
void BST&lt;Key, Elem, KEComp, EEComp&gt;::
clearhelp(BinNode&lt;Elem&gt;* subroot) {
  if (subroot == NULL) return;
  clearhelp(subroot-&gt;left());
  clearhelp(subroot-&gt;right());
  delete subroot;
}

template &lt;class Key, class Elem, class KEComp, class EEComp&gt;
BinNode&lt;Elem&gt;* BST&lt;Key, Elem, KEComp, EEComp&gt;::
inserthelp(BinNode&lt;Elem&gt;* subroot, const Elem&amp; val) {
  if (subroot == NULL)            // Empty tree: create node
    return (new BinNodePtr&lt;Elem&gt;(val, NULL, NULL));
  if (EEComp::lt(val, subroot-&gt;val())) // Insert on left
    subroot-&gt;setLeft(inserthelp(subroot-&gt;left(), val));
  else subroot-&gt;setRight(inserthelp(subroot-&gt;right(), val));
  return subroot;  // Return subtree with node inserted
}

template &lt;class Key, class Elem, class KEComp, class EEComp&gt;
BinNode&lt;Elem&gt;* BST&lt;Key, Elem, KEComp, EEComp&gt;::
deletemin(BinNode&lt;Elem&gt;* subroot, BinNode&lt;Elem&gt;*&amp; min) {
  if (subroot-&gt;left() == NULL) { // Found min
    min = subroot;
    return subroot-&gt;right();
  }
  else {                         // Continue left
    subroot-&gt;setLeft(deletemin(subroot-&gt;left(), min));
    return subroot;
  }
}

template &lt;class Key, class Elem, class KEComp, class EEComp&gt;
BinNode&lt;Elem&gt;* BST&lt;Key, Elem, KEComp, EEComp&gt;::
removehelp(BinNode&lt;Elem&gt;* subroot, const Key&amp; K,
           BinNode&lt;Elem&gt;*&amp; t) {
  if (subroot == NULL) return NULL; // Val is not in tree
  else if (KEComp::lt(K, subroot-&gt;val())) // Check left
    subroot-&gt;setLeft(removehelp(subroot-&gt;left(), K, t));
  else if (KEComp::gt(K, subroot-&gt;val())) // Check right
    subroot-&gt;setRight(removehelp(subroot-&gt;right(), K, t));
  else {                           // Found it: remove it
    BinNode&lt;Elem&gt;* temp;
    t = subroot;
    if (subroot-&gt;left() == NULL)       // Only a right child
      subroot = subroot-&gt;right();      //  so point to right
    else if (subroot-&gt;right() == NULL) // Only a left child
      subroot = subroot-&gt;left();       //  so point to left
    else {                    // Both children are non-empty
      subroot-&gt;setRight(deletemin(subroot-&gt;right(), temp));
      Elem te = subroot-&gt;val();
      subroot-&gt;setVal(temp-&gt;val());
      temp-&gt;setVal(te);
      t = temp;
    }
  }
  return subroot;
}

template &lt;class Key, class Elem, class KEComp, class EEComp&gt;
bool BST&lt;Key, Elem, KEComp, EEComp&gt;:: findhelp(
      BinNode&lt;Elem&gt;* subroot, const Key&amp; K, Elem*&amp; e) const {
  if (subroot == NULL) return false;         // Empty tree
  else if (KEComp::lt(K, subroot-&gt;val()))    // Check left
    return findhelp(subroot-&gt;left(), K, e);
  else if (KEComp::gt(K, subroot-&gt;val()))    // Check right
    return findhelp(subroot-&gt;right(), K, e);
  else { e = &amp;(subroot-&gt;val());  return true; } // Found it
}

template &lt;class Key, class Elem, class KEComp, class EEComp&gt;
void BST&lt;Key, Elem, KEComp, EEComp&gt;::
printhelp(BinNode&lt;Elem&gt;* subroot, int level) const {
  if (subroot == NULL) return;          // Empty tree
  printhelp(subroot-&gt;left(), level+1);  // Do left subtree
  for (int i=0; i&lt;level; i++)           // Indent to level
    cout &lt;&lt; &quot;  &quot;;
  cout &lt;&lt; subroot-&gt;val() &lt;&lt; &quot;\n&quot;;       // Print node value
  printhelp(subroot-&gt;right(), level+1); // Do right subtree
}

<b><font color="#FF0000"><span lang="en-ca">//the file name is Elem.h</span></font></b></pre>
<pre>//This is the element of login system
class Record
{
private:
	int id;
	char pwd[7];
public:
	Record(const Record&amp; rec);
	int getID() const {return id;}
	const char* getPWD() const { return pwd;}
	void setID(int newID){ id = newID;}
	void setPWD(const char* newPWD){strncpy(pwd, newPWD, 6);}
	Record(int newID, char* password);	
	Record();
	Record&amp; operator=(const Record&amp; rec);
};

Record::Record()
{
	id =-1;
}

Record&amp; Record::operator =(const Record&amp; rec)
{
	id = rec.getID();
	strcpy(pwd, rec.getPWD());
	return *this;
}


Record::Record(int newID, char* password)
{
	id=newID;
	strncpy(pwd, password, 7);
}

Record::Record(const Record&amp; rec)
{
	id = rec.getID();
	strcpy(pwd, rec.getPWD());
}

class KEComp
{
public:
	static bool lt(int key, const Record&amp; Elem) {return key&lt;Elem.getID();}
	static bool eq(int key, const Record&amp; Elem) {return key==Elem.getID();}
	static bool gt(int key, const Record&amp; Elem) {return key&gt;Elem.getID();}
};

class EEComp
{
public:
	static bool lt(const Record&amp; Elem1, const Record&amp; Elem2)
		{ return Elem1.getID()&lt;Elem2.getID();}
	static bool eq(const Record&amp; Elem1, const Record&amp; Elem2)
		{ return Elem1.getID()==Elem2.getID();}
	static bool gt(const Record&amp; Elem1, const Record&amp; Elem2)
		{ return Elem1.getID()&gt;Elem2.getID();}
};


<b><font color="#FF0000"><span lang="en-ca">//the file name is menu.h</span></font></b></pre>
<pre>/*********************************************************
*Name of file: menu.h
*function: It is a generic class for input menus. 
*Idea of program: Whatever an input menu is simply ask user to
*	input a number to indicate his choice which has some associated
*	infomation displayed. So I just set up a menu by inputing a 
*	set of strings and return the number which user input.
*	I also want it to have a set of automatical response by
*	inputing a set of function pointers which can be called when a
*	number is entered.
************************************************************/
#include &lt;iostream&gt;

using namespace std;

const int MaxMenuItems = 10;
const int MaxTitleLength = 20;
class Menu
{
private:
	char titles[MaxMenuItems][MaxTitleLength];
	void (*respondList[MaxMenuItems])();
	int itemCount;	
	int quitIndex;
	int getInput();
	void printMenu();
public:
	void setMenu(char** menuTitles, int titleNum);
	int input(bool useDefault=true);	
	void setRespond(int index, void (*respond)());
	void setQuitIndex(int index);//this is not very useful
};

void Menu::setQuitIndex(int index)
{
	if (index&lt;itemCount)
	{
		quitIndex = index;
	}
	else
	{
		cout&lt;&lt;&quot;Out of menu count!\n&quot;;
	}
}


void Menu::setMenu(char** menuTitles, int titleNum)
{
	itemCount = titleNum;
	for (int i=0; i&lt; titleNum; i++)
	{
		strcpy(titles[i], menuTitles[i]);
		respondList[i]=NULL;
	}
	quitIndex = itemCount-1;//by default it should quit at last item
}

void Menu::setRespond(int index, void (*respond)())
{
	if (index&lt;itemCount)
	{
		respondList[index] = respond;
	}
	else
	{
		cout&lt;&lt;&quot;Out of menu count!\n&quot;;
	}
}

int Menu::input(bool useDefault)
{
	int index;
	index = getInput();
	if (useDefault)
	{
		if (respondList[index]!=NULL)
		{
			respondList[index];
		}
	}
	return index;
}

void Menu::printMenu()
{
	cout&lt;&lt;&quot;\n       Menu (choose by enter item index\n&quot;;
	for (int i=0; i&lt;itemCount; i++)
	{
		cout&lt;&lt;&quot;\t(&quot;&lt;&lt;i+1&lt;&lt;&quot;) &quot;&lt;&lt;titles[i]&lt;&lt;endl;
	}
	cout&lt;&lt;&quot;choice&gt;&quot;;
}


int Menu::getInput()
{
	//char buffer[20];
	int result=0;
	printMenu();
	do 
	{
		cin&gt;&gt;result;		
		if (result&lt;1||result&gt;itemCount)
		{
			cout&lt;&lt;&quot;Please enter a number for your choices!\n&quot;;
		}
	}
	while (result&lt;1||result&gt;itemCount);
	return result-1;
}
</pre>
<pre><b><font color="#FF0000"><span lang="en-ca">//the file name is login.cpp</span></font></b></pre>
<pre>//////////////////////////////////////////////////////////////////////
//author: qingzhe huang
//date: oct. 26, 2003
//purpose: To use BST to simulate login system
//idea of program:
//		1. My class MyBST is only inherited from a certain template class---BST
//		with all type parameter already set up. So, it is not a template class
//		anymore. 
//		2. By printing it in alphabetic order, I should use inorder. By saving
//		in file in a way such that when it is read in, it can gives exact same
//		tree. It should use preorder.
//		3. I implement my own Key-Element-compare class and Element-Element-compare
//		class. 
//		4. ID should be 7-digit, if it is smaller than 1000000, which has length of 7,
//		0's should be added in the front to make it as long as 7 characters.
//		5.	Password is 6-character strings and the longer part will be chopped to 6.
//		6. There are a default input and output file name, if there is no parameter 
//		following command line. If there is one parameter after file name, it is 
//		considered to be input file name. If there are two parameter, then they are
//		input file name and output file name.
////////////////////////////////////////////////////////////////////////////////////////
#include &lt;iostream&gt;
#include &quot;BST.h&quot;
#include &quot;Elem.h&quot;
#include &quot;Menu.h&quot;
#include &lt;fstream&gt;

using namespace std;

char* menuStr[5] = {&quot;Add new user&quot;, &quot;Delete user&quot;, &quot;Verify user&quot;, &quot;Print user&quot;, &quot;Quit&quot;};

char* defaultFileName = &quot;c:\\nickid.dat&quot;;

class MyBST: public BST&lt;int, Record, KEComp, EEComp&gt;
{
private:
	ifstream in;
	ofstream out;
	Menu menu;
	void int2str(int i, char* buffer, int len);
	void preOrder(BinNode&lt;Record&gt;*&amp; node);
	void visitNode(BinNode&lt;Record&gt;*&amp; node);
	void inOrder(BinNode&lt;Record&gt;* node);
	void printNode(BinNode&lt;Record&gt;* node);
	void doAdd();
	bool getID(int&amp; ID);
	bool getPassword(char* str);
	bool deleteUser(int ID);
	void doVerify();
	void doDelete();
	void doPrint();
public:
	void readFile(const char* fileName);
	void writeFile(const char* fileName);
	bool addNew(int ID, char* passWord);
	bool verifyUser(int ID, char* passWord);
	void printUsers();
	void getChoice();
};


int main(int argc, char** argv)
{	
	MyBST my;
	char* inputName = defaultFileName, *outputName=defaultFileName;
	if (argc==2)
	{
		inputName = argv[1];
	}
	else
	{
		if (argc==3)
		{
			inputName=argv[1];
			outputName=argv[2];
		}
	}
	my.readFile(inputName);
	my.getChoice();
	my.writeFile(outputName);

	return 0;
}

//the buffer should be at least one longer than &quot;len&quot; for '\0'
void MyBST::int2str(int i, char* buffer, int len)
{
	int length;
	itoa(i, buffer, 10);
	length = strlen(buffer);
	if (length&lt; len)
	{
		for (int j=0; j&lt;=len; j++)//&lt;= to include '\0'
		{
			if (j&lt;=length)
			{
				buffer[len-j]=buffer[length-j];
			}
			else
			{
				buffer[len-j]='0';//to fill with '0'
			}
		}
	}
}


void MyBST::doVerify()
{
	int id;
	char buffer[20];
	if (getID(id))
	{
		if (getPassword(buffer))
		{
			if (verifyUser(id, buffer))
			{
				cout&lt;&lt;&quot;Valid user\n&quot;;
				return;
			}
			else
			{
				cout&lt;&lt;&quot;Invalid user\n&quot;;
				return;
			}
		}
	}
	cout&lt;&lt;&quot;incorrect input of ID or password\n&quot;;
}

void MyBST::doPrint()
{
	inOrder(root);
}


void MyBST::doDelete()
{
	int ID;
	if (getID(ID))
	{
		if (deleteUser(ID))
		{
			cout&lt;&lt;&quot;user &quot;&lt;&lt;ID&lt;&lt;&quot; is deleted successfully!\n&quot;;
			return;
		}
	}
	cout&lt;&lt;&quot;fail to delete &quot;&lt;&lt;ID&lt;&lt;endl;
}

bool MyBST::getID(int&amp; ID)
{	
	char buffer[20];
	int i=0;
	char* ptr=buffer;
	char* start=buffer;
	cout&lt;&lt;&quot;\nPlease enter your ID:&quot;;
	cin&gt;&gt;buffer;
	while (i&lt;7)
	{
		if (*ptr==' '&amp;&amp;i==0)
		{
			start++;
			ptr++;
		}
		else
		{
			if (*ptr&gt;='0'&amp;&amp;*ptr&lt;='9')
			{	
				ptr++;
				i++;
			}
			else
			{
				return false;
			}
		}
	}
	*ptr = '\0';
	ID = atoi(start);
	return true;
}

bool MyBST::getPassword(char* buffer)
{
	int i=0;
	char* ptr=buffer;
	int start=0;
	cout&lt;&lt;&quot;\nPlease enter your password:&quot;;
	cin&gt;&gt;buffer;
	while (i&lt;6)
	{
		if (*ptr==' '&amp;&amp;i==0)
		{
			start++;
		}
		else
		{
			if (isalnum(*ptr))
			{
				i++;
			}
			else
			{
				return false;
			}
		}
		ptr++;
	}
	*ptr = '\0';
	if (start!=0)
	{
		i=0;
		while (i&lt;7)//include '\0'
		{
			buffer[i]=buffer[start+i];
		}
	}

	return true;
}
	


void MyBST::doAdd()
{
	int ID;
	char buffer[30];
	cout&lt;&lt;&quot;Please enter your ID and password:&quot;;
	if (getID(ID))
	{
		if (getPassword(buffer))
		{
			if (addNew(ID, buffer))
			{	
				cout&lt;&lt;&quot;\nYour ID is added successfully!\n&quot;;
				return;
			}
		}
	}
	cout&lt;&lt;&quot;Fail to add your ID\n&quot;;
}


void MyBST::getChoice()
{
	int index;
	char** temp=menuStr;
	menu.setMenu(temp, 5);
	while ((index=menu.input(false))!=4)
	{
		switch(index)
		{
		case 0:
			doAdd();
			break;
		case 1:
			doDelete();
			break;
		case 2:
			doVerify();
			break;
		case 3:
			doPrint();
			break;
		}
	}
}


void MyBST::printNode(BinNode&lt;Record&gt;* node)
{
	int id;
	char buffer[8];
	id = node-&gt;val().getID();
	int2str(id, buffer, 7);
	cout&lt;&lt;buffer&lt;&lt;&quot;   &quot;&lt;&lt;node-&gt;val().getPWD()&lt;&lt;endl;	
}

void MyBST::inOrder(BinNode&lt;Record&gt;* node)
{
	BinNode&lt;Record&gt;*l, *r;
	if  (node!=NULL)
	{
		l = node-&gt;left();
		r = node-&gt;right();
		inOrder(l);
		printNode(node);
		inOrder(r);
	}
}

bool MyBST::verifyUser(int ID, char* password)
{
	Record* rec;
	if (find(ID, rec))
	{
		if (!strcmp(password, rec-&gt;getPWD()))
		{
			return true;
		}
	}
	return false;
}

bool MyBST::deleteUser(int ID)
{
	Record* rec;
	if (remove(ID, rec))
	{
		//delete rec;
		return true;
	}
	
	return false;
}

void MyBST::preOrder(BinNode&lt;Record&gt;*&amp; node)
{
	BinNode&lt;Record&gt;* l, *r;
	while (node!=NULL)
	{
		l = node-&gt;left();
		r = node-&gt;right();
		visitNode(node);
		preOrder(l);
		preOrder(r);
	}
}


void MyBST::visitNode(BinNode&lt;Record&gt;*&amp; node)
{
	int i;
	char buffer[8];
	i = node-&gt;val().getID();
	int2str(i, buffer, 7);
	out&lt;&lt;&quot;   &quot;&lt;&lt;buffer&lt;&lt;&quot;  &quot;&lt;&lt;node-&gt;val().getPWD();
	delete node;
	node =NULL;
}




void MyBST::readFile(const char* fileName)
{
	int id;
	char buffer[30];
	Record* ptr;
	in.open(fileName, ios::in);
	clear();
	while (!in.eof())
	{
		in&gt;&gt;id&gt;&gt;buffer;
		ptr = new Record(id, buffer);	
		insert(*ptr);
	}
	in.close();
}

void MyBST::writeFile(const char* fileName)
{
	out.open(fileName, ios::out);
	preOrder(root);
}

bool MyBST::addNew(int ID, char* passWord)
{
	Record *rec;

	if (find(ID, rec))
	{
		cout&lt;&lt;&quot;User ID &quot;&lt;&lt;ID&lt;&lt;&quot; already exists!\n&quot;;
		return false;
	}
	else
	{
		rec = new Record(ID, passWord);
		insert(*rec);
		return true;
	}
}



</pre>
<pre><span lang="en-ca"><font color="#FF0000">//the input file </font><a href="userids.dat">is here</a><font color="#0000FF">.</font></span>


</pre>

<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;                                   
&nbsp;&nbsp;&nbsp; <a href="WhoAmI.htm">                  







                       <img src="picture/back.gif" style="border: medium none" alt="back.gif (341 bytes)" width="32" height="35"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
<a href="index.htm"><img src="picture/up.gif" style="border: medium none" alt="up.gif (335 bytes)" width="35" height="32"></a>       &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;                         
<img src="picture/next.gif" style="border: medium none" alt="next.gif (337 bytes)" width="32" height="35">          


</p>

</body>

</html>