Pascal/Turbo Pascal - necesito ayuda con arreglos de 2 dimensiones

 
Vista:

necesito ayuda con arreglos de 2 dimensiones

Publicado por kenneth (1 intervención) el 27/07/2013 04:24:09
tengo un problema con un calificador no valido y no se como arreglarlo alguien me podria ayudar!? se los agradeceria! el programa se trata de que hay 6 armarios en los cuales hay 5 estantes de 12 espacios en cada armario y no puedo hacerlo con arreglos de mas de 2 dimensiones; este es el codigo

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
program	 estanterias;
uses
	crt, dos;
const
	d1 = 6;
	d2 = 5;
	esp = 12;
type
	codigo = record
		titulo: string;
		autor: string;
		tematica: string;
	end;
 
	codigo2 = record
		editorial: string;
		anio: string;
	end;
var
	armario: array[1..d1] of integer;
	almacena: array[1..d2, 1..esp] of codigo;
	arm, fil, col: integer;
 
procedure ingresar_libros;
var
	almacena2: array[1..d2, 1..esp] of codigo2;
begin
	for arm:= 1 to d1 do
		for fil:= 1 to d2 do
			for col:= 1 to esp do begin
				write('Ingrese titulo del libro: ');
				readln(almacena[arm,fil,col].titulo);
				write('Ingrese autor del libro: ');
				readln(almacena[arm,fil,col].autor);
				write('Ingrese tematica del libro: ');
				readln(almacena[arm,fil,col].tematica);
				write('Ingrese editorial del libro: ');
				readln(almacena2[arm,fil,col].editorial);
				write('Ingrese anio del libro: ');
				readln(almacena2[arm,fil,col].anio);
			end; {for col}
end;
 
procedure mostrar_libros;
var
	almacena2: array[1..d2, 1..esp] of codigo2;
begin
	writeln('Titulo	 Autor	Tematica   Editorial	Anio');
	arm:= 0;
	fil:= 0;
	col:= 0;
	for arm:= 1 to d1 do
		for fil:= 1 to d2 do
			for col:= 1 to esp do begin
				writeln('Titulo: 'almacena[arm,fil,col].titulo);
				writeln('Autor: 'almacena[arm,fil,col].autor);
				writeln('Tematica: 'almacena[arm,fil,col].tematica);
				writeln('Editorial: 'almacena2[arm,fil,col].editorial);
				writeln('Anio: 'almacena2[arm,fil,col].anio);
			writeln;
			end; {for col}
	        writeln; writeln;
end;
 
procedure buscar;
var
	buscado: string;
	control: integer;
	almacena2: array[1..d2, 1..esp] of codigo2;
