For each of the problems below you are to consider making a function to solve th
ID: 3590715 • Letter: F
Question
For each of the problems below you are to consider making a function to solve the problem. As before, state the purpose of the function in your own words. Next specify input that is needed for the function to complete the task, and state what input should be passed to the function as parameters and what would be acquired inside the function using the input function. Specify the expected output and state if the output will be returned to the function call or be sent to the monitor. Finally give the step by step process that will obtain the output from the input (the algorithm). In addition to these 4 items also specify test data that can be used for each function. Remember to describe your steps in enough detail so someone other than you could follow your algorithm and solve the problem. Also do not write any actual code.
Problem 2: Describe a function that would accept 7 values from the function call and determine the minimum and maximum of those 7 values. Design this function without using the idea of arrays or lists. Send back to the function call the minimum and maximum value. (Hint, you should use no more than 7 comparisons to find the maximum and no more than 7 comparisons to find the minimum.)
Explanation / Answer
Algorithm : Fucntion to find the minimum and maximum value from the given 7values.
function minimum(x1,x2,x3,x4,x5,x6,x7):
Input :7 values. (x1,x2,x3,x4,x5,x6,x7)
output: Minimum value (min) from 7 given values.
pseudocode:
Step 1: Assign first value as minimum value, min=x1
Step 2: compare this min value with next value.
min = (min < x2) ? min : x2 .
// if min is less than x2, then min =min, else min= x2
step 3: Repeat step 2, for all other 6 remaining value.
min = (min < x3) ? min : x3
min = (min < x4) ? min : x4
min = (min < x5) ? min : x5
min = (min < x6) ? min : x6
min = (min < x7) ? min : x7
Step 4: Return the minimum value , return min
function maximum(x1,x2,x3,x4,x5,x6,x7):
Input :7 values. (x1,x2,x3,x4,x5,x6,x7)
output: Maximum value (max) from 7 given values.
pseudocode:
Step 1: Assign first value as maximum value, max=x1
Step 2: compare this max value with next value.
max = (max > x2) ? max : x2
If max is greater than x2, then max =max, else max= x2
Step 3: Repeat the Step 2, for all other 6 remaining value.
max = (max > x3) ? max : x3
max = (max > x4) ? max : x4
max = (max >x5) ? max : x5
max = (max > x6) ? max : x6
max = (max > x7) ? max : x7
Step 8: Return the maximum value. as, return max
//i have given algorithm for function minimum and function maximum . if you need any more clarification or any modification please do comments.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.