Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For each of the problems below you are to consider making a function to solve th

ID: 3862873 • 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.

Explanation / Answer

Name of function- minmax()

Purpose- To find the greatest and least of a set of 7 values

Input Required- 7 values to be input by the user. All of these will be input when the function is being executed.
No input taken before the start of the function will be passed to it as parameters.
(Note- in case the phrase 'accept 7 values from the function call' means that these values have to be passed to the function as parameters, please make the required changes to the above statement. I am mentioning algorithms for both scenarios below)

Expected Output- The function should return the minimum and maximum of the 7 entered values. As given in the problem statement, these values have to be returned to the calling function. So they will be returned to the function and not to the monitor directly.

Algorithm 1 (use this if the 7 input values don't have to be passed as parameters)

START

INCLUDE IOSTREAM
USE NAMESPACE STD
FUNCTION NAME- minmax()
RETURN TYPE- std::pair<data-type,data-type> //replace data-type with the type of data being input- int, double, etc
DECLARATIONS- <data-type> min, max, num;       //replace data-type with the type of data being input- int, double, etc
               int counter

COUT "Enter the seven values :-"
FOR(counter=1;counter<8;counter++){
   CIN num;
   IF counter == 1
       min=max=num;
   ELSE
       IF num>max
           max=num
       IF num<min
           min=num
}
RETURN std::make_pair(min,max)   //this will return the values min and max as a sort of structure with the two values in it.
                               // these values can then be accessed separately in the calling function by using .first for min      
                               //(in this case) and .second for max
STOP

Algorithm 2 (use this if the 7 input values have to be passed as parameters)

START

INCLUDE IOSTREAM
INCLUDE STRING
INCLUDE STDLIB.H
USE NAMESPACE STD
FUNCTION NAME- minmax()
RETURN TYPE- std::pair<data-type,data-type> //replace data-type with the type of data being input- int, double, etc
PARAMETERS- string Values   //the calling function must receive the 7 values and concatenate them into a single string separated
                           //by spaces before passing the said string to the minmax function
DECLARATIONS- <data-type> min, max, num;       //replace data-type with the type of data being input- int, double, etc
               int counter
FOR (counter=1;counter<8;counter++){
   SEPARATE AND REMOVE THE LEFTMOST VALUE FROM THE STRING Values AND CONVERT IT TO THE REQUIRED DATA-TYPE AND ASSIGN THIS SEPARATED VALUE TO num
               //this can be done using a combination of find() and substr() methods of string object
               //followed by the type conversion
               //e.g- if data-type is int, the statement will be something like,
               //num=atoi((Values.substr(0,Values.find(" "))).c_str());
               // for float use atof() and so on.

//then remove this substring from the Values string using substr()
  
   IF counter == 1
       min=max=num;
   ELSE
       IF num>max
           max=num
       IF num<min
           min=num
}
RETURN std::make_pair(min,max)   //this will return the values min and max as a sort of structure with the two values in it.
                               // these values can then be accessed separately in the calling function by using .first for min      
                               //(in this case) and .second for max
STOP

Test Data:-
This will depend on the data-type you want to use. If you want to use int, then any valid seven int values will do, if you want to use double, any seven double values will do, if you want to use string, then any seven string values (without spaces) will do and so on...
(Please modify this section as required)