Переделайте, пожалуйста, программу из Turbo pascal в ABC pascal - Pascal ABC

Узнай цену своей работы

Формулировка задачи:

Помогите, пожалуйста, перевести из PASCAL TURBO в PASCAL ABC

Решение задачи: «Переделайте, пожалуйста, программу из Turbo pascal в ABC pascal»

textual
Листинг программы
Program ProgInt;
Uses Crt, GraphABC;
Var Punkt : Byte;
     Knopka : Char;
     AppExit, Vved : Boolean;
     a, b, Square : Real;
     Gd, Gm : Integer;
 
{udalyaet probeli}
Function Probel(Str : String) : String;
Var i : Integer;
     Result : String;
Begin
  Result := '';
  For i := 1 To Length(Str) Do If Str[i] <> ' ' Then
  Result := Result + Str[i];
  Probel := Result;
End;
 
{proveryaet na nalichie levih simvolov}
Function Prov(Str : String) : Boolean;
Var i : Integer;
Begin
  Prov := True;
  For i := 1 To Length(Str) Do
  If ((Ord(Str[i]) < 45) Or (Ord(Str[i]) > 57)) Or (Ord(Str[i]) = 47) Then
  Begin
     Prov := False;
     Exit;
  End;
End;
 
{risuet menu}
Procedure Punkt_Menu;
Begin
  ClrScr;
  If Punkt = 1 Then TextColor(4)
  Else TextColor(DarkGray);
  GoToxy(30, 5);
  WriteLn('About');
  If Punkt = 2 Then TextColor(4)
  Else TextColor(DarkGray);
  GoToxy(30, 8);
  WriteLn('Vvod dannih');
  If Punkt = 3 Then TextColor(4)
  Else TextColor(DarkGray);
  GoToxy(30, 11);
  WriteLn('Vichislenie integrala');
  If Punkt = 4 Then TextColor(4)
  Else TextColor(DarkGray);
  GoToxy(30, 14);
  WriteLn('Grafik');
  If Punkt = 5 Then TextColor(4)
  Else TextColor(DarkGray);
  GoToxy(30, 17);
  WriteLn('Exit');
 
End;
 
{ob avtore}
Procedure Punkt_Avtor;
Begin
  ClrScr;
  TextColor(5);
  GoToxy(30, 20);
  WriteLn('Author:Naumov Andrey    ');
  GoToxy(33, 22);
  WriteLn('Gruppa: CT-140010   ');
  GoToxy(30, 24);
  WriteLn('Data: 29.05.2014');
  TextColor(9);
  GoToxy(1, 7);
  WriteLn('    Programma zaprasivaet predeli integrirovaniya, vichislyaet');
  WriteLn('    znachenie integrala i stroit grafik.');
  WriteLn;
  WriteLn('                    Integral:');
  WriteLn;
  WriteLn('                        b');
  WriteLn('                       --');
  WriteLn('                       | (2^X dX');
  WriteLn('                      --');
  WriteLn('                      a');
  WriteLn;
  TextColor(4);
  GoToxy(40, 40);
  Write('Press to Enter');
  ReadKey;
  Punkt_Menu;
End;
 
{vvod i proverka dannih}
Procedure Punkt_Vvod;
Var Str : String;
     i : Integer;
Begin
 
  ClrScr;
//  CursorOff;
  TextColor(DarkGray);
  GoToxy(20, 10);
  Write('Vvedite nijniu predel:');
  Str := '';
  While Str = '' Do
  Begin
     ReadLn(Str);
     Str := Probel(Str);
     If Prov(Str) Then Val(Str, a, i)
     Else
     Begin
        Str := '';
        Write('Pishite tol''ko chislo!');
     End;
  End;
  GoToxy(20, 16);
  Write('Vvedite verxniu predel:');
  Str := '';
  While Str = '' Do
  Begin
     ReadLn(Str);
     Str := Probel(Str);
     If Prov(Str) Then Val(Str, b, i)
     Else
     Begin
        Str := '';
        Write('Pishite tol''ko chislo!');
     End;
     If b <= a Then Str := '';
  End;
  WriteLn;
  Vved := True;
  GoToxy(28, 30);
  WriteLn('Dannie vvedeni verno!');
  TextColor(4);
  GoToxy(40, 40);
  Write('Ok, thanks!');
  ReadKey;
 
