Pascal/Turbo Pascal - Ayuda! vectores

 
Vista:
sin imagen de perfil

Ayuda! vectores

Publicado por Alejandro (15 intervenciones) el 24/06/2015 17:44:44
Hola que tal, me gustaria saber como hacer este ejercicio, la parte de archivo y registro me sale, pero me cuesta la parte donde hay que crear un vector.

el ejercicio me pide lo siguiente:

estos son los datos.

DNI ASISTENTE
(String [8])

Categoría de Asistente
(entero)

Apellido y Nombre
(String [30])

Importe de la inscripción
(entero)

Pagó S/N

1. Generar un archivo perdat.dat. Crear un solo campo concatenando Apellido y Nombre.
2. A partir de los datos contenidos en el archivo generado en el pto anterior:
a) Generar un vector que contenga la cantidad de personas que asistieron por categoría de asistente. Mostrar por pantalla el vector generado.
b) Informar por pantalla la cantidad de Autores (01) que no hayan abonado aun (“N”).
c) Calcular, mediante una función, el porcentaje que representa los asistentes alumnos (04) sobre el total de personas que asistieron.
d) Detectar la categoría que tuvo el mayor número de asistentes (se debe utilizar el vector generado en el pto a). Mostrar por pantalla la cantidad, el código y el nombre al cual pertenece.
e) Listar los datos de Docentes (03) que abonaron la inscripción (“S”).

Categoría de Asistente: 01-Autores, 02-Profesionales, 03-Docentes, 04-Alumnos
Pago s/n: “S”-SI,”N”-NO

me gustaria que me ayuden, porque estoy re perdido.

muchas gracias
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! vectores

Publicado por ramon (2158 intervenciones) el 25/06/2015 21:54:52
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
{No te entendí muy bien mira esto }
 
 program veztor;
  uses
     crt;
   const
      categoria : array[1..4] of string[2] = (
      '01','02','03','04');
      define : array[1..4] of string[13] = (
      'Autor','Profesionales','Docentes','Alumnos');
      max = 60;
   type
      datos = record
            dni     : string[8];
            asiste  : integer;
            apenomb : string[30];
            import  : integer;
            paga    : string[2];
           end;
 
  var
     f : file of datos;
     dato : datos;
     vector : array[1..max] of datos;
     cont : integer;
     categ : array[1..4] of integer;
 
 
  procedure guardar(d : datos);
  begin
     assign(f.'perdat.dat');
  {$I-} reset(f); {$I+}
      if ioresult <> 0 then
      begin
         rewrite(f);
         seek(f,0);
         write(f,d.apenomb);
         close(f);
      end
    else
       begin
         seek(f,filesize(f));
         write(f,d.apenomb);
         close(f);
       end;
       vector[cont].d;
       cont := cont + 1;
       if cont > max then
       cont := max;
  end;
 
   procedure asistencia;
   var
      dd : longint;
   begin
      fillchar(categ,sizeof(categ),0);
      assign(f.'perdat.dat');
  {$I-} reset(f); {$I+}
      if ioresult <> 0 then
      begin
         writeln('   Error De Archivo o No Existe Pulse Una Tecla');
         readkey;
      end
   else
       begin
          for dd := 0 to filesize(f) - 1 do
          begin
             seek(f,dd);
             read(f,dato);
             vector[cont] := dato;
         case vector[cont].asiste of
    1 : categ[1] := categ[1] + 1;
    2 : categ[2] := categ[2] + 1;
    3 : categ[3] := categ[3] + 1;
    4 : categ[4] := categ[4] + 1;
     end;
             cont := cont + 1;
             if cont > max then
             break;
          end;
          close(f);
      clrscr;
      writeln;
      writeln('   ',define[1],' = ',categ[1]);
      writeln('   ',define[2],' = ',categ[2]);
      writeln('   ',define[3],' = ',categ[3]);
      writeln('   ',define[4],' = ',categ[4]);
      writeln;
      writeln('   Pulse Una Tecla');
      readkey;
       end;
   end;
 
 
 
 
 
  begin
 
  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
sin imagen de perfil

Ayuda! vectores

Publicado por Alejandro (15 intervenciones) el 26/06/2015 03:41:51
Hola que tal, este seria el problema
Sin-titulo
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

Ayuda! vectores

Publicado por ramon (2158 intervenciones) el 26/06/2015 11:38:00
{Esto me aclara lo que quieres mejor te preparare ejemplo}
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

