
(*   This program computes the non-complex roots of a quadratic equation
of the form a*x**2 + b*x + c.  It performs I/O to a binary file, but 
displays the input coefficients and outputs roots in a readable form 
on the console.  If the roots are imaginary, the program prints an 
appropriate message.  

   Variables:
     ZeroConst -   real constant used to check for imaginary roots
     InputCoef -   real input file which holds the input coefficients
     QuadResult -  real output file which holds the quadratic results
     AVar,BVar,CVar - real coefficients
     TempVar -     real value for temporary storage    *)

program Quadratic(Output);

const ZeroConst = 0.0;

var InputCoef,QuadResult : file of real;
    AVar,BVar,CVar : real;
    TempVar : TEMPREAL;

begin 
   
    reset(InputCoef,':F1:DATA3');   (* position input file at beginning *)
    rewrite(QuadResult,':F1:RESULT');   (* initialize output file *)

    while not EOF(InputCoef) do begin

        AVar := InputCoef^;   get(InputCoef);          (* get *)
        BVar := InputCoef^;   get(InputCoef);      (* coefficients *)
        CVar := InputCoef^;   get(InputCoef);    (* from input file *)
        write('Input coefficients are: ',AVar,BVar,CVar);  (* echo inputs *)
        writeln; write('Roots are: ');
        TempVar := (BVar * BVar) - (4 * AVar * CVar); (* compute discriminant *)
        if TempVar >= ZeroConst then begin
            TempVar := sqrt(TempVar);
            QuadResult^ := (-BVar + TempVar) / (2 * AVar);
            write(QuadResult^);  put(QuadResult); 
            QuadResult^ := -(BVar + TempVar) / (2 * AVar);
            writeln(QuadResult^);   put(QuadResult)
            end   (* of if *)
        else writeln(' imaginary'); (* print to default output file *)

    end;  (* of while *)

    writeln
end.(* Quadratic *)

