DeberesPascal/ejercicio2.pas

99 lines
2.5 KiB
Plaintext
Raw Normal View History

2021-04-05 23:49:59 +02:00
uses sysutils;
type
CostoArrayRow = array[1..3] of double;
CantidadArrayRow = array[1..4] of Int64;
CostoArray = array[1..3] of CostoArrayRow;
CantidadArray = array[1..3] of CantidadArrayRow;
const
ESTACIONES : array[1..4] of string = ('Verano', 'Otoño', 'Invierno', 'Primavera');
ARTICULOS : array[1..3] of string = ('A', 'B', 'C');
COSTES : array[1..3] of string = ('Costo de materiales', 'Mano de obra', 'Otros gastos');
procedure printCantidad(cantidad: CantidadArray);
var
i, j: Int64;
begin
for i := 1 to Length(ESTACIONES) do
write(#9 + ESTACIONES[i]);
write(#10);
for i := 1 to Length(cantidad) do
begin
write(ARTICULOS[i]);
for j := 1 to Length(cantidad[i]) do
begin
write(#9 + IntToStr(cantidad[i][j]));
end;
write(#10);
end;
end;
procedure printCosto(costo: CostoArray);
var
i, j: Int64;
begin
for i := 1 to Length(ARTICULOS) do
write(#9 + ARTICULOS[i]);
write(#10);
for i := 1 to Length(costo) do
2021-04-06 00:38:19 +02:00
begin
2021-04-05 23:49:59 +02:00
write(COSTES[i]);
for j := 1 to Length(costo[i]) do
begin
write(#9 + FloatToStr(costo[i][j]));
end;
write(#10);
end;
end;
procedure printCostoPorEstacion(costo: CostoArray; cantidad: CantidadArray);
var
i, j, k: Int64;
precio_por_cantidad: double;
begin
for i := 1 to Length(ESTACIONES) do
write(#9 + ESTACIONES[i]);
write(#10);
for i := 1 to Length(COSTES) do
begin
write(COSTES[i]);
for j := 1 to Length(ESTACIONES) do
begin
precio_por_cantidad := 0;
for k := 1 to Length(ARTICULOS) do
precio_por_cantidad += cantidad[k][j] * costo[j][k];
write(#9 + FloatToStr(precio_por_cantidad));
end;
write(#10);
end;
end;
procedure printTables(costo: CostoArray; cantidad: CantidadArray);
begin
printCosto(costo);
printCantidad(cantidad);
printCostoPorEstacion(costo, cantidad);
end;
var
costo: CostoArray;
cantidad: CantidadArray;
i, j: Int64;
begin
Randomize;
for i := 1 to 3 do
for j := 1 to 3 do
{ No argument generates a double Random number. }
costo[i][j] := Random() * 10;
for i := 1 to 3 do
for j := 1 to 4 do
{ Argument generates a int64 Random number lesser than the argument. }
cantidad[i][j] := Random(2000) + 500;
printTables(costo, cantidad);
end.