End;
 
{rasschet integrala}
Procedure Punkt_Raschet;
Begin
 
  ClrScr;
{  a:=0;
  b:=5;
  vved:=true;}
  Square := (exp(b*ln(2))-exp(a*ln(2)))/ln(2);
  TextColor(DarkGray);
  GoToxy(30, 10);
  WriteLn('Vichislenue integrala:');
  WriteLn;
  WriteLn('      b');
  Write('     --          x^(',b:5:2);Write(')-x^(',a:5:2);WriteLn(')');
  WriteLn('     | 2^X dX =-------------------------=',Square:10:3);
  WriteLn('    --                   ln(2)    ');
  WriteLn('    a');
  WriteLn;
 
  If Vved = False Then
  Begin
     WriteLn('Net dannih! Vvedite ''a'' i ''b''.');
     WriteLn;
     TextColor(4);
     GoToxy(40, 40);
     Write('press to enter');
     ReadKey;
     Exit;
  End;
 
 
  GoToxy(30, 20);
  TextColor(4);
  GoToxy(40, 40);
  Write('Ok');
  ReadKey;
 
End;
 
{risovanie integrala}
Procedure Punkt_Grafik;
Var x, y, TempX, TempY, Ymax, Ymin, _Ymax, _Ymin, Step, y0, Yold : Real;
     TempStr : String;
Begin
 
  ClrScr;
  If Vved = False Then
  Begin
     WriteLn('Net dannih! Vvedite ''a'' i ''b''.');
     WriteLn;
     TextColor(4);
     GoToxy(40, 40);
     WriteLn('Press to enter');
     ReadKey;
     Exit;
  End;
