// CliListaAlunos.cpp
// Cliente das classes Template cLista<class T> e cListaOrdenada<class T> 

// Aula de 10 de Janeiro de 2002

#include "aluno.h"
#include "ListaOrdenada.h"
#include <iostream.h>
#include <iomanip.h>

void Listar();

enum { INSERIR = 1, REMOVER , LISTAR , TERMINAR };

void ClearScreen();

cListaOrdenada<cAluno> Lista;

void main()
{  	
  int Opcao, Nr;
  char Nome[30];
  bool Res;

  do 
  {
	ClearScreen();	

	cout << endl << endl ;
	cout << "1. Inserir aluno" << endl ;
	cout << "2. Remover aluno" << endl ;
	cout << "3. Listar alunos" << endl;
	cout << "4. Terminar  " << endl;
	cout << endl << endl ;

	cout << "\tEscolha opcao : ";
	cin >> Opcao ;
	cout << endl << endl ;
	
	switch ( Opcao )
	{		
	 
	 case INSERIR :
			cout << "Nr do aluno : "  ; cin >> Nr; cin.ignore();
			cout << "Nome do aluno : "; cin.get( Nome , 30 );
			
			Lista.Inserir( cAluno( Nr, Nome ) ); 
			
			cout << "Aluno inserido na lista !" << endl;
			break;
	 case REMOVER:
			cout << "Nr do aluno : "  ; cin >> Nr;
			
			Res = Lista.Remover( cAluno(Nr,"") );
			
			if( Res )
				cout << "Aluno nr " << Nr << " removido da lista ! " << endl;
			else
				cout << "Nao consta na lista o aluno com o nr " << Nr << " !" << endl;

			break;
	 case LISTAR:			
			Listar();
			break; 
	}
		
	cin.ignore();
	cin.get();

  } while ( Opcao != TERMINAR );

}

void ClearScreen()
{
	int i;
	for ( i=0; i<24; i++ ) cout << endl;
}

void Listar()
{
	int i;
	cAluno *p;

	for( i=1; i <= Lista.GetNrElementos() ; i++ )
	{
		p = Lista.Obter(i);
		cout << setw(5) << p->GetNr() << "  " << p->GetNome() << endl;
	}
}
