Pascal/Turbo Pascal - Ejercicio pas no aparece titulo ordenado

 
Vista:
sin imagen de perfil

Ejercicio pas no aparece titulo ordenado

Publicado por Luciano (3 intervenciones) el 20/08/2015 03:23:14
Hola relize este ejercicio donde me dedique a crear un indice de titulos de un libro el titulo viene dado por una palabra clave entre #palabra clave#(esto dentro de una cadena),bien lo que hize fue buscar palabra clave y cargar mi titulo del modo que quede palabra clave continuacion del titulo/el comienzo ej Los #reyes# catolicos

Titulo ordenado (en otra cadena)

reyes catolicos/Los
una vez ordenado mi titulo lo que hize es cargar mi cadena en un arreglo para luego trabajar con EL MISMO y ordenarlo alfabeeticamente comparando otro arreglo cargado con otro titulo bueno esa seria mi idea pero mi punto de problema esta
que al ejecutar el programa no ME APARECE EL TITULO ordenado
solo aparece codigo autor nro pag


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
PROGRAM EJER1;
USES CRT;
TYPE Dato=record
       Codigo:string [10];
       Titulo:string[50];
       Autor:string[30];
       Nropag:string[4];
       end;
 
       t= array [1..200] of Dato;
 Var
  arch:file of Dato;
  reg,menor,mayor:Dato;
  arch2: text;
  A,B: string;
  N1,N2,x,y,z,Cen,Desc: integer;
  Libros:t;
 
procedure BUSCAR;
var
c:integer;
begin
N1:= 0;
N2:= 0;
for c:=1 to 50 do
  begin
  if A[c]='#' then
    if N1= 0 then
    begin
      N1:= c;
    end
    else
    begin
      N2:= c; break;
    end;
  end;
end;
 
Procedure Cargar;
var
i:integer;
res1, res2: integer;
BEGIN
res1:= (N2-1) -N1;
res2:= 10 - res1;
 
 if res1 <10 then
 begin
  for i:= (N1+1) to (N2-1) do
  begin
   write (B, A[i]);
  end;
  for i:= 1 to res2+1 do
  begin
   write (B,' ');
   end;
  end
  else if res1 = 10 then
  begin
    for i:= (N1+1) to (N2-1) do
    begin
     write (B, A[i]);
    end;
    write (B,' ');
  end
  else
  begin
  for i:= (N1+1) to ((N1+1)+10) do
  begin
   write (B,A[i]);
  end;
  write (B, ' ');
 end;
 
  for i:= (N2+2) to length(A) do
  begin
   write (B, A[i]);
  end;
  write (B, '/');
  for i:= 1 to (N1-2) do
  begin
   write (B,A[i]);
 end;
 
 
end;
 
 Begin
  clrscr;
  x:= 0;
  Desc:=200;
  cen:= 1;
  Assign (arch,'C:\prueba.txt');
  rewrite (arch);
  writeln('ingrese los datos que se necesite');
  repeat
  if Desc = 0 then
  begin
  writeln ('Ud ya no puede agregar mas libros');
  Cen:=0;
  end
  else
  begin
  x:=x+1;
  Desc:= Desc-1;
  writeln ('---------------------------------------------------');
  writeln (' ');
  writeln ('Codigo: '); Readln (reg.Codigo);
  writeln ('Titulo: '); Readln (A);
  writeln ('Autor: '); Readln (reg.Autor);
  Writeln ('Numero de Pagina'); Readln (reg.Nropag);
  BUSCAR;
  Cargar;
  reg.Titulo:= B;
  Libros[x]:=reg;
  writeln (' ');
  writeln (Libros[x].Titulo);
 
  writeln('-----------------------------------------------------------');
  writeln(' ');
  writeln('Tiene ',DESC,' cantidad de libros para cargar');
  writeln('¿Desea cargar otro libro más?');
  writeln('1 = SI');
  writeln ('0 = NO');
  readln(Cen);
  end;
  until Cen = 0;
 
 
for y:=1 to x do
begin
for Z:=1 to (x-1) do
begin
if Libros[Z].Titulo < Libros[Z+1].Titulo then
begin
mayor:=Libros[Z+1]; menor:=Libros[Z];
end
else
begin
menor:=Libros[Z+1]; mayor:=Libros[Z];
end;
Libros[Z]:=menor; Libros[Z+1]:=mayor;
end;
end;
writeln('La lista ordenada de los libros es:');
Write('Titulos de los libros         CODIGO    AUTOR    NRO DE PAGINA');
 