//  InitGraph(Gd, Gm, '');
  SetWindowSize(640,480);
  Ymax := -1000000;
  Ymin :=  1000000;
 
  x := 80;
  While x <= 560 Do
  Begin
     TempX := (x-80) / 480 * (b - a) + a;
     TempY := exp(TempX*ln(2));
     If Ymax < TempY Then Ymax := TempY;
     If Ymin > TempY Then Ymin := TempY;
     x := x + 1;
  End;
  Step := (Ymax - Ymin) / 10;
  _Ymax := Ymax;
  _Ymin := Ymin;
  If (Ymin > 0) And (Ymax > 0) Then
  Begin
     Ymin := -Step;
     Ymax := Ymax + Step;
  End
  Else If (Ymin < 0) And (Ymax < 0) Then
  Begin
     Ymax := Step;
     Ymin := Ymin - Step;
  End
  Else
  Begin
     Ymin := Ymin - Step;
     Ymax := Ymax + Step;
  End;
 
  SetPenColor(clGreen);
  x := Round(a);
  While x <= Round(b) Do
  Begin
     Line(Round((x-a)/(b-a)*480) + 80, 80,
            Round((x-a)/(b-a)*480) + 80, 400);
     x := x + 1;
  End;
  y := Round(Ymin);
  While y <= Round(Ymax) Do
  Begin
     Line(80, 480 - Round((y-Ymin)/(Ymax-Ymin)*320)-80,
            560, 480 - Round((y-Ymin)/(Ymax-Ymin)*320)-80);
     y := y + 1;
  End;
 
  SetPenColor(clRed);
  y0 := -Ymin / (Ymax - Ymin) * 320 + 80;
  Line(80, 480 - Round(y0), 560, 480 - Round(y0));
 
  TempX := a;
  TempY := exp(TempX*ln(2));
  y := (TempY - Ymin) / (Ymax-Ymin) * 320 + 80;
  Line(80, 480 - Round(y), 80, 480 - Round(y0));
  TempX := (560-80) / 480 * (b - a) + a;
  TempY := exp(TempX*ln(2));
  y := (TempY - Ymin) / (Ymax-Ymin) * 320 + 80;
  Line(560, 480 - Round(y), 560, 480 - Round(y0));
 
  Yold := y0;
  x := 80;
  While x <= 560 Do
  Begin
     TempX := (x-80) / 480 * (b - a) + a;
     TempY := exp(TempX*ln(2));
     y := (TempY - Ymin) / (Ymax-Ymin) * 320 + 80;
     Line(Round(x)-1, 480 - Round(Yold), Round(x), 480 - Round(y));
     Yold := y;
     x := x + 1;
  End;
  SetPenColor(clYellow);
  TextOut(10, 60, 'Integral = ');
  Square := (exp(b*ln(2))-exp(a*ln(2)))/ln(2);
  Str(Square:4:2, TempStr);
  TextOut(100, 60, Tempstr);
  SetPenColor(clBlack);
  x := -a / (b - a) * 480 + 80;
  Line(Round(x), 80, Round(x), 400);
  y := -Ymin / (Ymax - Ymin) * 320 + 80;
  Line(80, 480 - Round(y), 560, 480 - Round(y));
  SetPenColor(clYellow);
  Str(a:2:2, TempStr);
  TextOut(80, 420, 'a = ' + TempStr);
  Str(b:2:2, TempStr);
  TextOut(520, 420, 'b = ' + TempStr);
  Str(_Ymax:2:2, TempStr);
  TextOut(300, 60, 'Ymax = ' + TempStr);
  Str(_Ymin:2:2, TempStr);
  TextOut(300, 420, 'Ymin = ' + TempStr);
  TextOut(240, 5, 'y = 2^x');
 
  ReadKey;
//  CloseGraph;
 
End;
 
Begin
  AppExit := False;
  Vved := False;
  Punkt := 1;
//  Gd := Detect;
  Punkt_Menu;
 
  While AppExit = False Do
  Begin
     Knopka := ReadKey;
     Case Ord(Knopka) Of
        80 : Inc(Punkt);
        72 : Dec(Punkt);
        27 : AppExit := True;
        13 :
        Case Punkt Of
          1 : Punkt_Avtor;
          2 : Punkt_Vvod;
          3 : Punkt_Raschet;
          4 : Punkt_Grafik;
          5 : AppExit := True;
        End;
     End;
     If Punkt > 5 Then Punkt := 1;
     If Punkt < 1 Then Punkt := 5;
     Punkt_Menu;
  End;
 
End.

Объяснение кода листинга программы

The code you provided is written in Pascal ABC and it seems like a program for graphing an integral. It has several parts:

  1. Punkt_Avtor procedure, which sets the text color to dark gray, goes to the coordinates (30, 17) and writes the string Exit.
  2. Punkt_Vvod procedure, which clears the screen, sets the cursor off, sets the text color to dark gray, goes to the coordinates (20, 10), reads the string input from the user until it's not empty, and then sets the text color back to black.
  3. Punkt_Raschet procedure, which clears the screen, sets the text color to dark gray, goes to the coordinates (30, 10), reads the string input from the user until it's not empty, and then calculates and prints the integral using the given values of a and b.
  4. Punkt_Grafik procedure, which clears the screen, initializes the graph with the given window size, and then draws a graph using the given values of a and b.
  5. The GoToxy function is used to go to a specific coordinate on the screen.
  6. The ReadKey; statement reads the key pressed by the user.
  7. The AppExit := True; statement at the end of the program indicates that the application is exiting. Please note that the code you provided doesn't include the full program, so it might not work as expected.

Оцени полезность:

14   голосов , оценка 4.214 из 5
Похожие ответы