//========================================================================= #define PROGRAMMER "SOLUTIONS, NoFrills" #define PROG_CODE "soln" #define COURSE "ECE-1021" #define YEAR (2004) #define TERM "Spring" #define SECTION (0) #define ASSIGNMENT "HW #4A" #define REVISION (0) #define TITLE "Mystery Algorithm" #define SUBTITLE "Function: UNKNOWN" #define EMAIL "ece1021@eas.uccs.edu" #define FILENAME "04a0soln.txt" //========================================================================= This is the pseudocode for a classic computational algorithm. It is very complete meaning that you should be able to code it directly from the pseudocode. Once it is coded, run it and try to determine what the functional relationship is between the input value and the output value. 1) TASK: Get a number from the user 1.1) PUT: "Enter a non-negative floating point value: " 1.2) GET: x (type double) 1.3) PUT: "Enter number of significant digits to produce: " 1.4) GET: sig (type int) 2) TASK: Print the output header 2.1) PUT: "The output value is " 2.1.1) REM: space after string, no carriage return 3) TASK: Initialize working value 3.1) SET: y = 5*x (type double) 3.1.1) REM: Algorithm designed to work with five times the input value 4) TASK: Initialize certain variables based on size of input 4.1) REP: 4.1.1) PRE: 4.1.1.1) SET: z = 1 (type double) 4.1.1.2) SET: j = 0 (type int) 4.1.2) WHILE: ( y - 100z >= 0) 4.1.2.1) SET: z = 100z 4.1.2.2) SET: j = j + 1 4.1.3) LOOP: 5) TASK: Generate output one digit at a time 5.1) REP: 5.1.1) PRE: 5.1.1.1) SET: s = 0 (type double) 5.1.1.2) SET: k = 0 (type int) 5.1.2) WHILE: ( k < sig ) 5.1.2.1) REP: 5.1.2.1.1) PRE: 5.1.2.1.1.1) SET: n = 0 (type int) 5.1.2.1.2) LOOP: 5.1.2.1.2.1) d = [100s + 5(2n+1)]z (type double) 5.1.2.1.2.2) y = y - d 5.1.2.1.2.3) n = n + 1 5.1.2.1.3) UNTIL ( y < 0 ) 5.1.2.1.4) POST: 5.1.2.1.4.1) SET: y = y + d 5.1.2.1.4.2) SET: n = n - 1 5.1.2.2) SET: z = z / 100 5.1.2.3) SET: s = 10s + n 5.1.2.4) IF: ( k > 0) 5.1.2.4.1) SET: k = k + 1 5.1.2.4.2) PUT: n 5.1.2.4.2.1) REM: no leading or trailing space, no carriage return 5.1.2.5) ELSE: 5.1.2.5.1) SEL: ( n > 0) 5.1.2.5.1.1) TRUE: 5.1.2.5.1.1.1) SET: k = k + 1 5.1.2.5.1.1.2) PUT: n 5.1.2.5.1.1.2.1) REM: no leading or trailing space, no carriage return 5.1.2.5.1.2) FALSE: 5.1.2.5.1.2.1) IF: ( j < 0 ) 5.1.2.5.1.2.1.1) PUT: n 5.1.2.5.1.2.1.1.1) REM: no leading or trailing space, no carriage return 5.1.2.6) IF: ( j = 0 ) 5.1.2.6.1) PUT: '.' 5.1.2.6.1.1) REM: decimal point with no space, no carriage return 5.1.2.7) SET: j = j - 1 5.1.3) LOOP: