#include <iostream.h>
#include <string.h>
#include <conio.h>
#include <ctype.h>
#include <stdlib.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 out1(char *);
    int out2(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 *m){if(!(strcmp(m,facnomer))){return 1;}else return 0;}
   int student::out1(char *m){if(!(strcmp(m,name))){return 1;}else return 0;}
   int student::out2(char *m){if(!(strcmp(m,spec))){return 1;}else return 0;}

   struct element
{ element *next;			
   student *content;		
};

class list
{ element *begin;
   element *current;
   public:
   list()  { begin = NULL; current = begin; }
   ~list();
void newl(student *);
void first() { current = begin; }	
student *next_el()
  { student *ad = NULL;	       
     if(current != NULL)	
	{ ad = current -> content;
	   current = current -> next;
	}
       return ad;
  }
 student *next_el1()
  { student *ad = NULL;	       
     if(current != NULL)	
	{ ad = current -> content;
	   
	}
       return ad;
  }
void iztrivane();
void out_list();
void out_list(char *);
void out_list1(char *);
void out_list2(char *);
void out_list3(char *);
void out_list4(char *);
void out_list5(char *);
int end()			
  { return (current == NULL); }
};

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

  void list::iztrivane()
  {element *ad=NULL;
  if(current != NULL)
	 {  ad = current -> next;
	    current->content= ad->content;
	    current = ad;
	}
  }



void list::newl(student *x)
  { element *adel = new element;
     adel -> next = begin;
     adel -> content = x;
     begin = adel;
  }

void list :: out_list()
   { student *ptr;
      first();
      while( !end() )
	{ ptr =next_el();
	  ptr->out();
	}
   }

void list :: out_list(char *x)
   { student *ptr; 
      first(); 
      while( !end() )
	{ ptr =next_el();
         if(ptr->out(x))
	  ptr->out();
	  else; 
	}
   }
  
 void list :: out_list1(char *x)
   { student *ptr;
      first();
      while( !end() )
	{ ptr =next_el();
         if(ptr->out1(x))
	  ptr->out();
	}
   }

   void list :: out_list2(char *x)
   { student *ptr;
      first();
      while( !end() )
	{ ptr =next_el();
	 if(ptr->out2(x))
	  ptr->out();
	}
   }

    void list :: out_list3(char *x)
   { student *ptr;
      first();
      while( !end() )
	{ ptr =next_el1();
	 if(ptr->out(x)){
	 cout<<"iztrivane na student"<<endl; ptr->out();
	  while( !end() )
	 {iztrivane();}}
	 else
	 current = current -> next;
	}
   }

       void list :: out_list4(char *x)
   { student *ptr;
      first();
      while( !end() )
	{ ptr =next_el1();
	 if(ptr->out1(x)){
	 cout<<"iztrivane na student"<<endl; ptr->out();
	  while( !end() )
	 {iztrivane();}}
	 else
	 current = current -> next;
	}
   }

       void list :: out_list5(char *x)
   { student *ptr;
      first();
      while( !end() )
	{ ptr =next_el1();
	 if(ptr->out2(x)){
	 cout<<"iztrivane na student"<<endl; ptr->out();
	  while( !end() )
	 {iztrivane();}}
	 else
	 current = current -> next;
	}
   }

void main()
 { list l;
 int k=0,i=0,n=0;
  char q;
do{
   cout<<"kolko studenti 6te vavejdate;"<<endl;
   cin>>i;
   student *a;
   for(n=0;n<i;n++)
   { cout<<"vavedete student :"<<(n+1)<<endl; 
    a=new student;
   l.newl(a);}
   char FN[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>>k;
        if(k<1||k>7)
	cout<<"\nGreshen vhod"; 
        else {
       	cout<<"\n vavedi danni po koito da zapo4ne tarseneto" ;
		switch(k){
		case 1:cout<<"vavedete fakulteten nomer"<<endl;
                cin>>FN;
		l.out_list(FN);break;
		case 2:cout<<"vavedete ime"<<endl; 
		 cin>>NAME ;  l.out_list1(NAME); break;
		case 3:cout<<"vavedete specialnost"<<endl;
		cin>>SPEC;  l.out_list2(SPEC); break; 
		case 4:cout<<"vavedete fakulteten nomer"<<endl;
                cin>>FN; l.out_list3(FN);break;
		case 5:cout<<"vavedete ime"<<endl; 
		 cin>>NAME ;   l.out_list4(NAME); break;
		case 6:cout<<"vavedete specialnost"<<endl;
		cin>>SPEC;  l.out_list5(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.out_list();
   	      cout<<"jelaete li da vavedete nov zapis "<<endl;
              cout<<"otgovorite sa Y i N "<<endl;
	q=getch();
    }
    while(toupper(q)=='Y');
   exit(0);
 }