Expected results for test: P3-57.pl460 P3-57.pl460 : ;; square_root will calculate the square root of a numeric value to 5 decimal ;; places of precision. The formal argument should be a non-negative (0 or ;; positive) numeric value. (define (square n) (* n n) ) (define (abs v) (if (< v 0) (- 0 v) v ) ) (define (newton v l u) (let ((m (/ (+ l u) 2))) (if (< (abs (- (square m) v)) 0.00000000001) m (if (< (square m) v) (newton v m u) (newton v l m) ) ) ) ) (define (square_root v) (cond ((not (number? v)) "Argument must be numeric") ((< v 0) "Argument must be >= 0") ((= 0 v) 0) ((< v 1) (/ (round (* 100000 (/ 1 (newton (/ 1 v) 0 (/ 1 v))))) 100000)) ((= 1 v) 1) (else (/ (round (* 100000 (newton v 0 v))) 100000)) ) ) (define (main) (display (square_root 225.0)) (newline) (display (square_root 2.25)) (newline) (display (square_root 0.0225)) (newline) (display (square_root -1)) (newline) ) (main) Input file: P3-57.pl460 0 errors found in input file P3-57.cpp : // Autogenerated PL460 to C++ Code // File: P3-57.cpp #include #include "Object.h" using namespace std; Object square (Object n) { Object __RetVal; __RetVal = (n * n); return __RetVal; } Object abs (Object v) { Object __RetVal; if ((v < Object("0"))) { __RetVal = (Object("0") - v); } else { __RetVal = v; } return __RetVal; } Object newton (Object v, Object l, Object u) { Object __RetVal; { Object m = ((l + u) / Object("2")); if ((abs((square(m) - v)) < Object("0.00000000001"))) { __RetVal = m; } else { if ((square(m) < v)) { __RetVal = newton(v, m, u); } else { __RetVal = newton(v, l, m); } } } return __RetVal; } Object square_root (Object v) { Object __RetVal; if (! (numberp (v))) { __RetVal = Object("Argument must be numeric"); } else if ((v < Object("0"))) { __RetVal = Object("Argument must be >= 0"); } else if ((Object("0") == v)) { __RetVal = Object("0"); } else if ((v < Object("1"))) { __RetVal = (round ((Object("100000") * (Object("1") / newton((Object("1") / v), Object("0"), (Object("1") / v))))) / Object("100000")); } else if ((Object("1") == v)) { __RetVal = Object("1"); } else { __RetVal = (round ((Object("100000") * newton(v, Object("0"), v))) / Object("100000")); } return __RetVal; } int main () { Object __RetVal; cout << square_root(Object("225.0")); cout << endl; cout << square_root(Object("2.25")); cout << endl; cout << square_root(Object("0.0225")); cout << endl; cout << square_root(Object("-1")); cout << endl; return 0; } PL460 program output: 15.0 1.5 0.15 Argument must be >= 0 C++ program output: 15.0 1.5 0.15 Argument must be >= 0 Differences: < pl460 | cpp > 15.0 15.0 1.5 1.5 0.15 0.15 Argument must be >= 0 Argument must be >= 0