Pascal/Turbo Pascal - Ayuda con archivos

 
Vista:

Ayuda con archivos

Publicado por Juancito (20 intervenciones) el 07/08/2013 15:55:10
Alguien que me pueda dar una mano... Ya que no entiendo como trabajarlo.

Suponga que tiene un archivo donde cada registro es un arreglo de 5 enteros. Cada entero
corresponde a la nota en la materia 1, 2, 3, 4 y 5 de los alumnos de primer año de una
carrera. Cada registro del archivo corresponde a las notas de un alumno y el archivo
contiene las notas de todos los alumnos de primer año de la carrera. Codifique un
procedimiento que devuelva un arreglo con la nota promedio en
cada una de las materias.

Este seria el archivo:

| 7 | 6 | 5 | 7 | 8 |
| 3 | 9 | 8 | 5 | 4 |
| 6 | 8 | 9 | 5 | 3 |
| 5 | 6 | 5 | 7 | 8 |
| 3 | 9 | 2 | 5 | 4 |
| 6 | 8 | 2 | 4 | 3 |

Este el promedio de cada materia (array)

| 5 | 8 | 5 | 6 | 5 |

PD: Estoy estudiando Introduccion a la Programacion con Pascal y es muy basico como lo utilizamos
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

Ayuda con archivos

Publicado por ramon (2158 intervenciones) el 08/08/2013 12:11:15
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
{A ver si esto os ayuda un poco}
 
 program archivon;
 uses
    crt;
  const
      maxalum = 6;
      maxnot = 5;
      nombre = 'c:\tp\bin\notas.dat';
   ejemplo : array[1..maxalum,1..maxnot] of integer = (
   (7,6,5,7,8),
   (3,9,8,5,4),
   (6,8,9,5,3),
   (5,6,5,7,8),
   (3,9,2,5,4),
   (6,8,2,4,3));
 
   type
      alumnos = record
            numero : integer;
            notas : array[1..maxnot] of integer;
            end;
 
   var
     f : file of alumnos;
     regalum : alumnos;
     media :   array[1..maxalum] of integer;
 
 
   procedure guarda_a_archivo;
   begin
      assign(f,nombre);
  {$I-} reset(f); {$I+}
      if ioresult <> 0 then
      begin
          rewrite(f);
          seek(f,0);
          write(f,regalum);
          close(f);
      end
   else
       begin
          seek(f,filesize(f));
          write(f,regalum);
          close(f);
       end;
   end;
 
   procedure carga_ejemplo;
   var
     v, n : integer;
   begin
       writeln('   Las Notas Son ');
       writeln;
      for v := 1 to maxalum do
      begin
       regalum.numero := v;
       for n := 1 to maxnot do
       begin
           regalum.notas[n] := ejemplo[v][n];
           write('  ',regalum.notas[n]);
       end;
        writeln;
        guarda_a_archivo;
   end;
  end;
 
  procedure presenta_notas_medias;
  var
    lanota, d, y, m : integer;
    materi : array[1..maxalum,1..maxnot] of integer;
   begin
       assign(f,nombre);
  {$I-} reset(f); {$I+}
      if ioresult <> 0 then
      begin
         writeln('**** Error De Archivo Pulse Una Tecla ****');
         readkey;
         exit;
      end
    else
       begin
           d := 0;
           y := 1;
         repeat
            seek(f,d);
            read(f,regalum);
            lanota := 0;
            for m := 1 to maxnot do
            begin
               materi[y,m] := regalum.notas[m];
            end;
            y := y + 1;
            d := d + 1;
         until d > filesize(f) - 1;
         writeln;
       for d := 1 to maxnot do
       begin
         lanota := 0;
         for y := 1 to maxalum do
         begin
         lanota := lanota + materi[y,d];
         end;
         media[d] := round(lanota / maxalum);
        end;
         writeln('   Las Medias Son ');
         writeln;
         for y := 1 to maxnot do
         write('  ',media[y]);
         readkey;
       end;
   end;
 
 
 
   begin
       clrscr;
       carga_ejemplo;
       presenta_notas_medias;
       erase(f);
   end.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar