Advertisement
Guest User

Untitled

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