#include <iostream.h>
#include <time.h>
#include <string>
#include "list.h"
#include "ListIterator.h"

class Persona {
public: 
  Persona(string s):nome(s) {  }
  virtual void print() { cout << "Il mio nome e' " << nome << endl; }
  static Persona* factory(int tipo,string nome, int dato); 
protected:
  string nome;
};

class Studente : public Persona {
public: 
  Studente(string s, float g) : Persona(s),media(g) { }
  void print() { cout << "Il mio nome e' " << nome
     << " e la mia media e' " << media << endl; }
private:
  float media;
};

class Professore : public Persona {
public: 
  Professore(string s, int n) : Persona(s), pubblicazioni(n) { }
  void print() { cout << "Il mio nome e' " << nome
     << " ed ho  " << pubblicazioni << " pubblicazioni" << endl; }
private:
  int pubblicazioni;
};

class Dottorando : public Persona {
public: 
  Dottorando (string s, int n) : Persona(s),numero_anni(n) { }
  void print() { cout << "Il mio nome e' " << nome
     << " e sono un dottorando con " << numero_anni << " anni di frequenza" << endl; }
private:
  int numero_anni;
};
Persona* Persona::factory(int tipo,string nome, int dato) 
   {
      if(tipo==1) return new Persona(nome);
      if(tipo==2) return new Studente(nome,dato);
      if(tipo==3) return new Professore(nome,dato);
      if(tipo==4) return new Dottorando(nome,dato);
}
void interroga(Persona *p){p->print();}
int main()
{
  list <Persona> p;
  Persona *x;
  string nome[]={"Giuseppe","Mario","Giovanni","Antonio"};
  int tipo[]={1,2,3,4};                   
  int dato[]={0,30,34,4};                   
  for(int i=0;i<4;i++)
    { 
    
  p.enter(Persona::factory(tipo[i],nome[i],dato[i])); 
   }
  ListIterator<Persona> it(p);
  while(it.next())  interroga(it.current()) ;
        return 0;
}
