with complex_types; use complex_types; with complex_elementary_functions; use complex_elementary_functions; with text_io; use text_io; with complex_io; procedure calc is package cx_io is new complex_io(float, complex); use cx_io; type funct_type is ( quit, stop, bye, sqrt, log, exp, sin, arcsin, asin, sinh, arcsinh, asinh, cos, arccos, acos, cosh, arccosh, acosh, tan, arctan, atan, tanh, arctanh, atanh, cot, arccot, acot, coth, arccoth, acoth); package funct_io is new enumeration_io(funct_type); use funct_io; funct : funct_type := sin; argument : complex := (0.0,0.0); result : complex := (0.0,0.0); line : string(1..80); length : natural; position : natural; line_error : exception; argument_error : exception renames complex_elementary_functions.argument_error; begin put_line("Complex Function Calculator."); put_line("Note, the function and the value are modal."); put_line(" The argument '(r)' or '(R)' is previous result."); loop begin put_line("enter (,)"); get_line(line,length); position := 1; begin get(line(1..length),funct,position); position := position + 1; exception when others => if line(1) /= '(' then raise line_error; end if; end; begin get(line(position..length),argument,position); exception when others => if line(position..position+2) = "(r)" or line(position..position+2) = "(R)" then argument := result; elsif position <= length then raise line_error; end if; end; case funct is when quit | stop | bye => exit; when sqrt => result := sqrt(argument); when log => result := log(argument); when exp => result := exp(argument); when sin => result := sin(argument); when arcsin | asin => result := arcsin(argument); when sinh => result := sinh(argument); when arcsinh | asinh => result := arcsinh(argument); when cos => result := cos(argument); when arccos | acos => result := arccos(argument); when cosh => result := cosh(argument); when arccosh | acosh => result := arccosh(argument); when tan => result := tan(argument); when arctan | atan => result := arctan(argument); when tanh => result := tanh(argument); when arctanh | atanh => result := arctanh(argument); when cot => result := cot(argument); when arccot | acot => result := arccot(argument); when coth => result := coth(argument); when arccoth | acoth => result := arccoth(argument); end case; put(" = "); put(result); new_line; exception when text_io.end_error => exit; when line_error => put_line("Bad input."); when argument_error => put_line("argument_error"); when constraint_error => put_line("constraint_error"); when others => put_line("Some exception!"); end; end loop; end calc;