Ayuda! vectores

Publicado por ramon (2158 intervenciones) el 27/06/2015 00:41: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
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
{A qui tienes espero esto sirva}
 
 program congreso;
 uses
    crt;
  const
     categoria : array[1..4] of string[14] = (
     'Autores','Profesionales','Docentes','Alumnos');
     archivo = 'teyet.dat';
 
  type
    asistentes = record
          dni : string[8];
          categ : integer;
          apenom : string[30];
          import : integer;
          pago : char;
        end;
     string8 = string[8];
 
   var
     asist : asistentes;
     f : file of asistentes;
     vector : array[1..4] of integer;
     todo : array[1..200] of asistentes;
     entradas : integer;
     uu, may : integer;
     activo : boolean;
 
 
  procedure guardar(d : asistentes);
  begin
     assign(f,archivo);
  {$I-} reset(f); {$I+}
      if ioresult <> 0 then
      begin
         rewrite(f);
         seek(f,0);
         write(f,d);
         close(f);
      end
    else
       begin
         seek(f,filesize(f));
         write(f,d);
         close(f);
       end;
  end;
 
  procedure cargar;
  var
     tt : longint;
     ss : integer;
  begin
      assign(f,archivo);
  {$I-} reset(f); {$I+}
      if ioresult <> 0 then
      begin
         writeln('   Error de Archivo o no Existe Pulse Una Tecla');
          readkey;
      end
   else
      begin
        if filesize(f) - 1  <= 200 then
        begin
           ss := filesize(f) - 1;
        end
         else
           begin
           ss := 200;
           end;
        for tt := 0 to ss do
        begin
        seek(f,tt);
        read(f,todo[tt + 1]);
       end;
        close(f);
        entradas := ss;
     end;
    end;
 
    procedure entradadatos;
    var
      ted : char;
    begin
       clrscr;
       writeln('   **** Entrada De Datos ****');
       writeln;
       write('   DNI                : ');readln(asist.dni);
       writeln('   1=Autores 2=Profesionales 3=Docentes 4=Alumnos');
       write('   Categoria          : ');readln(asist.categ);
       write('   Apellido y Nombre  : ');readln(asist.apenom);
       write('   Importe Num Entero : ');readln(asist.import);
       write('   Pagado S/N         : ');readln(asist.pago);
       repeat
          ted := upcase(readkey);
       until ted in['S','N'];
       if ted = 'S' then
       guardar(asist);
    end;
 
    procedure asistencias;
    var
      cont : integer;
    begin
        cargar;
        fillchar(vector,sizeof(vector),0);
        for cont := 1 to entradas do
        case todo[cont].categ of
    1 : vector[1] := vector[1] + 1;
    2 : vector[2] := vector[2] + 1;
    3 : vector[3] := vector[3] + 1;
    4 : vector[4] := vector[4] + 1;
      end;
      clrscr;
      writeln('  ******* Personas Por Categoria *********');
      writeln;
      writeln('   ',categoria[1],' = ',vector[1]);
      writeln('   ',categoria[2],' = ',vector[2]);
      writeln('   ',categoria[3],' = ',vector[3]);
      writeln('   ',categoria[4],' = ',vector[4]);
      writeln;
      writeln('  Pulse Una Tecla ');
      readkey;
      uu := 0;
      for cont := 1 to 4 do
      if vector[cont] > uu then
      begin
         uu := vector[cont];
         may := cont;
      end;
        activo := true;
    end;
 
  procedure autores_que_no_an_abonado;
  var
    aut, cont : integer;
  begin
     cargar;
     aut := 0;
     for cont := 1 to entradas do
     if (todo[cont].pago = 'N') and (todo[cont].categ = 1) then
     aut := aut + 1;
     clrscr;
     writeln('   Cantidad de Autores sin Abonar Es : ',aut);
     writeln;
     writeln('  Pulse Una Tecla ');
     readkey;
  end;
 
  function procentaje_alumnos : real;
  var
    cont, ss : integer;
    begin
       procentaje_alumnos :=  0.0;
       cargar;
       ss := 0;
       for cont := 1 to entradas do
       if todo[cont].categ = 4 then
       ss := ss + 1;
       procentaje_alumnos := entradas / ss;
    end;
 
 
  procedure docentes_que_abonaron;
  var
    cont, jj : integer;
  begin
      cargar;
      jj := 0;
      for cont := 1 to entradas do
      if (todo[cont].pago = 'S') and (todo[cont].categ = 3) then
      jj := jj + 1;
      clrscr;
      writeln('   Cantidad de Docentes Que Abonaron Es : ',jj);
      writeln;
      writeln('  Pulse Una Tecla ');
      readkey;
  end;
 
  procedure menu;
  var
    ts : char;
    sal : boolean;
    begin
       sal := false;
      repeat
         clrscr;
         writeln('    ////// Menu Jeneral \\\\\\');
         writeln;
         writeln('  1 Entrada Datos');
         writeln('  2 Asistencias');
         writeln('  3 Autores que No An Abonado');
         writeln('  4 Categoria Que Tuvo El Mayor Numero De Asistentes');
         writeln('  5 Asistentes De Alumnos Sobre El Total De Personas');
         writeln('  6 Docentes Que Abonaron');
         writeln('  7 Salir');
         writeln;
         writeln('   Elija Opcion');
         repeat
             ts := readkey;
         until ts in['1','2','3','4','5','6','7'];
         clrscr;
      case ts of
   '1' : entradadatos;
   '2' : asistencias;
   '3' : autores_que_no_an_abonado;
   '4' : begin
           if activo = true then
           begin
              clrscr;
              writeln('   Mayor Num Asistentes ');
              writeln;
              writeln('   La Categoria  Es : ',categoria[may]);
              writeln('   Asistentes  Es   : ',uu);
              writeln;
              writeln('  Pulse Una Tecla ');
              readkey;
           end;
         end;
   '5' : begin
            writeln('    Asistentes De Alumnos Sobre El Total');
            writeln;
            writeln('    Alumnos Son : ',procentaje_alumnos:0:2);
            writeln;
            writeln('  Pulse Una Tecla ');
            readkey;
         end;
   '6' : docentes_que_abonaron;
   '7' : sal := true;
     end;
      until sal = true;
   end;
 
  begin
     clrscr;
     activo := false;
     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
