Program Agenda;
  type
    agenda_pessoa = array[1..10] of String;
 pessoa_contato= record
 nome :  agenda_pessoa;
 endereco :  agenda_pessoa;
 tel :  agenda_pessoa;
  end;
var
   contato_agenda : array[1..10] of pessoa_contato;
   i:integer;
   menu:Char;    
{============================ INICIO DO PROCEDIMENTO -------- Criando o Procedimento para cadastro -------------------------------- }
Procedure  cad_contato ;
  var
    nome:   agenda_pessoa;
    endereco: agenda_pessoa;
    tel:   agenda_pessoa;
    i:    integer;
Begin
  textcolor( lightcyan );
    for i := 1 to  10 do begin
      write( '|  Entre com o nome do  ' , i , ' contato:......| : ' );
   read( contato_agenda[i].nome[i] );
   WRITELN( '' );
   write( '| Entre com o endereco do ' , I , ' contato:..........| : ');
   read( contato_agenda[i].endereco[i] );
   WRITELN( '' );
   write( '| Entre com o telefone do ' , I , ' contato:..........| : ' );
   readln( contato_agenda[i].tel[i] );
    end;
      for i := 1 to  10 do begin
       WRITELN( '' );
        writeLN( '| Listando o nome do ' , i , ' contato.........................| : ' , contato_agenda[i].nome[i] );
        WRITELN( '' );
   writeLN( '| Listando o endereco do ' , i , ' contato..................| : ' , contato_agenda[i].endereco[i] );
   WRITELN( '' );
   writeLN( '| Listando o tel do ' , i , ' contato.....................| : ' , contato_agenda[i].tel[i] );
   WRITELN( '' );
   //WRITELN( ' TECLE ENTER NEXT REGISTRO ' );
      readkey;
 end;
        //WRITELN( 'ENTER NEXT REGISTRO..... ' );
        writeln( ' APÓS LISTAR TODOS OS REGISTRO TECLE ENTER PARA VOLTAR AO MENU. ' );
      readkey;
End;  
{===================== FIM DO PROCEDIMENTO -------- Criando o Procedimento para cadastro -------------------------------- }
{ INICIO DO PROCEDIMENTO -------- Criando o Procedimento para DELETAR cadastro -------------------------------- }
Procedure  deleta_contato ;
{ VARIAVEIS PARA A PESQUISA BINARIA }
  var
    i,j:integer;
    comeco, final, meio:integer;
    pesq, resposta x: string;
    acha: boolean;
//============================================
    nome: agenda_pessoa;
Begin
{INICIANDO A ORDERNAÇÃO}
  for i := 1 to  9 do
    for j := i+1 to 10 do
      if ( contato_agenda[i].nome[i] > contato_agenda[j].nome[j]) then
        begin
          x := contato_agenda[i].nome[i] ;
       contato_agenda[i].nome[i] := contato_agenda[j].nome[j];
  contato_agenda[j].nome[j] := x;
   end;
{ FIM DA ORDERNAÇÃO }
{ INICIANDO A ALTERACAO }
//inicializando a variavel -- RESP
 resposta= 'SIM';
while (resposta= 'SIM')or (resposta= 'sim')do
  begin
    writeln( ' Entre com o nome que deseja deletar: ' );
    readln( pesq );
//INICIALIZANDO AS VARIAVEIS --- COMECO, FINAL , ACHAR;
    COMECO:= 1; FINAL:= 10; ACHA:= false;
    while (comeco <= final ) and ( acha = false ) do
      begin
        meio:= (comeco + final ) div 2;
      if (pesq = contato_agenda[meio].nome[meio] ) then
        acha:= true
      else
        if (pesq < contato_agenda[meio].nome[meio]) then
    final:= meio - 1
 else
   comeco:= meio + 1;
      end;
          IF (acha = true) then
     begin
       contato_agenda[meio].nome[meio] := '';
       writeln( ' registro apagado ' );
     end
       else
         writeln( pesq , ' Registro não existe. ' );
  WRITELN( '' );
{ROTINA PARA ALTERAR NOVAMENTE}
  writeln( ' Deseja deletar outro ocntato: Sim ou Não ? ' );
  readln( resposta);
  readkey;
  end;
{ FINALIZANDO A ALTERAÇÃO }
end;
{ FIM DO PROCEDIMENTO -------- fim do Procedimento para DELETAR cadastro --------------------------------}
{ INICIO DO PROCEDIMENTO -------- Criando o Procedimento para ALTERACAO DE cadastro -----------------------------}
Procedure  altera_contato ;
{ VARIAVEIS PARA A PESQUISA BINARIA } 
  var
    i,j:integer;
    comeco, final, meio:integer;
    pesq, resposta x: string;
    acha: boolean;
//================================================
    nome: agenda_pessoa;
    Perg : Integer;
Begin
{ORDERNAÇÃO}
  for i := 1 to  9 do
    for j := i+1 to 10 do
      if ( contato_agenda[i].nome[i] > contato_agenda[j].nome[j]) then
  begin
    x := contato_agenda[i].nome[i] ;
    contato_agenda[i].nome[i] := contato_agenda[j].nome[j];
    contato_agenda[j].nome[j] := x;
  end;
{ FIM DA ORDERNAÇÃO }
{ iniciando a pesquisa }
 //inicializando a variavel -- RESP
 resposta= 'SIM';
   while (resposta= 'SIM')or (resposta= 'sim')do
   begin
     writeln( ' Entre com o nome que deseja alterar: ' );
     readln( pesq );
