karlangadas

Ya casi acaba

Nov 30th, 2015
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 3.60 KB | None | 0 0
  1. program pregunta1;
  2. type Str30 = String[30];
  3.      Str180 = String[180];
  4.      Str10 = String[10];
  5.      TRegIngredientes = record
  6.        codIng:Integer;
  7.        cant:Real;
  8.      end;
  9.      TIngredientes = array [1..31] of TRegIngredientes;
  10.      TReg = record
  11.        codigo:Integer;
  12.        nomPlato:Str30;
  13.        ingredientes: TIngredientes;
  14.      end;
  15.      TArchBin =  File of TReg;
  16.  
  17. procedure PrepararArchivos(var archTxt: Text;var archBin: TArchBin);
  18. begin
  19.   assign(archTxt,'platos.txt');
  20.   assign(archBin,'platos.bin');
  21. end;
  22.  
  23. function SacaPalabra(var cadenota: Str180):Str10;
  24. var p:Integer;
  25. begin
  26.   while (cadenota<>'') and (cadenota[1]=' ') do delete(cadenota,1,1);
  27.   p:=pos(' ',cadenota);
  28.   if p=0 then begin
  29.     sacaPalabra:=cadenota;
  30.     cadenota:='';
  31.   end else begin
  32.     sacaPalabra:=copy(cadenota,1,p-1);
  33.     delete(cadenota,1,p);
  34.   end;
  35.  
  36. end;
  37. function ObtenerIng(var cadenota: str180):TIngredientes;
  38. var Ingred: TIngredientes;
  39.      i,j:Integer;
  40.      cantidad,codigoIng: Str10;
  41. begin
  42.   i:=0;
  43.   repeat
  44.    inc(i);
  45.    codigoIng:=sacaPalabra(cadenota);
  46.    val(codigoIng,Ingred[i].codIng);
  47.    cantidad:=sacaPalabra(cadenota);
  48.    val(cantidad,Ingred[i].cant);
  49.   until cadenota='';
  50.   ObtenerIng:=Ingred;
  51.  
  52. procedure ObtenerNomPlato(var cadenota:Str180;var RegPlato:TReg);
  53. var i,num,err:Integer;
  54. begin
  55.   i:=0;
  56.   RegPlato.nomPlato:=' ';
  57.   repeat
  58.     inc(i);
  59.     val(cadenota[i],num,err);
  60.     if err<>0 then RegPlato.nomPlato[i]:=cadenota[i];
  61.   until err=0;
  62.   delete(cadenota,1,length(RegPlato.nomPlato));
  63.   delete(RegPlato.nomPlato,length(RegPlato.nomPlato[i]),1);
  64.  
  65. end;
  66.  
  67. procedure BorrarEspacios(var cadenota: Str180);
  68. var i: Integer;
  69. begin
  70.   i:=0;
  71.   repeat
  72.     inc(i);
  73.     if (cadenota[i]=' ') and (cadenota[i+1]=' ') then delete(cadenota,i,1);
  74.   until (i+1=length(cadenota));
  75. end;
  76.  
  77. procedure ObtenerValoresDeCadenota(var cadenota: Str180;var RegPlato: TReg);
  78. var Ingredientes: TIngredientes;
  79.     p,j,num,err:Integer;
  80.     nomPlato: Str30;
  81.  
  82. begin
  83.   repeat
  84.     if (cadenota[1]=' ') then delete(cadenota,1,1);
  85.   until (cadenota[1]<>' ');
  86.  
  87.   BorrarEspacios(cadenota);
  88.   ObtenerNomPlato(cadenota,RegPlato);
  89.   RegPlato.ingredientes:=ObtenerIng(cadenota);
  90.  
  91.  
  92. end;
  93.  
  94. procedure ColocarEnArchBin(var archTxt: Text;var archBin: TArchBin);
  95. var codigoPlat,i: Integer;
  96.     nomPlato: String;
  97.     RegPlato: TReg;
  98.     Cadenota: Str180;
  99.  
  100. begin
  101.   reset(archTxt);
  102.   rewrite(archBin);
  103.   while not eof (archTxt) do begin
  104.     RegPlato.codigo:=0;
  105.     RegPlato.nomPlato:='';
  106.     for i:=1 to 31 do begin Regplato.ingredientes[i].cant:=0;Regplato.ingredientes[i].codIng:=0;end;
  107.     read(archTxt,RegPlato.codigo);
  108.     cadenota:='';
  109.     readln(archTxt,cadenota);
  110.     ObtenerValoresDeCadenota(cadenota,RegPlato);
  111.     write(archBin,RegPlato);
  112.   end;
  113.   close(archBin);close(archTxt);
  114. end;
  115.  
  116. procedure Imprimirporsilasweas(var archBin: TArchBin);
  117. var i:Integer;
  118.     RegPlato: TReg;
  119. begin
  120.   reset(archBin);
  121.   while not eof(archBin) do begin
  122.     read(archBin,RegPlato);
  123.     writeln(RegPlato.codigo);
  124.     writeln(RegPlato.nomPlato);
  125.     i:=0;
  126.     repeat
  127.       inc(i);
  128.       if (RegPlato.ingredientes[i].codIng<>0) and (RegPlato.ingredientes[i].cant<>0) then begin
  129.         write(RegPlato.ingredientes[i].codIng,' ',RegPlato.ingredientes[i].cant:2:3,' ');
  130.       end;
  131.     until (RegPlato.ingredientes[i].codIng=0) and (RegPlato.ingredientes[i].cant=0);
  132.     writeln;
  133.   end;
  134.   close(archBin);
  135. end;
  136.  
  137. var  archTxt: Text;
  138.      archBin: TArchBin;
  139. begin
  140.   PrepararArchivos(archTxt,archBin);
  141.   ColocarEnArchBin(archTxt,archBin);
  142.   Imprimirporsilasweas(archBin);
  143.   readln
  144. end.
Advertisement
Add Comment
Please, Sign In to add comment