Instituto de Computação - UNICAMP

MC111 - Introdução ao Processamento de Dados

Prova 3 - Versão B

Islene Calciolari Garcia

Primeiro semestre de 2002

  1. (2 pontos) Indique qual será a saída do programa abaixo:
    program verifica_saida;
    
    procedure proc1(var a: integer; var b: integer);
    begin 
        a := a + 1; 
        b := b + 1;
    end;
    
    procedure proc2(a: integer; b: integer);
    begin
       proc1(a, b);
       writeln ('a = ', a);
       writeln ('b = ', b);
    end;
    
    var
       x, y: integer;
    begin
       x := 1; y := 2;
       proc2(x, y);
       writeln ('x = ', x);
       writeln ('y = ', y);
    end.
    
    Resposta:
    a = 2
    b = 3
    x = 1
    y = 2
    
  2. Considere as seguintes declarações:
    const tam_vet = 100;
    type tipo_vetor = array [1..tam_vet] of real;
    
  3. (2 pontos) Considere as seguintes declarações:
    const n_linhas = 100, n_colunas = 100;
    type tipo_matriz = array [1..n_linhas, 1..n_colunas] of integer;
    
    Escreva um procedimento que multiplica os elementos de uma matriz por um escalar x.

    Resposta:

    procedure mult_escalar (var mat: tipo_matriz; x: integer); 
    var
       i, j: integer;
    begin
       for i := 1 to n_linhas do
         for j := 1 to n_colunas do
            mat[i,j] := mat[i,j] * x;
    end;
    
  4. (2 pontos) Escreva o conteúdo do arquivo saida.txt após a execução do programa abaixo:
    program verifica_saida;
    var
       arq1, arq2, arq3 : text;
       v1, v2	    : integer;
       
    begin
       assign (arq1, 'dados1.txt'); reset(arq1);
       assign (arq2, 'dados2.txt'); reset(arq2);
       assign (arq3, 'saida.txt');  rewrite(arq3);
    
       while (not eof(arq1)) and (not eof(arq2)) do
       begin
          readln(arq1, v1);
          readln(arq2, v2);
          writeln(arq3, v1 + 2 * v2);
       end;
       while (not eof(arq1)) do 
       begin
          readln(arq1, v1);
          writeln(arq3, v1);
       end;
       while (not eof(arq2)) do 
       begin
          readln(arq2, v2);
          writeln(arq3, 2 * v2);
       end; 
       close(arq1);
       close(arq2);
       close(arq3);
    end.
    
    

    dados1.txt dados2.txt saida.txt
    5 2 9
    1 1 3
    3 2 7
    2 3 8
    9 1 11
    8 8
    10 10


    Islene Calciolari Garcia