begin
	control:= 0;
	write(;Ingrese libro a buscar: ');
	readln(buscado);
	for arm:= 1 to d1 do
		for fil:= 1 to d2 do
			for col:= 1 to esp do begin
				if(buscado = almacena[arm,fil,col].titulo) then begin
					writeln('Esta en la posicion ', arm ', ', fil ', ', col);
					writeln('Titulo: 'almacena[arm,fil,col].titulo);
					writeln('Autor: 'almacena[arm,fil,col].autor);
					writeln('Tematica: 'almacena[arm,fil,col].tematica);
					writeln('Editorial: 'almacena2[arm,fil,col].editorial);
					writeln('Anio: 'almacena2[arm,fil,col].anio);
					control:= 1;
				end; {if}
	if(control = 0) then
		writeln('No esta');
end;
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

necesito ayuda con arreglos de 2 dimensiones

Publicado por ramon (2158 intervenciones) el 28/07/2013 13:51:37
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
{Fíjate en las correcciones en pascal no puede entrar variables de mas de 64000 bytes sino
dará error  por ello te tengo que cambiar los tamaños de los string y para el año lo paso
a integer puesto que es numero.}
 
program	 estanterias;
 uses
   crt, dos;
 const
    d1 = 6;
    d2 = 5;
    esp = 12;
 type
     codigo2 = record
        editorial : string[40];
        anio : integer;
    end;
 
  codigo = record
    titulo : string[40];
     autor : string[40];
  tematica : string[40];
     codes : codigo2;
   end;
 
  almacena = array[1..d2,1..esp] of codigo;
 
var
  armario : array[1..d1] of almacena;
  libro, arm, fil, col: integer;
 
  procedure ingresar_libros;
  var
    tt : char;
  begin
   tt := #0;
   arm := 1;
   fil := 1;
   col := 1;
 repeat
   repeat
        clrscr;
        writeln('Armario Num : ',arm,'   Estanteria : ',fil,'    Espacio : ',col);
        writeln;
        write('Ingrese titulo del libro : ');
        readln(armario[arm][fil,col].titulo);
        write('Ingrese autor del libro : ');
        readln(armario[arm][fil,col].autor);
        write('Ingrese tematica del libro : ');
        readln(armario[arm][fil,col].tematica);
        write('Ingrese editorial del libro : ');
        readln(armario[arm][fil,col].codes.editorial);
        write('Ingrese a¤o del libro : ');
        readln(armario[arm][fil,col].codes.anio);
        libro := libro + 1;
        writeln('**** Desea Entrar Mas Libros [S/N] ****');
        repeat
            tt := upcase(readkey);
        until tt in['S','N'];
        if tt = 'S' then
        col := col + 1;
      until (tt = 'N') or (col > 12);
      if tt <> #0 then
      tt := #0;
      writeln('**** Desea Colocar Mas Estanterias [S/N] ****');
        repeat
            tt := upcase(readkey);
        until tt in['S','N'];
        if tt = 'S' then
        begin
        fil := fil + 1;
        if fil > 5 then
        begin
           arm := arm + 1;
           fil := 1;
        end;
        col := 1;
        end;
     until (tt = 'N') or (arm > 6);
 end;
 
 procedure mostrar_libros;
 begin
     if libro = 0 then
     begin
        writeln('  No Libros Disponibles Pulse Una Tecla ');
        readkey;
     end
  else
     begin
   for arm := 1 to d1 do
    begin
    for fil := 1 to d2 do
     begin
     for col := 1 to esp do
     begin
        if armario[arm][fil,col].titulo <> '' then
        begin
        writeln('Titulo    : ',armario[arm][fil,col].titulo);
        writeln('Autor     : ',armario[arm][fil,col].autor);
        writeln('Tematica  : ',armario[arm][fil,col].tematica);
        writeln('Editorial : ',armario[arm][fil,col].codes.editorial);
        writeln('A¤o       : ',armario[arm][fil,col].codes.anio);
        writeln;
         end;
        end; {for col}
       end;
     end;
   end;
      readkey;
  end;
 
 procedure buscar;
 var
   buscado : string[40];
   control : integer;
   begin
       clrscr;
       if libro = 0 then
       begin
        writeln('  No Libros Disponibles Pulse Una Tecla ');
        readkey;
     end
  else
     begin
        control := 0;
        write('Ingrese libro a buscar : ');
        readln(buscado);
  for arm := 1 to d1 do
  begin
    for fil := 1 to d2 do
    begin
      for col := 1 to esp do
      begin
      if buscado = armario[arm][fil,col].titulo then
      begin
        writeln('Esta en la posicion ', arm ,'  ', fil ,'  ', col);
        writeln;
        writeln('Titulo    : ',armario[arm][fil,col].titulo);
        writeln('Autor     : ',armario[arm][fil,col].autor);
        writeln('Tematica  : ',armario[arm][fil,col].tematica);
        writeln('Editorial : ',armario[arm][fil,col].codes.editorial);
        writeln('A¤o       : ',armario[arm][fil,col].codes.anio);
        control := 1;
       end;
      end; {if}
     end;
    end;
  end;
    if control = 0 then
    writeln('No esta');
    readkey;
  end;
 
  procedure menu;
  var
    sal : boolean;
    tec : char;
   begin
      sal := false;
    repeat
       clrscr;
       writeln('**** Menu General ****');
       writeln;
       writeln('   1 = Entradas Libros');
       writeln('   2 = Mostrar Libros');
       writeln('   3 = Buscar Libro');
       writeln('   4 = Salir');
       writeln;
       writeln('<<<<< Elija Opcion >>>>>');
       repeat
           tec := readkey;
       until tec in['1','2','3','4'];
       clrscr;
   case tec of
  '1' : begin clrscr; ingresar_libros; end;
  '2' : begin clrscr; mostrar_libros; end;
  '3' : begin clrscr; buscar; end;
  '4' : sal := true;
   end;
  until sal = true;
 end;
 
 begin
     libro := 0;
     menu;
 end.
 
{Espero esto te sirva sino tendrás que trabajar con puntero}
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