Anda di halaman 1dari 11

Declaraciones

CONST
max_can= 4
max_part= 30
max_prov= 22
Type
Matriz= array [1..max_can, 0..max_part, 0..max_prov] of longint;
Var
h: matriz;
s: char;
Procedure cero_matriz (var hm: matriz)
Var
i,j,k: Integer;
Begin
For i:= 1 to max_can do
For j: 1 to max_part fo
For k:= 1 to max_prov do
Begin
hm [i,j,k]:= 0;
End;
Procedure Ingreso_ de _ datos (var hm: matriz)
Var
Can, Prov : Integer;
Part, Vot: Longint;
Begin
Clrscr;
Text color (yellow);
Writeln ('Ingreso de datos');
Writeln (' ');
Text color (white);
Writeln ('Ingresar candidato (1-4) o 0 para terminar');
Writeln (' ');
Readln (can);
While(can < > 0) do
Can <1 o (Can> max_can
Then Else
Begin Begin
Writeln; Repeat
Textcolor (red); Writeln;
Writeln('dato ingresado fuera de rango'); Writeln('Ingresar el partido');
Textcolor (white); Writeln;
Writeln; Readln(part);
Writeln('Ingresar candidato (1-4)'); (part<1) or (part>max_part)
Writeln (can); Then Else
End Begin
Writeln;
TextColor(red);

writeln('Dato
ingresado fuera
de rango');
TextColor(white);
Writeln;

Writeln('Ingresar
el partido
(1-30)');
Writeln;
Readln(part);
End;
Until (part>=1) and (part<=max_part);
Begin
Repeat
Writeln(' ');
Writeln('Ingresar la provincia');
Writeln(' ');
Readln(prov);
(prov<1) or (prov>max_prov)
Then Else
Begin
Writeln;
TextColor(red);

writeln('Dato
ingresado fuera
de rango');
TextColor(white);
Writeln;

Writeln('Ingresar
el provincia
(1-22)');
Writeln;
Readln(prov);
End;
until (prov>=1) and(prov<=max_prov);
Begin
Writeln(' ');
Writeln('Ingresar la cantidad de votos');
Writeln(' ');
Readln(vot);
Writeln ('Ingresar el candidato o
0 para terminar');
Writeln(' ');
Readln(Can);
End;
End;
End;
End;
Procedure mostrar_matriz(hm:matriz);
Var
i,j,k: Integer;
s: char;
begin
clrscr;
TextColor(yellow);
writeln('PARTE 1: MOSTRAR INFORMACION LEIDA');
TextColor(white);
writeln('Se mostraran los datos ingresados, para ver uno en particular');
writeln('presione 1, si no desea ver ninguno presione cualquier otro numero.');
writeln;
readln(cond);
while (cond=1) do
Begin
Clrscr
Writeln (' Ingrese el candidato, el partido y la provincia que desea ver,');
Writeln (' cuando se lo pida y se mostrara la cantidad de votos.');
Repeat
Writeln;
Writeln (' Ingresar el candidato');
Writeln (' ');
Readln (i) ;
(i<1) or (i>max_can)
Then Else
Begin
Writeln;
TextColor(red);
writeln('Dato
ingresado fuera
de rango');
TextColor(white);
Writeln;

Writeln('Ingresar
el candidato
(1-4)');
Writeln;
Readln(i);
End;
until (i>=1) and (i<=max_can);
Begin
repeat
writeln;
writeln('Ingresar el partido');
writeln;
readln(j);
(j<1) or (i>max_part)
Then Else
Begin
Writeln;
TextColor(red);

writeln('Dato
ingresado fuera
de rango');
TextColor(white);
Writeln;

Writeln('Ingresar
el partido
(1-30)');
Writeln;
Readln(i);
End;
until (j>=1) and (j<=max_part);
begin
repeat
writeln(' ');
writeln('Ingresar la provincia');
writeln(' ');
readln(k);
(k<1) or (k>max_prov)
Then Else
Begin
Writeln;
TextColor(red);

writeln('Dato
ingresado fuera
de rango');
TextColor(white);
Writeln;

Writeln('Ingresar
la provincia
(1-22)');
Writeln;
Readln(i);
End;
until (k>=1) and (k<=max_prov);
hm [i,j,k]<>0
Then Else
Begin Begin
Writeln (''); Writeln;
Writeln('la cantidad de votos es:' Writeln('No se han ingresado datos
hm[i,j,k] disintos de 0 para este caso');
End End;
Readln(part);
Writeln ('');
Writeln ('Para seguir apretar una tecla y un enter');
readln (s);
clrscr;
Writeln (' Para ver ms datos presione 1');
Writeln ('Si no se desea ver ninguno presione cualquier otro numero');
readln (cond);
end;
end;
End;
End;
Procedure candidato_2 (hm:matriz)
Var
i,j,k, cond, cont: Integer;
max:longint;
begin
max:= 0
clrscr;
TextColor(yellow);
writeln('PARTE 2: PARTIDO DE PROVINCIA QUE MAS VOTO AL CANDIDATO 2');
TextColor(white);
writeln('Si desea ver cual es el partido de provincia que');
writeln('más voto al candidato 2 presione 1, si no desea ver ninguno presione cualquier otro numero.');
readln(cond);
Begin
max:=0
clrscr;
writeln('Ingrese el numero 2 y presione enter.');
readln(i);
max:=0
for j:i to max_part do
for k:1 to max_prov do
begin
hm [i, 0, 0] > max
Then Else
Begin
max:= hm [i, j,k];
end;
end;
end;
writeln('');
writeln('');
cont:=0
for j:i to max_part do
for k:1 to max_prov do
begin
(hm [i, 0, 0] = max)
Then Else
cont:=cont+1;
end;

end;
(if cont:=1)
Then Else
begin (max <> 0 )
writeln('La mayor cantidad de votos Then Else
que recibio el candidato ',i); Begin
writeln ('es':max); writeln('La mayor
cantidad de votos
begin que recibio el
candidato', i);
For j:= 1 to max_part do
Writeln( 'es de',
For k:=1 to max_prov do max);
Writeln
begin ('lospartidos
con esa
(hm [i,j,k]= max) cantidad
de
Then Else votos son')

For j:=1 to max_part do

For k:=1 to max_prov do


writeln('El partido
con esa cantidad begin
de votos es el: ',j,'
de la provincia ',k);
end;
writeln('el ',j,'
End;
de la
End provincia ',k);

end;
End;
(max=0)
Then Else
Writeln('No se han ingresado datos para el

candidato 2 o este no ha recibido votos')


Writeln('Según los datos ingresados
end;
writeln('Presione una tecla y enter para continuar con el programa');
readln(s);
cond:=0;
end;
Procedure porcentaje(var hm:matriz);
Var
i,j,k,cond:integer;
tot:longint;
porc1,porc2,porc3,porc4:real;
begin
clrscr;
TextColor(yellow);
writeln('PARTE 3: PORCENTAJE DE CADA CANDIDATO EN EL RESULTADO FINAL');
TextColor(white);
writeln('Para ver el porcentaje de cada candidato en el resultado final');
writeln('presione 1 y enter.');
readln(cond);
while (cond=1) do
begin
cond:=0;
tot:=0;
begin
for j:=0 to max_part do
begin
for k:=0 to max_prov do
begin
hm[1,0,0]:=hm[1,0,0]+hm[1,j,k];
hm[2,0,0]:=hm[2,0,0]+hm[2,j,k];
hm[3,0,0]:=hm[3,0,0]+hm[3,j,k];
hm[4,0,0]:=hm[4,0,0]+hm[4,j,k];
end;
end;
end;
begin
clrscr;
tot:=tot+hm[1,0,0]+hm[2,0,0]+hm[3,0,0]+hm[4,0,0];
end;
Can <1 o (Can> max_can
Then Else
Begin begin
porc1:=hm[1,0,0]*100/tot; writeln('No se han ingresado datos');
porc2:=hm[2,0,0]*100/tot; end;
porc3:=hm[3,0,0]*100/tot;
porc4:=hm[4,0,0]*100/tot;
Writeln (' el porcentaje de cada
candidato, ')
Writeln ('según los datos ingresados,
en el resultado final:');
Writeln (' ');
Write (candidato 1:')
Writeln (porc1:2:2, '%');
write('candidato 2: ');
writeln(porc2:2:2, '%');
write('candidato 3: ');
writeln(porc3:2:2, '%');
write('candidato 4: ');
writeln(porc4:2:2, '%');
writeln(' ');
end
end;
writeln('Presione una tecla y enter para continuar');
readln(s);
end;
Function gan (hm:matriz): integer;
Var
i,j,k,cond:integer;
maxi:longint;
Begin
Maxi:= 0
For i:= 1 to d do
Begin
For j:= 0 to 30 do
For k:= 0 to 22
Begin
hm [i, 0, 0]:= hm[ i, 0,0 ] + hm [i ,j ,k]
end;
Begin
hm [i, 0, 0] > maxi
Then Else
Begin
maxi:= hm [i, 0,0];
gan:= i
end;
end;
end;
end;
begin (* programa principal*)
clrscr;
TextColor(yellow);
writeln('TP Nø19');
writeln('');
TextColor(white);
writeln('Para comenzar con el programa presionar una tecla y luego enter.');
readln(s);
cero_matriz (h);
writeln('');
ingreso_de_datos(h);
mostrar_matriz(h);
candidato_2(h);
porcentaje(h);
clrscr;
TextColor(yellow);
writeln('PARTE 4: CANDIDATO GANADOR');
TextColor(white);
writeln;
writeln('El candidato ganador, segun los datos ingresados,');
writeln(' ');
writeln(' es el ',gan(h),'.');
writeln('');
writeln;
writeln;
writeln('Fin del Programa');
writeln(' ');
writeln('Apretar una tecla y luego enter para salir.');
readln(s);
end.
procedure porcentaje(var hm:matriz);

Anda mungkin juga menyukai