segunda-feira, 22 de outubro de 2012



Programas para cadastramento e ordenação de 5 alunos


Exemplo 1 de 2:

program cad_alunos;
uses crt;

var
   mat          : array [1..5] of integer;
   nome         : array [1..5] of string [30];
   notas        : array [1..5,1..3] of real;
   media        : array [1..5] of real;
   i,j,k,l      : integer;
   soma         : real;
   aux_mat      : string [30];
   aux_nota     : real;

begin
     soma:=0;
     clrscr;
     writeln ('Cadastramento de Alunos');
     writeln;
     {*** Cadastramento de Alunos ***}
     for i:= 1 to 5 do
       begin
          write ('Matricula: '); readln (mat);
          write ('Nome     : '); readln (nome);
          for i:= 1 to 5 do
             begin
                writeln ('Notas do ',i,'o. trimestre: ');
                for l:= 1 to 3 do
                  begin
                     write ('Informe a ',l,'a. nota: '); readln (nota[i,l]);
                     soma:= soma + nota[i,l];
                  end;
          media[i]:= soma / 3;
       end;

       {*** Ordenacao dos alunos Cadastrados ***}
       for i:= 1 to 4 do
         for j:= i+1 to 5 do
           if mat[i] > mat[j] then
              begin
                 {*** Troca Matricula ***}
                 aux_mat:=mat[i];
                 mat[i]:=mat[j];
                 mat[j]:=aux_mat;

                 {*** Trocar Notas ***}
                 for l:= 1 to 3 do
                     begin
                        aux_nota:= nota[i,l];
                        nota[i,l]:= nota[j,l];
                        nota[j,l]:= aux_nota;
                     end;

                 {*** Troca Media ***}
                 aux_nota:= media[i];
                 media[i]:= media[j];
                 media[j]:= aux_nota;


              end;
end.


Exemplo 2 de 2:


program cad_alunos;
uses crt;

var
   mat          : array [1..5] of integer;
   nome         : array [1..5] of string [30];
   nota         : array [1..5,1..3] of real;
   media        : array [1..5] of real;
   i,j,k,l      : integer;
   soma         : real;
   aux_mat      : integer;
   aux_nota     : real;

begin
   soma:=0;
   clrscr;
   writeln ('Cadastramento de Alunos');
   writeln;
   {*** Cadastramento de Alunos ***}
   for i:= 1 to 5 do
     begin
        write ('Matricula: '); readln (mat[i]);
        write ('Nome     : '); readln (nome[i]);
        for i:= 1 to 5 do
          begin
             writeln ('Notas do ',i,'o. trimestre: ');
             for l:= 1 to 3 do
               begin
                  write ('Informe a ',l,'a. nota: '); readln (nota[i,l]);
                  soma:= soma + nota[i,l];
               end;
          end;
        media[i]:= soma / 3;
     end;

   {*** Ordenacao dos alunos Cadastrados ***}
   for i:= 1 to 4 do
     for j:= i+1 to 5 do
       if mat[i] > mat[j] then
         begin
            {*** Troca Matricula ***}
            aux_mat:=mat[i];
            mat[i]:=mat[j];
            mat[j]:=aux_mat;

            {*** Trocar Notas ***}
            for l:= 1 to 3 do
              begin
                 aux_nota:= nota[i,l];
                 nota[i,l]:= nota[j,l];
                 nota[j,l]:= aux_nota;
              end;

            {*** Troca Media ***}
            aux_nota:= media[i];
            media[i]:= media[j];
            media[j]:= aux_nota;
         end;

   {*** Relatorio dos Alunos Cadastrados ***}
   for i:= 1 to 5 do
     begin
        write ('Matricula: ',mat[i]);
        write ('Nome     : ',nome[i]);
        for i:= 1 to 5 do
          begin
             writeln ('Notas do ',i,'o. trimestre: ');
             for l:= 1 to 3 do
                writeln (l,'a. nota: ',nota[i,l]);
             writeln ('Media : ',media[i]);
          end;
     end;
   writeln;
   writeln ('Tecle <ENTER> para sair ... '); readln;
end.



Nenhum comentário:

Postar um comentário