Home computickets Error execution: The object reference does not indicate an instance of the...

Error execution: The object reference does not indicate an instance of the object

Author

Date

Category

The program must calculate the values ​​of some functions (in this case f (x) = sin (x) * cos (x) and g (x) = (x – 1) ^ 3). But in 23 row (pointed out the comment) an error appears indicated in the subject. Also in line 24 and 32 (also specified) an error is displayed “The PASCALABC.NET cycle parameter should be described in the cycle header.” Thank you in advance!

Program LR2;
VAR A: REAL; // Left Cut Border
  B: Real; // Right Cut Border
  N: Integer; // Number of intervals
  I: integer; // Cycle variable
  H: Real; // Chase magnitude
  X: Array of Real; // Array Arguments Function
  F: Array of Real; // Array of values ​​F (X)
  G: Array of Real; // array of values ​​G (x)
Begin.
 WRITE ('Enter the value of the first point: a =');
 readln (a);
 Write ('Enter the value of the second point: B =');
 readln (b);
 IF A & GT; = B Then Writeln ('Segment Input Error, A must be strictly less than b!')
 Else Begin.
 Write ('Enter the number of interervalov: n =');
 readln (n);
 IF N & LT; = 0 THEN WRITELN ('Error input of the colliding intervals, n should be a trip to more than 0!')
 Else Begin.
 h: = (b - a) / n;
 x [1]: = 1; // Row 23.
 For i: = 1 to n do // Row 24
   Begin.
   F [i]: = sin (x [i]) * cos (x [i]);
   G [i]: = Power ((x [i] -1), 3);
   x [i + 1]: = a + h;
   end;
Writeln ('┌───────────────────────┐');
Writeln ('│ x │ f (x) │ G (x) │');
For i: = 1 to n do // Row 32
 Begin.
 Writeln ('├───────────────────────┤');
 Writeln ('│', x [i], '│', f [i], '│', g [i], '│');
 end;
 end;
 end;
end.

Answer 1

ok, declared dynamic, and not a static array

x: Array of Real

but

WHEN DYNAMIC A VARIABLE OF A DYNAMIC ARRAY TYPE, THE INITIAL LENGTH
Of the Array Is Zero. The Actual Length of the Array Must Be Set Wit
The Standard SetLength Function, Which Will Allocate The Necessary
MEMORY TO CONTAIN THE ARRAY ELEMENTS ON THE HEAP.

Who is the array size then tasks before writing something?

https://www.freepascal.org/docs-html/ref /refsu14.html


Answer 2

begin
 VAR A: = ReadReal ('Enter the value of the first point: a =');
 VAR B: = ReadReal ('Enter the value of the second point: B =');
 IF A & GT; = B THEN
  Print ('Cut error, A must be strictly less b!')
 ELSE.
 Begin.
  Write ();
  VAR N: = ReadInteger ('Enter the number of intervals: n =');
  IF N & LT; = 0 THEN
   Print ('Error entering the number of intervals, n should be hot more than 0!')
  ELSE.
  Begin.
   VAR X: = NEW REAL [N + 1];
   VAR F: = NEW REAL [N + 1];
   VAR G: = NEW REAL [N + 1];
   VAR H: = (B - a) / n;
   for var i: = 0 to n do
   Begin.
    x [i]: = a + i * h;
    F [i]: = sin (x [i]) * cos (x [i]);
    G [i]: = (x [i] - 1) ** 3
   end;
   PrintLN ('┌────────────────┬────────┐');
   PrintLN ('│ x │ F (x) │ G (x) │');
   for var i: = 0 to n do
   Begin.
    PrintLN ('├────────────────┼────────┤');
    Writeln ('│', x [i]: 7: 2, '│', f [i]: 8: 4, '│', g [i]: 8: 4, '│')
   end;
   PrintLN ('└────────────────┴────────┘');
  End.
 End.
end.
Enter the value of the first point: a = 2.8
Enter the value of the second point: B = 4.9
Enter the number of intervals: n = 5
┌───────────────────────┐.
│ x │ f (x) │ g (x) │
├───────────────────────┤.
│ 2.80│ -0.3156│ 5.8320│
├───────────────────────┤.
│ 3.22│ 0.0781│ 10.9410│
├───────────────────────┤.
│ 3.64│ 0.4199│ 18.3997│
├───────────────────────┤.
│ 4.06│ 0.4824│ 28.6526│
├───────────────────────┤.
│ 4.48│ 0.2241│ 42.1442│
├───────────────────────┤.
│ 4.90│ -0.1832│ 59.3190│
└───────────────────────┘.

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions