Advertisement
Guest User

Untitled

a guest
May 3rd, 2013
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.54 KB | None | 0 0
  1. Uses SysUtils, Math;
  2. Const low  = 1;
  3.       high = 6;
  4.       inc  = 0.01;
  5.       prec = 3;
  6.  
  7. Var Out: TextFile;
  8.     Deg: Extended;
  9.     I  : QWord = 0;
  10.  
  11.   Function getDegreeName: Byte;
  12.   Var I: low..high;
  13.   Begin
  14.    For I := low To High Do
  15.     if (CompareValue(Deg, I) = EqualsValue) Then
  16.      Exit(I);
  17.    Exit(Floor(Deg));
  18.   End;
  19.  
  20.   Function toString(const F: Extended): String;
  21.   Begin
  22.    Result := FloatToStr(F);
  23.  
  24.    if (Length(Result) < prec) and (Pos('.', Result) = 0) Then
  25.     Result += '.0';
  26.  
  27.    While (Length(Result) <= prec) Do
  28.     Result += '0';
  29.   End;
  30.  
  31. Begin
  32.  DefaultFormatSettings.DecimalSeparator := '.';
  33.  
  34.  Writeln('-- start --');
  35.  
  36.  AssignFile(Out, 'output.txt');
  37.  
  38.  Try
  39.   ReWrite(Out);
  40.  
  41.   Writeln(Out, '#include <iostream>');
  42.   Writeln(Out);
  43.   Writeln(Out, 'using namespace std;');
  44.   Writeln(Out);
  45.   Writeln(Out, 'char e[][10] = {"jedynka", "dwojka", "trojka", "czworka", "piatka", "szostka"};');
  46.   Writeln(Out, '#define a(b,c) if(((b-d)<0?-b+d:b-d)<',toString(inc),')cout<<e[c-1]<<endl;');
  47.   Writeln(Out);
  48.   Writeln(Out, 'int main()');
  49.   Writeln(Out, '{');
  50.   Writeln(Out, ' double d;');
  51.   Writeln(Out, ' cin >> d;');
  52.   Writeln(Out);
  53.  
  54.   Deg := low;
  55.  
  56.   While (Deg <= high+inc) do
  57.   Begin
  58.    Write(Out, ' a(', toString(Deg), ',', getDegreeName, ') else');
  59.    if (I mod 10 = 0) Then
  60.     Writeln(Out);
  61.    Deg += inc;
  62.    I += 1;
  63.   End;
  64.  
  65.   Writeln(Out, ' cout << "poza zakresem" << endl;');
  66.  
  67.   Writeln(Out, '}');
  68.  Finally
  69.   Flush(Out);
  70.   CloseFile(Out);
  71.  End;
  72.  
  73.  Writeln('-- done --');
  74.  Readln;
  75. End.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement