Question

In: Computer Science

C++ Write the definition of a function minMax that has five parameters. The first three parameters...

C++

Write the definition of a function minMax that has five parameters. The first three parameters are integers. The last two are set by the function to the largest and smallest of the values of the first three parameters. The function does not return a value.

The function can be used as follows:

        int a=31, b=5, c=19 big, small;
        minMax(a,b,c,&big,&small);
        /* big is now 31 */
        /* small is now 5 */

**ONLY THE FUNCTION

Solutions

Expert Solution

Code -

#include <stdio.h>
// Populate big/small based on max/min of x, y and z.
void minMax (int x, int y, int z, int *big, int *small) {
//initialize big with value of x
*big = x;
//check if y is greater then big then initialize y to big
if (y > *big) *big = y;
//check if z is greater then big then initialize z to big
if (z > *big) *big = z;

//initialize big with value of x
*small = x;
//check if y is smaller then big then initialize y to big
if (y < *small) *small = y;
//check if z is smaller then big then initialize z to big
if (z < *small) *small = z;
}
int main()
{
//initialize variable a,b,c,big and small
int a=49,b=78,c=24,big,small;
//call function minMax with the following values
minMax(a,b,c,&big,&small);
//print the values of Big and small
printf("Big is: %d\n",big);
printf("Small is: %d",small);

return 0;
}

Screenshots -

pls do give a like , thank you


Related Solutions

************CODING IN C++ ONLY ******************** Instructions Write a function, remove, that takes three parameters: an array...
************CODING IN C++ ONLY ******************** Instructions Write a function, remove, that takes three parameters: an array of integers, the number of elements in the array, and an integer (say, removeItem). The function should find and delete the first occurrence of removeItem in the array. (Note that after deleting the element, the number of elements in the array is reduced by 1.) Assume that the array is unsorted. Also, write a program to test the function. Your program should prompt the...
Programming in C (not C++) Write the function definition for a function called CompareNum that takes...
Programming in C (not C++) Write the function definition for a function called CompareNum that takes one doyble argument called "num". The function will declare, ask, and get another double from the user. Compare the double entered by the user to "num" and return a 0 if they are the same, a -1 num is less than the double entered by the user and 1 if it is greater.
C++ Write the implementation of the function concatenateIntArrays. This function receives 4 parameters in the following...
C++ Write the implementation of the function concatenateIntArrays. This function receives 4 parameters in the following order: An array of integer values (array1). An integer representing the size of array1 (size1). An array of integer values (array2). An integer representing the size of array2 (size). The function creates a dynamic array of integers of size size1+size2 to store all the values in array1, followed by all the values in array2. The function returns the pointer used to create the dynamic...
Write a Python function that takes two parameters: the first a list of strings and the...
Write a Python function that takes two parameters: the first a list of strings and the second a single string. The function should return True or False depending on whether the string is in the list or not. For example, if the list contains eggs, milk, bananas, and the second parameter is pumpkin, the function should return False. Thank you.
Write a Python function that takes two parameters: the first a list of strings and the...
Write a Python function that takes two parameters: the first a list of strings and the second a single string. The function should return True or False depending on whether the string is in the list or not. For example, if the list contains eggs, milk, bananas, and the second parameter is pumpkin, the function should return False. Thank you.
Please, use C++ for this question. (b) Write the definition of displayBox() function. The function will...
Please, use C++ for this question. (b) Write the definition of displayBox() function. The function will display a matrix of integers from 1 to 4 such that the first row will contain four 1s, the second row will contain four 2s, the third row will contain four 3s and the fourth row will contain four 4s. Function must use nested loops to display each column and row heading as well as the numbers. The function has no parameters and no...
Write the following task in C++1) Write the definition of a function numOccurrences thatsearches...
Write the following task in C++1) Write the definition of a function numOccurrences that searches for a character in a character array and returns the number of times it occurs in the array. The function has three formal parameters: a char array array, an int variable arraySize representing the size of the array, and a character variable letter representing the character to be searched for in the array.2) Assume the array numbers is an int array of size 10 and...
Nested Loops Problem 3 Write a function called makesentence() that has three parameters: nouns, verbs, and...
Nested Loops Problem 3 Write a function called makesentence() that has three parameters: nouns, verbs, and gerunds. Each parameter is a list of strings, where nouns list has noun strings (such as 'homework'), verbs list has veb strings (such as 'enjoy'), and gerunds list has gerund strings (those -ing words, such as 'studying'). The function will go through all these lists in a systematic fashion to create a list of all possible sentences that use all the noun, verb, and...
Write a C++ function, smallestIndex, that takes as parameters an int array and its size and...
Write a C++ function, smallestIndex, that takes as parameters an int array and its size and returns the index of the first occurrence of the smallest element in the array. Write another C++ function,lastLargestIndex, that takes as parameters an int array and its size and returns the index of the last occurrence of the largest element in the array. An analysis and design of the function smallestIndex is given below. Write an analysis and design for the function lastLargestIndex. Write...
Write a C++ function, smallestIndex, that takes as parameters an int array and its size and...
Write a C++ function, smallestIndex, that takes as parameters an int array and its size and returns the index of the first occurrence of the smallest element in the array. Also, write a program to test your function. You must write our commands in the middle: Write a C++ Program: #include <iostream> using namespace std; const int ARRAY_SIZE = 15; void printArray(const int x[], int sizeX); int smallestIndex(const int x[], int sizeX); int main() {      int list[ARRAY_SIZE] = {56,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT