A Simple Employee Database in C++

This is just part of a group of classes used to create an employee database. The employeegroup class uses pointers which are used for memory management (as opposed to Java which does the memory management for you.) If for some reason you'd like the entire program, let me know and I'll send you a copy containing all the classes used. Just post a comment to leave me a message.
#include "employeegroup.h"
 
EmployeeGroup::EmployeeGroup() : EGname("BLANK"), head(NULL), tail(NULL), lastreturn(NULL), exists_head(false), exists_tail(false), size(0) 
{}
 
EmployeeGroup::EmployeeGroup(String s)
{
	EGname=s;
	head=NULL;
	tail=NULL;
	lastreturn=NULL;
	exists_head=false;
	exists_tail=false;
	size=0;
}
 
EmployeeGroup::~EmployeeGroup()
{
	enode* current = head;
	while(current!=NULL)
	{
		enode* next=current->next;
		delete current;     
		current = next;
	}
}
 
void EmployeeGroup::name(String n)
{
	EGname=n;
}
 
String EmployeeGroup::name()
{
	return EGname;
}
bool EmployeeGroup::insert(Employee e)
{
     enode *q,*t;
 
		 // Condition where neither head nor tail exists
		 if(head==NULL)
		 {
			cout << "Inserting head (first node)..." << endl;
			enode* temp = new enode;
			temp->e = e;
			temp->next = NULL;
			head=temp;
			exists_head=true;
			size++;
			return (true);
		 }
		 if (employee_already_exists(e))
			 return (false);
		 // Condition where head exists but no tail exists
		 t=head;
		 if (exists_head==true)
			 if(exists_tail==false)
			 {
 
				  if (t->e.idno < e.idno)   //insertion after head
				  {
					  enode* temp = new enode;
					  temp->e = e;
					  temp->next = NULL;
					  t->next = temp;
					  tail=temp;
					  size++;
					  exists_tail=true;
					  cout << "Inserting after head successful!" << endl;
					  return (true);
				  } else   //insertion before head
				  {
					  enode* temp = new enode;
					  temp->e = e;
					  temp->next = head;
					  tail = head;
					  head = temp;
					  size++;
					  exists_tail=true;
					  cout << "Inserting before head successful!" << endl;
					  return (true);
				  }
			 }
 
			 // Condition where head exists and tail exists
			 q=head;
			 if (exists_head)
				if(exists_tail)
				{
					if (e.idno < q->e.idno)
					{
						  enode* temp = new enode;
						  temp->e = e;
						  temp->next = head;
						  head = temp;
						  size++;
						  cout << "Inserting before head successful!" << endl;
						  return (true);
 
					}
					if (e.idno > tail->e.idno)
					{
						  enode* p;
						  p=tail;
						  enode* temp = new enode;
						  temp->e = e;
						  temp->next = NULL;
						  p->next = temp;
						  tail=temp;
						  size++;
						  cout << "Inserting after tail successful!" << endl;
						  return (true);				
					}
					//If above two conditions are not met, we insert in the middle
					q=head;
				    while(q->next != NULL)
					{
					if ( q->e.idno < e.idno ) 
						if ( q->next->e.idno > e.idno )
						{
							enode* temp = new enode;
							temp->e = e;
							temp->next = q->next;
						    q->next = temp;
			                cout << "Inserting in the middle..." << endl;
			                size++;
			                return (true);
						}
			          q = q->next;
					}
				}
				return(false);
}
 
bool EmployeeGroup::employee_already_exists (Employee e)
{
	  enode* current;
	  current = head;
	  if (current->next==NULL)
	  {
	   	 if (current->e == e)
			{
				//cout << "An employee with that ID already exists.";
				return (true);
			}
	  }
	  while(current->next != NULL)		//Loop to see if an employee with an equal ID exists
	  {		
 
			if (current->e == e)
				{
					//cout << "An employee with that ID already exists.";
					return (true);
				}
			current = current->next;
	  }	
	return (false);
}
 
 
void EmployeeGroup::display()
{
cout << "\nEmployee group name is " << EGname << endl;
enode* current=head;
cout << "The pointer for head is " << head << endl;
while (current != NULL)
	{
		current->e.write();
		cout << "The next pointer for this person is " << current->next << endl;
		current = current->next;
	}
 
}
 
Employee EmployeeGroup::get_next()
{
	if (lastreturn==NULL)
	{
		lastreturn=head;
		lastreturn->e.write();
		return (lastreturn->e);
	}
	else
	{
		if (lastreturn->next==NULL)
		{
			cout << "End of List" << endl;
			return (NULL_EMP);
		} else
		{
		enode* temp;
		temp=lastreturn;
		lastreturn=lastreturn->next;
		temp->next->e.write();
		return (temp->next->e);
		}
	}
}
 
bool EmployeeGroup::remove( int id )
{
     enode *q,*r;
     q = head;
     if( q->e.idno == id )
		{
			head = q->next;
			delete q;
			size--;
			return (true);
		}
 
      r = q;
      while( q!=NULL )
      {
        if( q->e.idno == id )
             {
				r->next = q->next;
				delete q;
				size--;
				return (true);
			 }
 
      r = q;
      q = q->next;
   }
   cout<<"\nElement "<<id<<" not Found.";
   return (false);
}
 
 
int EmployeeGroup::empcount()
{
	return size;
}
 
