Added ejercicio2.

This commit is contained in:
sergiotarxz 2021-04-05 23:49:59 +02:00
parent 0ab89b9da9
commit b15b71d36c
Signed by: sergiotarxz
GPG Key ID: E5903508B6510AC2

98
ejercicio2.pas Normal file
View File

@ -0,0 +1,98 @@
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
begin;
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.