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

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.
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...
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,...
Write a function that will accept two integer matrices C and D by reference parameters. The...
Write a function that will accept two integer matrices C and D by reference parameters. The function will compute the transpose of C and store it in D. For your information, the transpose of matrix C is D, where D[j][i] = C[i][j]. [7 marks] Explain the time complexity of this function inside of the function code as a comment. [3 marks] in C++
Write a function in c++, called afterAll that takes two parameters, a vector of string and...
Write a function in c++, called afterAll that takes two parameters, a vector of string and a string. The function returns true if the 2nd parameter comes after all of the strings in the vector, order-wise, false if not. As an example, "zoo" comes after "yuzu".
In C++ Write a function which takes two parameters: an array of ints and an int...
In C++ Write a function which takes two parameters: an array of ints and an int size of the array and prints every element greater than 5 to the screen. As an example, if the array has the following 10 elements: 2 5 8 9 7 1 0 2 6 3, your function should print out 8 9 7 6. You may assume that the parameters passed to the function are valid. Your function must have the following signature: void...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT