Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program ArrayFiller;
- uses SysUtils;
- var a:array of array of Integer;
- foutname:String;
- Fout:Text;
- hbd:Boolean; //has been destroyed
- i,j,m,n:Word;
- IORes:Integer;
- fillfunc:function(x:Integer):Integer;
- range:Integer;
- neg:Char;
- function NegFiller(range:Integer):Integer;
- var res:Integer;
- begin
- res:=random(range*2)-range;
- NegFiller:=res;
- end;
- function PosFiller(range:Integer):Integer;
- var res:Integer;
- begin
- res:=random(range);
- PosFiller:=res;
- end;
- //main
- begin
- WriteLn('I see you are in deep trouble');
- WriteLn('Tough times have come');
- WriteLn('Which file should I fill?');
- foutname:='';
- ReadLn(foutname);
- while foutname='' do
- begin
- WriteLn('Write some filename, fool!');
- ReadLn(foutname);
- end;
- Assign(Fout,foutname);
- hbd:=False;
- if FileExists(foutname) then hbd:=True;
- {$I-}
- ReWrite(Fout);
- {$I+}
- IORes:=IOResult;
- if IORes<>0 then
- begin
- WriteLn('Even I cannot solve your problem this way.');
- WriteLn('Input/Output error #',IORes);
- ReadLn();
- halt(IORes);
- end;
- if hbd then WriteLn('That file has just been sacrificed.');
- WriteLn;
- Write('How big your trouble is? (rows, columns): ');
- ReadLn(m,n);
- WriteLn(Fout,m,' ',n);
- SetLength(a,m+1,n+1);
- WriteLn('Now I shall call the Great Randomizer.');
- Randomize;
- Write('Would you want to limit it? (int.) :');
- ReadLn(range);
- Write('Negatives? (y/n)');
- ReadLn(neg);
- case neg of
- 'y': fillfunc:=@NegFiller;
- 'n': fillfunc:=@PosFiller;
- end;
- for i:=1 to m do
- begin
- for j:=1 to n do
- begin
- a[i,j]:=fillfunc(range);
- Write(Fout,a[i,j]:3,' ');
- end;
- WriteLn(Fout);
- end;
- Close(Fout);
- WriteLn('Your praises have been answered.');
- WriteLn('Check the ',foutname);
- ReadLn();
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement