Guest User

Untitled

a guest
Feb 19th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 4.15 KB | None | 0 0
  1. program agenda;
  2. uses crt;
  3. const
  4.   MAX = 100;
  5. var
  6. nomes  : array[1..MAX] of string;
  7. lista:array[1..MAX] of record
  8.                         tel1,tel2,cel:string[10];
  9.                
  10.                            end;
  11.    
  12. i,j,k:integer;
  13. sn,op:char;
  14. elementoProcurado,aux:string;
  15.  
  16. procedure incluiOrdenado (nomeNovo: string);
  17. var
  18.     nomeAux: string;
  19.     antes, depois: integer;
  20. begin
  21.     { Primeiro teste. Se não tem nenhum nome no array,
  22.       faço uma inserção direta. }
  23.     if (i = 0) then
  24.         begin
  25.         nomes [i + 1] := nomeNovo;
  26.         end
  27.  
  28.     else if (i >= 1) then
  29.         begin
  30.         nomes [i + 1] := nomeNovo;
  31.         depois := i + 1;
  32.         antes := i;
  33.  
  34.         while (nomes [antes] > nomes [depois]) and (antes > 0) do
  35.             begin
  36.             nomeAux := nomes [depois];
  37.             nomes [depois] := nomes [antes];
  38.             nomes [antes] := nomeAux;
  39.             antes := antes - 1;
  40.             depois := depois - 1;
  41.             end;
  42.         end;
  43. end;
  44.  
  45. procedure incluir;
  46.  
  47. var
  48.     nomeNovo: string;
  49.     conta: integer;
  50. begin
  51.     i := 0;
  52.     while (i < MAX) do
  53.         begin
  54.         writeln ('Digite um novo nome');
  55.         readln (nomeNovo);
  56.         incluiOrdenado (nomeNovo);
  57.         i := i + 1;
  58.         writeln('Deseja incluir novo contato?');
  59.         end;
  60.  
  61.     clrscr;
  62.     writeln ('Array lotado!');
  63.     writeln;
  64.     writeln ('Nomes ordenados:');
  65.     writeln;
  66.  
  67.    
  68. end;
  69.  
  70. procedure busca;
  71. var
  72.  procuraContato: string;
  73.   BEGIN
  74.                         write('Informe o nome: ');  readln(ProcuraContato);
  75.                         writeln('=========================================');
  76.                         IF ( ProcuraContato <> '' ) THEN
  77.                         BEGIN
  78.                                 FOR i := 1 TO MAX DO
  79.                                 BEGIN
  80.                                         IF (ProcuraContato = nomes[i]) THEN
  81.                                         BEGIN
  82.                                                 writeln('Nome     : ', nomes[i]);
  83.                                                 writeln('Telefone : ', lista[i].tel1);
  84.                                                 writeln('Email    : ', lista[i].cel);
  85.                                                 writeln('-----------------------------------------');
  86.                                         END;
  87.                                 END;
  88.                                
  89.                                 IF (ProcuraContato <> nomes[i]) THEN
  90.                                         writeln('Contato nao encontrado.');
  91.                                        
  92.                         END;
  93.                        
  94.                         readln;
  95.                         clrscr;
  96.                 END;
  97.  
  98.    
  99. procedure listagem;
  100.   begin
  101.   for i := 1 to MAX do
  102.         writeln ('Nome ', i, ' ', nomes [i]);
  103.         writeln;
  104.    
  105.          
  106.        
  107.     end;       
  108.        
  109. procedure edita;
  110.  var
  111.  procuraContato: string;
  112.     begin
  113.      write('Informe o nome do contato que deseja alterar: ');  readln(ProcuraContato);
  114.                           writeln('=========================================');
  115.                           FOR i := 1 TO MAX DO
  116.                           BEGIN
  117.                                  IF (ProcuraContato = nomes[i]) THEN
  118.                                  BEGIN
  119.                                                                 write('Nome     [ ',nomes[i],']     : '); readln( nomes[i] );
  120.                                                                 write('Telefone [ ',lista[i].tel1,'] : '); readln( lista[i].tel1 );
  121.                                                                 write('Celular    [ ',lista[i].cel,']    : '); readln( lista[i].cel );
  122.                                                                 writeln('-----------------------------------------');
  123.                                  END;
  124.                           END;
  125.                           readln;
  126.                           clrscr;
  127.                 END;       
  128.        
  129. begin
  130.     repeat
  131.       writeln('Bem-vindo(a) à agenda!');
  132.       writeln('1- Para incluir novo contato');
  133.       writeln('2- Para busca um contato');
  134.       writeln('4- Para listagem');
  135.       writeln('5- Para editar contato');
  136.       writeln('6- Sair');
  137.       readln(op);
  138.          case op of
  139.            '1': incluir;
  140.            '2': busca;
  141.            '4': listagem;
  142.            '5': edita;
  143.          else
  144.          end;
  145.        
  146.   until op = '6'  
  147.  end.
Add Comment
Please, Sign In to add comment