//demonstrates list used with employee class
//implements linked list as a template
#include<iostream>
using namespace std;
const int len=80;//maximum length of names
class employee  //employee class
{
private:
char name[len];//employee name
unsigned long number;//employee number
public:
friend istream& operator>>(istream& s,employee& e);
friend ostream& operator<<(ostream&s,employee& e);
};
istream& operator>>(istream& s,employee& e)
{
cout<<"\n enter last name:  ";
cin>>e.name;
cout<<"enter number:  ";
cin>>e.number;
return s;
}
ostream& operator<<(ostream&s,employee& e)
{
cout<<"\n name:   "<<e.name;
cout<<"\n number:   "<<e.number;
return s;
}
template<class type>//struct link<type>
struct link  //one element of list
{
type data;//date item
link* next;//pointer to next link
};
template<class type>//class linklist<type>
class linklist
{
private:
link<type>*first;//pointer to first link
public:
linklist()//no-argument constructor
{first=NULL;}
void additem(type d);//add data item (one link)
void display();//display all links
};
template<class type>
void linklist<type>::additem(type d)//add data item
{
link<type>*newlink=new link<type>;//make a new link
newlink->data=d;//give it data
newlink->next=first;//it points to next link
first=newlink;//now first points to this
}
template<class type>
void linklist<type>::display()//display all links
{
link<type>*current=first;//set ptr to first link
while(current!=NULL)//quit on last link
{
cout<<endl<<current->data;//display data
current=current->next;//move to next link
}
}
int main()
{
linklist<employee>lemp;//class linklist<employee>
employee emptemp;//temporary employee storate
char ans;
do
{
cin>>emptemp;
lemp.additem(emptemp);
cout<<"\nadd another(y/n)?";
cin>>ans;
}
while(ans!='n');
lemp.display();
cout<<endl;
return 0;
}