#include <iostream.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>




class student
  {
    char facnomer[9];
    char *name,*spec;
    public:
    student();
    ~student();
    void out(){cout <<" fakulteten nomer:"  << facnomer <<"\n ime:"<< name << "\n specialnost:"<< spec<<endl;}
    int out(char *);
    int outt(char *);
    int outtt(char *);
  };

   student::student()   
  {cout<<"vavedete fakulteten nomer"<<endl;
   cin>>facnomer ;
   char n[100];  

   cout<<"vavedete ime"<<endl;
   cin>>n ;
   name=new char[strlen(n)+1];
        if(!name) exit(1);
	strcpy(name,n);
   cout<<"vavedete specialnost"<<endl;
   cin>>n;
   spec=new char[strlen(n)+1];
        if(!spec) exit(1);
	strcpy(spec,n);
   }
    student::~student()
    { if(name)
	       delete [] name;
      if(spec)
	       delete [] spec;
    }
   int student::out(char *j){if(!(strcmp(j,facnomer))){return 1;}else return 0;}
   int student::outt(char *j){if(!(strcmp(j,name))){return 1;}else return 0;}
   int student::outtt(char *j){if(!(strcmp(j,spec))){return 1;}else return 0;}

   struct element
{ element *sledv;			
   student *sadar;		
};

class list
{ element *begin;
   element *current;
   public:
   list()  { begin = NULL; current = begin; }
   ~list();
void newn(student *);
void first() { current = begin; }	
student *sledv_el()
  { student *d = NULL;	       
     if(current != NULL)	
	{ d = current -> sadar;
	   current = current -> sledv;
	}
       return d;
  }
 student *sledv_el1()
  { student *d = NULL;	       
     if(current != NULL)	
	{ d = current -> sadar;
	   
	}
       return d;
  }
void iztrivane();
void outl();
void outl(char *);
void out1(char *);
void out2(char *);
void out3(char *);
void out4(char *);
void out5(char *);
int end()			
  { return (current == NULL); }
};

list :: ~list()
  { element *sledv_el;
    current = begin;
     while(current != NULL)
	{ sledv_el = current -> sledv;
	   delete current;
	   current = sledv_el;
	}
  }

  void list::iztrivane()
  {element *d=NULL;
  if(current != NULL)
	 {  d = current -> sledv;
	    current->sadar= d->sadar;
	    current = d;
	}
  }



void list::newn(student *j)
  { element *f = new element;
     f -> sledv = begin;
     f -> sadar = j;
     begin = f;
  }

void list :: outl()
   { student *p;
      first();
      while( !end() )
	{ p =sledv_el();
	  p->out();
	}
   }

void list :: outl(char *j)
   { student *p; 
      first(); 
      while( !end() )
	{ p =sledv_el();
         if(p->out(j))
	  p->out();
	  else; 
	}
   }
  
 void list :: out1(char *j)
   { student *p;
      first();
      while( !end() )
	{ p =sledv_el();
         if(p->outt(j))
	  p->out();
	}
   }

   void list :: out2(char *j)
   { student *p;
      first();
      while( !end() )
	{ p =sledv_el();
	 if(p->outtt(j))
	  p->out();
	}
   }

    void list :: out3(char *j)
   { student *p;
      first();
      while( !end() )
	{ p =sledv_el1();
	 if(p->out(j)){
	 cout<<"iztrivane na student"<<endl; p->out();
	  while( !end() )
	 {iztrivane();}}
	 else
	 current = current -> sledv;
	}
   }

       void list :: out4(char *j)
   { student *p;
      first();
      while( !end() )
	{ p =sledv_el1();
	 if(p->outt(j)){
	 cout<<"iztrivane na student"<<endl; p->out();
	  while( !end() )
	 {iztrivane();}}
	 else
	 current = current -> sledv;
	}
   }

       void list :: out5(char *j)
   { student *p;
      first();
      while( !end() )
	{ p =sledv_el1();
	 if(p->outtt(j)){
	 cout<<"iztrivane na student"<<endl; p->out();
	  while( !end() )
	 {iztrivane();}}
	 else
	 current = current -> sledv;
	}
   }

void main()
 { list l;
 int x=0,y=0,z=0;
  char q;
do{
   cout<<"kolko studenti 6te vavejdate;"<<endl;
   cin>>y;
   student *a;
   for(z=0;z<y;z++)
   { cout<<"vavedete student :"<<(z+1)<<endl; 
    a=new student;
   l.newn(a);}
   char FACNOMER[9],NAME[60],SPEC[20];
  
  do{
         cout << "           Menu            "<< endl;
	cout << "Tursene na student po:     "<< endl;
	cout << "1  Fakulteten nomer	      "<< endl;
	cout << "2  Ime                    "<< endl;
	cout << "3  Specialnost	      "<< endl;
	cout << "Triene na student po:      "<< endl;
	cout << "4 Fakulteten nomer       "<< endl;
	cout << "5 Ime                    "<< endl;
	cout << "6  Specialnost            "<< endl;
         cout << "\nVaishiqt izbor? ";
	cin>>x;
        if(x<1||x>7)
	cout<<"\nGreshen vhod"; 
        else {
       	cout<<"\n vavedi danni po koito da zapo4ne tarseneto" ;
		switch(x){
		case 1:cout<<"vavedete fakulteten nomer"<<endl;
                cin>>FACNOMER;
		l.outl(FACNOMER);break;
		case 2:cout<<"vavedete ime"<<endl; 
		 cin>>NAME ;  l.out1(NAME); break;
		case 3:cout<<"vavedete specialnost"<<endl;
		cin>>SPEC;  l.out2(SPEC); break; 
		case 4:cout<<"vavedete fakulteten nomer"<<endl;
                cin>>FACNOMER; l.out3(FACNOMER);break;
		case 5:cout<<"vavedete ime"<<endl; 
		 cin>>NAME ;   l.out4(NAME); break;
		case 6:cout<<"vavedete specialnost"<<endl;
		cin>>SPEC;  l.out5(SPEC); break; }
	     } cout<<"jelaete li da vavedete nova opciq "<<endl;
              cout<<"otgovorite sa Y i N "<<endl;
	q=getch();
    }
    while(toupper(q)=='Y');
    cout<<"\nCeliq spisak e:"<<endl;
   l.outl();
   	      cout<<"jelaete li da vavedete nov zapis "<<endl;
              cout<<"otgovorite sa Y i N "<<endl;
	q=getch();
    }
    while(toupper(q)=='Y');
   exit(0);
 }