sin imagen de perfil

Ayuda! vectores

Publicado por Alejandro (15 intervenciones) el 27/06/2015 02:53:34
Hola, muchisisisimas gracias por la ayuda, mi pregunta es la siguiente, donde se crea la carpeta? en que ruta, o donde le agrego, porque tengo que crear un archivo .dat.

si no me equivoco se genera con assign (vf_arch, 'D:\teyet.dat'); pero en que linea le agrego?

y un procedure para que me muestre todos los datos cargados, si quiere la parte que hice yo.
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
sin imagen de perfil

Ayuda! vectores

Publicado por Alejandro (15 intervenciones) el 27/06/2015 03:17:58
algo asi, y que genere el archivo en el disco duro, y cuando yo cierre y vuelva abrir, este todavia los datos

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
program teyet;
uses crt;
type
 
	tr_teyet = record
 
		dni: string[8];
		codcad: integer;
		apellido: string[30];
		nombre: string[30];
		pago: char;
		importe:real;
 
	end;
 
	tf_teyet = file of tr_teyet;
var
	vf_arch: tf_teyet;
	vr_reg: tr_teyet;
 
procedure crearArchivo ();
begin
	assign (vf_arch, 'D:\teyet2015.dat');
		rewrite (vf_arch);
	writeln ('Archivo creado.!');
	close (vf_arch);
end;
procedure abrirArchivo ();
begin
	assign (vf_arch, 'D:\teyet2015.dat');
		reset (vf_arch);
end;
procedure cargarDatos ();
var
	ve_rpta: char;
 
begin
 
	abrirArchivo ();
 
	ve_rpta := 's';
 
	while ((ve_rpta <> 'n') and (ve_rpta <> 'N')) do
		begin
			seek (vf_arch, filesize(vf_arch));
			with vr_reg do
				begin
					writeln ('**************** Cargar datos **************** ');
					writeln ();
					write ('Nombre: ');
						readln (nombre);
					writeln ();
					write ('Apellido: ');
						readln (apellido);
					writeln ();
					write ('DNI: ');
						readln (dni);
					writeln ();
					write ('Codigo de categoria: ');
						readln (codcad);
					writeln ();
					write ('Importe de inscripcion: ');
						readln (importe);
					writeln ();
					write ('Pago S/N: ');
						readln (pago);
					writeln ();
				end;
 
			write (vf_arch, vr_reg);
			writeln ();
			write ('Ingresar otro registro?: ');
				readln (ve_rpta);
		end;
	close (vf_arch);
