var l, n, m, o, inc, xinc, yinc : int var x, y, x2, y2, critical : real var a, b, c, rootOne, rootTwo, scaleRootOne, scaleRootTwo, aS, bS, cS : real var scale : real locate (1, 18) put "Quadratic Calculator and Plotter" locate (3, 1) put " Usage: Receives individual values for an equation in standard form:" put " axx+bx+c. Input as directed." put "" put " Bugs: What bugs? No, no. They're 'features'." put "" put " Features: Due to certain 'features' in Turing, this utility" put " cannot process complex numbers (imaginary roots)." put "" put " The scaling is quite dumb. Currently, the only scale" put " available is 25ppu (pixels per unit)." put "" put " Caveats: No error traps! Avoid entering erroneous data." put "" put "" put "" put "" put " Author: Omar Elkharadly. Questions? Comments? email: goatse@rogers.com" put "" put " Enjoy." put "" put "" put " push the 'any' key to continue." procedure getKey var next : string (1) getch (next) end getKey getKey cls loop locate (1, 1) put "a: " .. get a locate (1, 1) put " " locate (1, 1) put "b: " .. get b locate (1, 1) put " " locate (1, 1) put " " locate (1, 1) put "c: " .. get c locate (1, 1) put " " %Calculate roots using the quadratic formula %form: ax^2 + bx + c rootOne := (-1 * b + sqrt ((b * b) - 4 * a * c)) / (2 * a) rootTwo := (-1 * b - sqrt ((b * b) - 4 * a * c)) / (2 * a) %Begin graph: %Set the scale for reasonable viewing (units:pixel) scale := .04 %implement the scale! aS := a * scale bS := b cS := c / scale scaleRootOne := (-1 * bS + sqrt ((bS * bS) - 4 * aS * cS)) / (2 * aS) scaleRootTwo := (-1 * bS - sqrt ((bS * bS) - 4 * aS * cS)) / (2 * aS) %put scaleRootOne %put scaleRootTwo inc := -500 xinc := 0 yinc := 0 for count : 1 .. 1000 inc := -500 + count xinc := xinc + 25 if xinc <= 640 then drawline (xinc, 0, xinc, 480, 1) end if yinc := yinc + 25 if yinc <= 480 then drawline (0, yinc, 640, yinc, 1) end if x := inc y := aS * (x * x) + bS * x + cS x2 := x + 1 if x = scaleRootOne or x = scaleRootTwo then y2 := 0 else y2 := (y / (aS * x * x + bS * x + cS)) * aS * x2 * x2 + bS * x2 + cS end if %put x, ",",",y,",", x2, ",", y2 l := round (x) m := round (y) n := round (x2) o := round (y2) drawline (l + 300, m + 150, n + 300, o + 150, 2) end for %Draw axes, more room is reserved for the first quadrant. drawline (0, 149, 640, 149, 4) drawline (0, 150, 640, 150, 4) drawline (0, 151, 640, 151, 4) drawline (299, 0, 299, 480, 4) drawline (300, 0, 300, 480, 4) drawline (301, 0, 301, 480, 4) %text output locate (19, 60) put a, "xx + ", b, "x + ", c locate (20, 60) put "(x,y)= ", "(", rootOne, ",", 0, ")" locate (21, 60) put "(x,y)= ", "(", rootTwo, ",", 0, ")" %Calculate max/min via symmetry critical := a * ((rootOne + rootTwo) / 2) * ((rootOne + rootTwo) / 2) + b * ((rootOne + rootTwo) / 2) + c if a < 0 then locate (22, 60) put "Max: (", ((rootOne + rootTwo) / 2), ",", critical, ")" else locate (22, 60) put "Min: (", ((rootOne + rootTwo) / 2), ",", critical, ")" end if end loop