Anatoly Chernyshev
2023-03-30 21:49:43 UTC
Just had an exercise with ChatGPT for Ada.
Here is what my request was: "Produce Ada code for solving a quadratic equation."
And here's the output from ChatGPT (quite flawless forgiving the absence of a math lib in the header):
----------------------------
with Ada.Text_IO; use Ada.Text_IO;
procedure Quadratic_Equation is
A, B, C, D : Float;
X1, X2 : Float;
begin
-- read coefficients A, B, and C from the user
Put("Enter coefficient A: ");
Get(A);
Put("Enter coefficient B: ");
Get(B);
Put("Enter coefficient C: ");
Get(C);
-- calculate the discriminant
D := B*B - 4.0*A*C;
-- check if the discriminant is negative
if D < 0.0 then
Put_Line("No real roots exist.");
else
-- calculate the roots
X1 := (-B + Sqrt(D)) / (2.0*A);
X2 := (-B - Sqrt(D)) / (2.0*A);
-- output the roots
Put_Line("Root 1 = " & Float'Image(X1));
Put_Line("Root 2 = " & Float'Image(X2));
end if;
end Quadratic_Equation;
and an extra remark:
Note that this implementation assumes that the discriminant (B^2 - 4AC) is positive or zero. If the discriminant is negative, then no real roots exist.
-----------------------------------------------
Before crying wolf, my impression is that ChatGPT might be useful for drafting simple pieces of code (say, homeworks). Very soon though one will arrive at a situation when the amount of efforts to explain the task to ChatGPT will be the same as to write the code yourself (I shall call it a limiting Kolmogorov complexity).
What do you think?
Here is what my request was: "Produce Ada code for solving a quadratic equation."
And here's the output from ChatGPT (quite flawless forgiving the absence of a math lib in the header):
----------------------------
with Ada.Text_IO; use Ada.Text_IO;
procedure Quadratic_Equation is
A, B, C, D : Float;
X1, X2 : Float;
begin
-- read coefficients A, B, and C from the user
Put("Enter coefficient A: ");
Get(A);
Put("Enter coefficient B: ");
Get(B);
Put("Enter coefficient C: ");
Get(C);
-- calculate the discriminant
D := B*B - 4.0*A*C;
-- check if the discriminant is negative
if D < 0.0 then
Put_Line("No real roots exist.");
else
-- calculate the roots
X1 := (-B + Sqrt(D)) / (2.0*A);
X2 := (-B - Sqrt(D)) / (2.0*A);
-- output the roots
Put_Line("Root 1 = " & Float'Image(X1));
Put_Line("Root 2 = " & Float'Image(X2));
end if;
end Quadratic_Equation;
and an extra remark:
Note that this implementation assumes that the discriminant (B^2 - 4AC) is positive or zero. If the discriminant is negative, then no real roots exist.
-----------------------------------------------
Before crying wolf, my impression is that ChatGPT might be useful for drafting simple pieces of code (say, homeworks). Very soon though one will arrive at a situation when the amount of efforts to explain the task to ChatGPT will be the same as to write the code yourself (I shall call it a limiting Kolmogorov complexity).
What do you think?