Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program pregunta1;
- type Str30 = String[30];
- Str180 = String[180];
- Str10 = String[10];
- TRegIngredientes = record
- codIng:Integer;
- cant:Real;
- end;
- TIngredientes = array [1..31] of TRegIngredientes;
- TReg = record
- codigo:Integer;
- nomPlato:Str30;
- ingredientes: TIngredientes;
- end;
- TArchBin = File of TReg;
- procedure PrepararArchivos(var archTxt: Text;var archBin: TArchBin);
- begin
- assign(archTxt,'platos.txt');
- assign(archBin,'platos.bin');
- end;
- function SacaPalabra(var cadenota: Str180):Str10;
- var p:Integer;
- begin
- while (cadenota<>'') and (cadenota[1]=' ') do delete(cadenota,1,1);
- p:=pos(' ',cadenota);
- if p=0 then begin
- sacaPalabra:=cadenota;
- cadenota:='';
- end else begin
- sacaPalabra:=copy(cadenota,1,p-1);
- delete(cadenota,1,p);
- end;
- end;
- function ObtenerIng(var cadenota: str180):TIngredientes;
- var Ingred: TIngredientes;
- i,j:Integer;
- cantidad,codigoIng: Str10;
- begin
- i:=0;
- repeat
- inc(i);
- codigoIng:=sacaPalabra(cadenota);
- val(codigoIng,Ingred[i].codIng);
- cantidad:=sacaPalabra(cadenota);
- val(cantidad,Ingred[i].cant);
- until cadenota='';
- ObtenerIng:=Ingred;
- procedure ObtenerNomPlato(var cadenota:Str180;var RegPlato:TReg);
- var i,num,err:Integer;
- begin
- i:=0;
- RegPlato.nomPlato:=' ';
- repeat
- inc(i);
- val(cadenota[i],num,err);
- if err<>0 then RegPlato.nomPlato[i]:=cadenota[i];
- until err=0;
- delete(cadenota,1,length(RegPlato.nomPlato));
- delete(RegPlato.nomPlato,length(RegPlato.nomPlato[i]),1);
- end;
- procedure BorrarEspacios(var cadenota: Str180);
- var i: Integer;
- begin
- i:=0;
- repeat
- inc(i);
- if (cadenota[i]=' ') and (cadenota[i+1]=' ') then delete(cadenota,i,1);
- until (i+1=length(cadenota));
- end;
- procedure ObtenerValoresDeCadenota(var cadenota: Str180;var RegPlato: TReg);
- var Ingredientes: TIngredientes;
- p,j,num,err:Integer;
- nomPlato: Str30;
- begin
- repeat
- if (cadenota[1]=' ') then delete(cadenota,1,1);
- until (cadenota[1]<>' ');
- BorrarEspacios(cadenota);
- ObtenerNomPlato(cadenota,RegPlato);
- RegPlato.ingredientes:=ObtenerIng(cadenota);
- end;
- procedure ColocarEnArchBin(var archTxt: Text;var archBin: TArchBin);
- var codigoPlat,i: Integer;
- nomPlato: String;
- RegPlato: TReg;
- Cadenota: Str180;
- begin
- reset(archTxt);
- rewrite(archBin);
- while not eof (archTxt) do begin
- RegPlato.codigo:=0;
- RegPlato.nomPlato:='';
- for i:=1 to 31 do begin Regplato.ingredientes[i].cant:=0;Regplato.ingredientes[i].codIng:=0;end;
- read(archTxt,RegPlato.codigo);
- cadenota:='';
- readln(archTxt,cadenota);
- ObtenerValoresDeCadenota(cadenota,RegPlato);
- write(archBin,RegPlato);
- end;
- close(archBin);close(archTxt);
- end;
- procedure Imprimirporsilasweas(var archBin: TArchBin);
- var i:Integer;
- RegPlato: TReg;
- begin
- reset(archBin);
- while not eof(archBin) do begin
- read(archBin,RegPlato);
- writeln(RegPlato.codigo);
- writeln(RegPlato.nomPlato);
- i:=0;
- repeat
- inc(i);
- if (RegPlato.ingredientes[i].codIng<>0) and (RegPlato.ingredientes[i].cant<>0) then begin
- write(RegPlato.ingredientes[i].codIng,' ',RegPlato.ingredientes[i].cant:2:3,' ');
- end;
- until (RegPlato.ingredientes[i].codIng=0) and (RegPlato.ingredientes[i].cant=0);
- writeln;
- end;
- close(archBin);
- end;
- var archTxt: Text;
- archBin: TArchBin;
- begin
- PrepararArchivos(archTxt,archBin);
- ColocarEnArchBin(archTxt,archBin);
- Imprimirporsilasweas(archBin);
- readln
- end.
Advertisement
Add Comment
Please, Sign In to add comment