end;
procedure mostrarDatos ();
begin
 
	abrirArchivo ();
 
	while not eof (vf_arch) do
		begin
			read (vf_arch, vr_reg);
				with vr_reg do
					begin
						writeln ();
						writeln ('Nombre: ',nombre);
						writeln ('Apellido: ',apellido);
						writeln ('DNI: ',dni);
						writeln ('Categoria: ',codcad);
						writeln ('Importe: $' ,importe:0:2);
						writeln ('Pago: ',pago);
					end;
		end;
end;
procedure menu ();
var
	ve_opcion: integer;
begin
 
	writeln ('Elegir opcion: ');
	writeln ();
	writeln ('1-Crear archivo');
	writeln ('2-Cargar datos');
	writeln ('3-Mostrar datos');
	writeln ();
	write ('Opcion: ');
		readln (ve_opcion);
	case ve_opcion of
 
		1:
			begin
				clrscr ();
				crearArchivo ();
				writeln ();
				menu ();
			end;
		2:
			begin
				clrscr ();
				cargarDatos ();
				writeln ();
				menu ();
			end;
		3:
			begin
				clrscr ();
				mostrarDatos ();
				writeln ();
				menu ();
			end;
 
	end;
end;
 
BEGIN
 
	menu ();
	crearArchivo ();
	abrirArchivo();
	cargarDatos ();
	mostrarDatos
 
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

Ayuda! vectores

Publicado por ramon (2158 intervenciones) el 27/06/2015 11:38:59
Como podrás comprobar el archivo se crea a qui procedure guardar(d : asistentes);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
begin
     assign(f,archivo);
  {$I-} reset(f); {$I+}
      if ioresult <> 0 then
      begin
         rewrite(f);
         seek(f,0);
         write(f,d);
         close(f);
      end
    else
       begin
         seek(f,filesize(f));
         write(f,d);
         close(f);
       end;
  end;

cuando entras los datos te pide si deseas guardar el archivo estará donde ejecutes el programa.
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
sin imagen de perfil

Ayuda! vectores

Publicado por Alejandro (15 intervenciones) el 28/06/2015 01:26:00
Ah si, ahí esta, mil disculpa. Ahora como hago para mostrar todos los datos cargados? sin importar la categoría
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

Ayuda! vectores

Publicado por ramon (2158 intervenciones) el 28/06/2015 11:55: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
{A qui tienes la carga también }
 
procedure cargar;
  var
     tt : longint;
     ss : integer;
  begin
      assign(f,archivo);
  {$I-} reset(f); {$I+}
      if ioresult <> 0 then
      begin
         writeln('   Error de Archivo o no Existe Pulse Una Tecla');
          readkey;
      end
   else
      begin
        if filesize(f) - 1  <= 200 then
        begin
           ss := filesize(f) - 1;
        end
         else
           begin
           ss := 200;
           end;
        for tt := 0 to ss do
        begin
        seek(f,tt);
        read(f,todo[tt + 1]);
       end;
        close(f);
        entradas := ss;
     end;
    end;
 
{Todos los datos asta 200 registros los puedes tomar y presentar de ' todo[x] ' }
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
sin imagen de perfil

Ayuda! vectores

Publicado por Alejandro (15 intervenciones) el 28/06/2015 17:10:08
Ok muchas gracias..

Le hago unas ultimas preguntas..

1- en que parte se crea la matriz?
2- que significa las variables uu, may y activo?
3- puedo hacer que la persona ponga el limite hasta donde quiere que sea el vector?
por ejemplo si la persona quiere que sean 300, que una variable lo lea y que el vector sea de ese tamaño
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

Ayuda! vectores

Publicado por ramon (2158 intervenciones) el 29/06/2015 01:06:53
A qui creamos el archivo 'entradadatos;' que tomaremos para la matriz a qui 'cargar;' la generamos;
Las variables uu, may y activo son:
uu = para comparar valor en asistencias.
may = como posición en el array de mayor asistencias.
activo = como información de que los datos de asistencias an sido tomados para su presentación.
Lo 3 no puesto que pascal no lo permite una vez iniciado pero puedes poner tu 500 y dejar que ellos
elijan de 1 a 500.
Sino tendrías que usar punteros.
Ten cuidado puesto que pascal te dará error de desbordamiento de pila si los datos del array o matriz
ocupan mas de 64000 bites.
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