Employee EmployeeGroup::find(int id)
{
	if (exists_head==false)				//Check to see if there's a head. If not, break.
	{
		cout << "There are no employees in this group.\n" << endl;
		return NULL_EMP;
	}
	enode* current=head;
	while (current->e.idno!=id)
	{
 
		if (current->next==NULL)
		{
			cout << "No employee with id "<< id << " was found.\n" << endl;
			return NULL_EMP;
		}
		else
		{
			current=current->next;
		}
	}
	cout << "We found the employee!!!" << endl;
	return (current->e);
 
}
Posted in C++

MySQL to XML Database Dump

Thumb PHP
This code was used to dump a list of legal blogs from a MySQL database to an OPML file.  After the dump, I would typically upload the OPML file to the company’s legal search engine which would then pull the RSS feeds into its own index. I also constructed a spider that would use Google to spider legal blogs for info.
<?php
header("Content-type: text/xml");
function check_not_empty($s, $include_whitespace = false)
{
    if ($include_whitespace) {
        // make it so strings containing white space are treated as empty too
        $s = trim($s);
    }
    return (isset($s) && strlen($s)); // var is set and not an empty string ''
}
 
 
 
$host = "localhost"; 
$user = ""; //I've erased the username and password for security
$pass = "";
$database = "law";
 
$linkID = mysql_connect($host, $user, $pass) or die("Could not connect to host.");
mysql_select_db($database, $linkID) or die("Could not find database.");
 
$query = "SELECT * FROM blogs2 ORDER BY Serialid ASC";
$resultID = mysql_query($query, $linkID) or die("Data not found.");
 
$header = "<?xml version=\"1.0\"?>\n
				<opml version=\"1.0\">\n
<head>\n
<title>Matthew Currier created</title>\n
<dateCreated>".date("F j, Y, g:i a")."</dateCreated>\n
</head>\n
<body>\n";
echo $header;
for($x = 0 ; $x < mysql_num_rows($resultID) ; $x++){
    $row = mysql_fetch_assoc($resultID);
	$Title = $row['Title'];
	$Htmlurl = $row['Htmlurl'];
	$Xmlurl = $row['Xmlurl'];
	$Serialid = $row['Serialid'];
	$Category1 = $row['Cat1'];
	$Category2 = $row['Cat2'];
	$Category3 = $row['Cat3'];
	$Category4 = $row['Cat4'];
	$Category5 = $row['Cat5'];
	$Category6 = $row['Cat6'];
	$Location1 = $row['Loc1'];
	$Location2 = $row['Loc2'];
 
	echo "\t<outline type=\"Legal Blogs\" serialID=\"$Serialid\" priority=\"1\" xmlUrl=\"$Xmlurl\" title=\"$Title\" htmlUrl=\"$Htmlurl\" ";
	if (isset($Category1)){ 
	echo "category1=\"".$Category1."\" ";
	}
	if (check_not_empty($Category2)){ 
	echo "category2=\"".$Category2."\" ";
	}
	if (check_not_empty($Category3)){ 
	echo "category3=\"".$Category3."\" ";
	}
	if (check_not_empty($Category4)){ 
	echo "category4=\"".$Category4."\" ";
	}
	if (check_not_empty($Category5)){ 
	echo "category5=\"".$Category5."\" ";
	}
	if (check_not_empty($Category6)){ 
	echo "category6=\"".$Category6."\" ";
	}
	if (check_not_empty($Location1)){ 
	echo "location1=\"".$Location1."\" ";
	}
	if (check_not_empty($Location2)){ 
	echo "location2=\"".$Location2."\" ";
	}
	echo "/>\n";
}
 
 
echo "</body>";
echo "</opml>";
 
 
?>
Posted in PHP

Multivariate Regression of High School Dropout Rate on Other Variables

SAS Thumb
This is the code I wrote for a multivariate regression project.  The independent variable is high school dropout rate and the dependent variables include parameters like unemployment rate, teen birth rate, and student-teacher ratio. If you don’t have SAS installed, you can also view a snippet of the output that the code produces.
/* Variables imported from excel
1 state
2 DropoutRate
3 UnempRate
4 PercentPassportAppsApproved
5 PercentRepresentedByUnions
6 StudentTeacherRatio2008
7 TeenBirthRate
 
x0=state
y=DropoutRate
x1=UnempRate
x2=PercentPassportAppsApproved
x3=PercentRepresentedByUnions
x4=StudentTeacherRatio2008
x5=TeenBirthRate
x6=Death Penalty
*/
 
dm "out; clear; log; clear"; /* These instructions clear the output and log windows */
 
/*Rename variables to simplify processing */
 
data work.fin2(rename=state=x0 rename=DropOutRate=y rename=UnempRate=x1
              rename=PercentRepresentedByUnions=x3 rename=PercentPassportAppsApproved=x2
              rename=StudentTeacherRatio2008=x4 rename=TeenBirthRate=x5 rename=DeathPenalty=x6); set final2;
 
    *Change Passport Apps approved into a readable percentage;
     PercentPassportAppsApproved=PercentPassportAppsApproved*100;
 
run;
 
DATA DropOne; set work.fin2;
 
    IF _N_ NE 9 THEN OUTPUT DropOne; *drops District of Columbia from data set;
    label y='Dropout Rate';
    label x1='Unemployment Rate';
    label x2='Passports Approved';
    label x3='Union Membership';
    label x4='Students to Teachers';
    label x5='Teen Birth Rate';
    label x6='Death Penalty(1)/No Death Pentalty(0)';
 
RUN;
 
proc reg data=DropOne;
title 'Regression of Dropout Rate on 6 independent variables (excluding DC)';
model y = x1 x2 x3 x4 x5 x6 / clb;
run;
This program produces the following output:
Posted in SAS