//INICIALIZANDO AS VARIAVEIS --- COMECO, FINAL , ACHAR;
     COMECO:= 1; FINAL:= 10; ACHA:= false;
       while (comeco <= final ) and ( acha = false ) do
         begin
           meio:= (comeco + final ) div 2;
            if (pesq = contato_agenda[meio].nome[meio] ) then
        acha:= true
      else
        if (pesq < contato_agenda[meio].nome[meio]) then
          final:= meio - 1
      else
        comeco:= meio + 1;
  end;
     IF (acha = true) then
 //***** Alteração de dados***
      begin
        write ('Para Alterar Informe 1 para contato, 2 para endereço, 3 telefone ou 4 para todos?');
        read (perg);
                 If (perg = 1) or (perg = 10) then
            begin
              writeln( '|  Entre com o novo nome do contato:..........| : ' );
              read( contato_agenda[meio].nome[meio] );
              WRITELN( '' );
            End;
              If (perg = 2) or (perg = 10) then
         begin
             writeln( '| Entre com o endereco do contato:.................| : '  );
              read( contato_agenda[meio].endereco[meio] );
                         WRITELN( '' );
                End;
                    if (perg = 3) or (perg = 10) then
             Begin
        writeln( '| Entre com o telefone do contato:............| : ' );
        readln( contato_agenda[meio].tel[meio] );
      end;
      end
               else
                 writeln( pesq , ' Não foi localizada. ' );
          WRITELN( '' );
{ROTINA PARA PESQUISAR NOVAMENTE}
                writeln( ' Deseja Alterar outro contato: Sim ou Não ? ' );
   readln( resposta);
   readkey;
   end;
    { finalizando a pesquisa }
   End;
{ FIM DO PROCEDIMENTO -------- Criando o Procedimento para cadastro -------------------------------- }
{ INICIO DO PROCEDIMENTO PARA PESQUISA -------- DESENVOLVIDO POR SIMAO NETO -------------------------------- }
Procedure  pesquisa_bin ;
  var
{ VARIAVEIS PARA A PESQUISA BINARIA }
    i,j:integer;
    comeco, final, meio:integer;
    pesq, resposta x: string;
    acha: boolean;
//=========================
    nome: agenda_pessoa;
Begin
{ORDERNAÇÃO}
  for i := 1 to  9 do
    for j := i+1 to 10 do
      if ( contato_agenda[i].nome[i] > contato_agenda[j].nome[j]) then
        begin
          x := contato_agenda[i].nome[i] ;
          contato_agenda[i].nome[i] := contato_agenda[j].nome[j];
          contato_agenda[j].nome[j] := x;
        end;
{ FIM DA ORDERNAÇÃO }
{ iniciando a pesquisa }
//inicializando a variavel -- RESP
resposta= 'SIM';
  while (resposta= 'SIM')or (resposta= 'sim')do
    begin
      writeln( ' Entre com o nome que deseja pesquisar: ' );
      readln( pesq );
//INICIALIZANDO AS VARIAVEIS --- COMECO, FINAL , ACHAR;
     COMECO:= 1; FINAL:= 10; ACHA:= false;
       while (comeco <= final ) and ( acha = false ) do
         begin
           meio:= (comeco + final ) div 2;
             if (pesq = contato_agenda[meio].nome[meio] ) then
           acha:= true
      else
        if (pesq < contato_agenda[meio].nome[meio]) then
          final:= meio - 1
      else
        comeco:= meio + 1;
  end;
       IF (acha = true) then
         writeln( pesq , ' Foi localizado (a) na posição ' ,meio )
       else
        // WRITELN( '' );
         writeln( pesq , ' Não foi localizada. ' );
{ROTINA PARA PESQUISAR NOVAMENTE}
  writeln( ' Deseja Pesquisar Novamente: Sim ou Não ? ' );
  readln( resposta);
  readkey;
    end;
{ finalizando a pesquisa }
End;
{ FIM DO PROCEDIMENTO PARA PESQUISA -------- DESENVOLVIDO POR SIMAO NETO -------------------------------- }
{ INICIO DO PROGRAMA -------- DESENVOLVIDO POR SIMAO NETO -------------------------------- }
BEGIN
//gotoxy(15,10);
textcolor( lightcyan );
textbackground( RED );
  menu:='0';
    while (menu  <> '5') do begin
    clrscr;
      gotoxy(25,1);writeln('ADS - 11 | ED - Estrutura de Dados');
      gotoxy(25, 3); writeln('Equipe de Desenvolvimento');
      gotoxy(25, 5); writeln('venico, patricia');
      gotoxy(28, 7); write('Menu principal');
      gotoxy(28, 7); write('Agenda Eletronica - v0.0.1');
      gotoxy(28, 10); write('1.....................Cadastro de Contatos');
      gotoxy(28, 12); write('2............Pesquisa de Contatos por nome');
      gotoxy(28, 14); write('3......Deleta contato');
      gotoxy(28, 16); write('4................Altera contato');
      gotoxy(28, 18); write('5..Fim do programa');
      gotoxy(28, 20); write('Escolha uma opcao ..........: ');
      readln(menu);
        IF (menu  <> '5') THEN
   case menu OF
   '1': cad_contato;
   '2': Pesquisa_bin;
   '3': deleta_contato;
   '4': altera_contato;
      else
   begin
     gotoxy(27, 25);
     writeln(  'Opcao invalida - tecle algo');
     readkey;
   end;
    end;
end;
End.
 
Nenhum comentário:
Postar um comentário