for y:=1 to x do
writeln(Libros[y].Titulo);
write('         ');
write(Libros[y].Codigo);
write('    ');
write(Libros[y].Autor);
write('    ');
write (Libros[y].Nropag);
readkey;
 
 
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

Ejercicio pas no aparece titulo ordenado

Publicado por ramon (2158 intervenciones) el 31/08/2015 00:26:24
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
{A ver si esto ayuda }
 
PROGRAM EJER1;
 USES
  CRT;
    TYPE
       Dato = record
        Codigo : string[10];
        Titulo : string[50];
         Autor : string[30];
        Nropag : string[4];
       end;
 
    t = array[1..200] of Dato;
 Var
     arch : file of Dato;
     A, B : string;
     cont, x, y, z : integer;
     Libros : t;
 
   function contador : longint;
   begin
      Assign(arch,'prueba.txt');
   {$I-} reset(arch); {$I+}
       if ioresult <> 0 then
       begin
           contador := 1;
       end
    else
        begin
           contador := filesize(arch) - 1;
           close(arch);
        end;
   end;
 
   procedure guarda(hh : dato);
   begin
      Assign(arch,'prueba.txt');
   {$I-} reset(arch); {$I+}
       if ioresult <> 0 then
       begin
         rewrite(arch);
         seek(arch,0);
         write(arch,hh);
         close(arch);
       end
    else
       begin
         seek(arch,filesize(arch));
         write(arch,hh);
         close(arch);
       end;
   end;
 
 
   procedure entradadatos;
   begin
      clrscr;
      write('   Entre Codigo       : ');
      readln(Libros[cont].Codigo);
      write('   Entre Titulo       : ');
      readln(Libros[cont].Titulo);
      write('   Entre Autor        : ');
      readln(Libros[cont].Autor);
      write('   Entre Num. Paginas : ');
      readln(Libros[cont].Nropag);
      guarda(Libros[cont]);
      cont := cont + 1;
      if cont > 200 then
      cont := 200;
   end;
 
 
  procedure muestratodo;
  var
    hf, ver : longint;
  begin
     Assign(arch,'prueba.txt');
   {$I-} reset(arch); {$I+}
       if ioresult <> 0 then
       begin
         writeln('    Archivo No Encontrado pulse Una Tecla');
         readkey;
       end
    else
       begin
         hf := filesize(arch) - 1;
         if hf > 200 then
         hf := 200;
         for ver := 0 to hf do
         begin
            seek(arch,ver);
            read(arch,Libros[ver + 1]);
         end;
         close(arch);
         for ver := 0 to hf do
         writeln(Libros[ver + 1].Codigo,'   ',Libros[ver + 1].Titulo,'   ',
         Libros[ver + 1].Autor,'   ',Libros[ver + 1].Nropag);
         readkey;
       end;
  end;
 
  procedure ordenaportitulo;
  var
    orden : dato;
    c, n : integer;
    dt : longint;
    begin
       Assign(arch,'prueba.txt');
   {$I-} reset(arch); {$I+}
       if ioresult <> 0 then
       begin
         writeln('    Archivo No Encontrado pulse Una Tecla');
         readkey;
       end
    else
       begin
         dt := filesize(arch) - 1;
         if dt > 200 then
         dt := 200;
         for n := 0 to dt do
         begin
            seek(arch,n);
            read(arch,Libros[n + 1]);
         end;
         close(arch);
        for c := 1 to dt + 1 do
           for n := dt + 1 downto c + 1 do
           if Libros[c].titulo > Libros[n].titulo then
           begin
              orden := Libros[c];
              Libros[c] :=  Libros[n];
              Libros[n] := orden;
           end;
       clrscr;
       writeln;
       for n := 1 to dt + 1 do
       begin
       with libros[n] do
       writeln('   ',codigo,'    ',titulo,'    ',autor,'    ',nropag);
       end;
       readkey;
    end;
  end;
 
 
   procedure menu;
   var
     sal : boolean;
     tec : char;
    begin
      sal := false;
      repeat
         clrscr;
         writeln;
         writeln('   ***** Menu Jeneral *****');
         writeln;
         writeln(' 1 = Entrada Libros');
         writeln(' 2 = Mostrar Libros');
         writeln(' 3 = Ordenar En Array');
         writeln(' 4 = Salir');
         writeln;
         writeln('     Elija Opcion');
         repeat
            tec := readkey;
         until tec in['1','2','3','4'];
         clrscr;
      case tec of
  '1' : entradadatos;
  '2' : muestratodo;
  '3' : ordenaportitulo;
  '4' : sal := true;
     end;
      until sal = true;
    end;
 
 
   begin
      cont := contador;
      menu;
   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