Pascal/Turbo Pascal - Ordenar arrays de registros

 
Vista:

Ordenar arrays de registros

Publicado por Rijolop (1 intervención) el 08/12/2012 12:44:56
Buenos días, estoy preparando un examen de programación en el que me entra hasta registros, y me puse hacer un problema inventado por mi que consiste en guardar el nombre de equipos de futbol y que, los dos ultimos salgan aparte como si hubiesen descendido y los primeros como si estuvieran clasificados para la champions y eso... Pero me sale un error al comparar los arrays para que me los ordene y no tengo ni idea :s, llevo dos días pensando...
Aquí os dejo lo que llevo, en el que aún estoy probando si soy capaz de ordenarlos...
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
program ivanmarica (input,output);
type
tclasificacion= Record
nombreequipo: string (20);
puntos:integer;
golesfavor:integer;
golescontra:integer;
end;
tarray=array [1..6] of tclasificacion;
carray=array [1..2] of tclasificacion;
var
i:integer;
k:integer;
miau:tarray;
segunda:carray;
aux:integer;
x:integer;
begin
for i:=1 to 6 do begin
with miau [i] do begin
write ('nombre de equipo');
readln (nombreequipo);
write ('cuantos puntos ha hecho');
readln (puntos);
write ('goles a favoh');
readln (golesfavor);
write ('golèëéh en contrah cieeh');
readln (golescontra);
end;
end;
with miau[i] do begin
for i:= 1 to 100 do begin
	for x:=2 to 6 do begin
if miau [x-1]>miau[x] then begin
aux:=miau[x-1];
miau[x-1]:=miau[x];
miau[x]:=aux;
end;
end;
end;
for i:=1 to 6 do writeln (miau[i]);
end.


Gracias por vuestra atención :D
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

Ordenar arrays de registros

Publicado por ramon (2158 intervenciones) el 08/12/2012 17:07:28
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
{Espero esto ayude}
 
program ivanmarica;
  uses
     crt;
  type
     tclasificacion = Record
      nombreequipo : string[20];
            puntos : integer;
        golesfavor : integer;
       golescontra : integer;
     end;
 
 var
   equipos : array[1..8] of tclasificacion;
       aux : tclasificacion;
   i, t, r : integer;
 
 procedure entradadatos;
 begin
     for i := 1 to 8 do
     begin
        clrscr;
        writeln('  Entre Datos Del Equipo N§ : ',i);
        writeln;
        write('nombre de equipo        : ');
        readln(equipos[i].nombreequipo);
        write('cuantos puntos ha hecho : ');
        readln(equipos[i].puntos);
        write('goles a favoh           : ');
        readln(equipos[i].golesfavor);
        write('goles en contra         : ');
        readln(equipos[i].golescontra);
    end;
  end;
 
   procedure ordenaequipos;
   begin
       for t := 1 to 8 do
         for r := 8 downto t + 1 do
         if equipos[t].puntos < equipos[r].puntos then
         begin
             aux := equipos[t];
             equipos[t] := equipos[r];
             equipos[r] := aux;
         end;
   end;
 
   procedure mostraresultados;
   var
      d : integer;
   begin
       writeln('.... Pasan .....');
       writeln;
       for d := 1 to 6 do
       writeln(equipos[d].nombreequipo,'   Puntos : ',equipos[d].puntos);
       writeln;
       writeln(',,,, Descienden ,,,,,');
       writeln;
       for d := 7 to 8 do
       writeln(equipos[d].nombreequipo,'   Puntos : ',equipos[d].puntos);
       writeln;
       writeln('*** Pulse [Enter] ***');
       readln;
   end;
 
   procedure menu;
   var
     tec : char;
   begin
      repeat
       clrscr;
       writeln('**** Menu General ****');
       writeln;
       writeln('  1 = Entrada Datos');
       writeln('  2 = Mostrar Resultados');
       writeln('  3 = Salir');
       writeln;
       writeln('<<< Elija Opcion >>>');
       repeat
       tec := readkey;
       until tec in['1','2','3'];
    case tec of
  '1' : begin
        clrscr;
        entradadatos;
        ordenaequipos;
        end;
  '2' : begin clrscr; mostraresultados; end;
    end;
      until tec = '3';
   end;
 
 
   begin
      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
1
Comentar

Ordenar arrays de registros

Publicado por frank (1 intervención) el 08/04/2013 04:27:59
Gracias Ramon, desde Venezuela. Muy buen aporte
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

Ordenar arrays de registros

Publicado por jesus camacaro (2 intervenciones) el 22/12/2013 22:06:19
Hola buenas tardes le escribi para ver si alguien de los master me pueden ayudar para organizar un arreglo de manera que muestre por fecha una determinada accion me explico que si hoy pasaron 20 vehiculos se muestre lavfecha y la cantidad de vehiculos procesados
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

Ordenar arrays de registros

Publicado por ramon (2158 intervenciones) el 24/12/2013 15:41:59
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
{a qui tienes un pequeño ejemplo}
 
 program arrais;
  uses
    crt;
  type
     string12 = string[12];
     datos = record
         matricu : string[20];
         marca   : string[30];
         fecha   : string12;
       end;
 
   var
     dat : array[1..200] of datos;
     i, l : integer;
     fech : string12;
     sal : boolean;
     tec : char;
 
   procedure entradadatos(var nu : integer);
   begin
      clrscr;
      writeln('****** Entrada Datos Veiculo *******');
      writeln;
      write('   Entre Matricula         : ');
      readln(dat[nu].matricu);
      write('   Entre Marca             : ');
      readln(dat[nu].marca);
      write('   Entre Fecha dia/mes/a¤o : ');
      readln(dat[nu].fecha);
      nu := nu + 1;
   end;
 
   procedure muestafecha(fe : string12);
   var
      total : integer;
   begin
      total := 0;
      for i := 1 to l do
      begin
      if dat[i].fecha = fe then
      begin
      writeln('   ',dat[i].matricu,'   ',dat[i].fecha);
      total := total + 1;
      end;
     end;
      writeln;
      writeln('  Total Veiculos = ',total);
   end;
 
  begin
     l := 1;
     sal := false;
    repeat
     entradadatos(l);
     clrscr;
     writeln('  Desea Entrar Mas Datos [S/N] ');
     tec := upcase(readkey);
     if tec in['S','N'] then
     begin
        if tec = 'N' then
        sal := true;
     end;
    until (sal = true) or (l > 200);
    clrscr;
    write('<<<< Entre Fecha A Presentar >>>>');
    readln(fech);
    clrscr;
    muestafecha(fech);
    readkey;
  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