Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program agenda;
- uses crt;
- const
- MAX = 100;
- var
- nomes : array[1..MAX] of string;
- lista:array[1..MAX] of record
- tel1,tel2,cel:string[10];
- end;
- i,j,k:integer;
- sn,op:char;
- elementoProcurado,aux:string;
- procedure incluiOrdenado (nomeNovo: string);
- var
- nomeAux: string;
- antes, depois: integer;
- begin
- { Primeiro teste. Se não tem nenhum nome no array,
- faço uma inserção direta. }
- if (i = 0) then
- begin
- nomes [i + 1] := nomeNovo;
- end
- else if (i >= 1) then
- begin
- nomes [i + 1] := nomeNovo;
- depois := i + 1;
- antes := i;
- while (nomes [antes] > nomes [depois]) and (antes > 0) do
- begin
- nomeAux := nomes [depois];
- nomes [depois] := nomes [antes];
- nomes [antes] := nomeAux;
- antes := antes - 1;
- depois := depois - 1;
- end;
- end;
- end;
- procedure incluir;
- var
- nomeNovo: string;
- conta: integer;
- begin
- i := 0;
- while (i < MAX) do
- begin
- writeln ('Digite um novo nome');
- readln (nomeNovo);
- incluiOrdenado (nomeNovo);
- i := i + 1;
- writeln('Deseja incluir novo contato?');
- end;
- clrscr;
- writeln ('Array lotado!');
- writeln;
- writeln ('Nomes ordenados:');
- writeln;
- end;
- procedure busca;
- var
- procuraContato: string;
- BEGIN
- write('Informe o nome: '); readln(ProcuraContato);
- writeln('=========================================');
- IF ( ProcuraContato <> '' ) THEN
- BEGIN
- FOR i := 1 TO MAX DO
- BEGIN
- IF (ProcuraContato = nomes[i]) THEN
- BEGIN
- writeln('Nome : ', nomes[i]);
- writeln('Telefone : ', lista[i].tel1);
- writeln('Email : ', lista[i].cel);
- writeln('-----------------------------------------');
- END;
- END;
- IF (ProcuraContato <> nomes[i]) THEN
- writeln('Contato nao encontrado.');
- END;
- readln;
- clrscr;
- END;
- procedure listagem;
- begin
- for i := 1 to MAX do
- writeln ('Nome ', i, ' ', nomes [i]);
- writeln;
- end;
- procedure edita;
- var
- procuraContato: string;
- begin
- write('Informe o nome do contato que deseja alterar: '); readln(ProcuraContato);
- writeln('=========================================');
- FOR i := 1 TO MAX DO
- BEGIN
- IF (ProcuraContato = nomes[i]) THEN
- BEGIN
- write('Nome [ ',nomes[i],'] : '); readln( nomes[i] );
- write('Telefone [ ',lista[i].tel1,'] : '); readln( lista[i].tel1 );
- write('Celular [ ',lista[i].cel,'] : '); readln( lista[i].cel );
- writeln('-----------------------------------------');
- END;
- END;
- readln;
- clrscr;
- END;
- begin
- repeat
- writeln('Bem-vindo(a) à agenda!');
- writeln('1- Para incluir novo contato');
- writeln('2- Para busca um contato');
- writeln('4- Para listagem');
- writeln('5- Para editar contato');
- writeln('6- Sair');
- readln(op);
- case op of
- '1': incluir;
- '2': busca;
- '4': listagem;
- '5': edita;
- else
- end;
- until op = '6'
- end.
Add Comment
Please, Sign In to add comment