1 answer

Write a function called ''minandmax'' . Function ''minandmax'' takes only one input argument that is a...

Question:

Write a function called ''minandmax'' .

Function ''minandmax'' takes only one input argument that is a matrix M .

This matrix M can be any size (any number of columns and rows) with any random integer values . Function ''minandmax'' returns two output arguments.

The first output argument is called ''difference_row'' that returns a row vector containing the absolute values of the difference between the maximum and minimum valued elements in each row.

The second output argument is called ''difference_all'' that returns the difference between the maximum and minimum valued elements in the entire matrix.


Answers

NOTE: HERE THE PROGRAM IS DONE BOTH WITH C++ AND JAVA

FOR BOTH THE PROGRAM TWO OUTPUT ARGUMENTS ARE TAKEN IN ARRAY AND PASSED TO MAIN FUNCTION. THE ARRAY IN MAIN FUNCTION PRINTS BOTH OUTPUT ARGUMENTS.

IN THIS WAY TWO OUTPUT ARGUMENTS ARE RETURNED BY FUNCTION USING ARRAY TO MAIN FUNCTION.

PROGRAM IN C++

#include<iostream>
#include <stdlib.h>
#include<time.h>

using namespace std;
/* r,c as global variable */
int r,c;
/* function defined with pointer for returning array */
int * minandmax(int v[][100])
{
int difference_row[r],i,j;
/* array of pointer */
int *result;
int max=0;
   int min=v[0][0];
   int difference_all;
   /* dynamically allocate space in result array */
   result=new int[r+1];
   /*Difference between the maximum and minimum valued elements in each row.*/
   for(i=0;i<r;i++)
   {
       for(j=0;j<c;j++)
       {
           if(max<v[i][j])
           {
               max=v[i][j];
           }
           if(min>v[i][j])
           {
               min=v[i][j];
           }
       }
       /* first output argument difference_row is a vector */
       difference_row[i]=max-min;
       max=0;min=v[0][0];
      
   }
   max=0;min=v[0][0];
   /* Difference between the maximum and minimum valued elements in the entire matrix */
   for(i=0;i<r;i++)
   {
       for(j=0;j<c;j++)
       {
           if(max<v[i][j])
           {
               max=v[i][j];
           }
           if(min>v[i][j])
           {
               min=v[i][j];
           }
   }
}
/*The second output argument is difference_all*/
difference_all=max-min;
/* take two output arguments in a sing array named by result */
for(i=0;i<r;i++) result[i]=difference_row[i];
result[r]=difference_all;

   /* return the two arguments difference_row vector and difference_all with the array result*/
   return result;
}

main()
{
   int i,j,v[100][100];
   /* pointer to array */
   int *res;
   /* console input */
   cout<<"How many rows :";
   cin>>r;
   cout<<"How many columns :";
   cin>>c;
   /* random integers taking in matrix */
   srand(time(0));
   for(i=0;i<r;i++)
   {
      for(j=0;j<c;j++)
      {
      v[i][j]=rand();  
       }
   }
   /* print matrix */
   cout<<endl<<endl<<"Matrix is"<<endl<<endl;
   for(i=0;i<r;i++)
   {
      for(j=0;j<c;j++)
      {
      cout<<v[i][j]<<"\t";  
       }
       cout<<endl;
   }
   cout<<endl;
   /* store starting address of returned array in res*/
   res=minandmax(v);
   /* print two desired returned values */
   cout<<endl<<"Difference between the maximum and minimum valued elements in each row."<<endl<<endl;
   for(i=0;i<r;i++)
   {
      cout<<res[i]<<" ";
   }
   cout<<endl<<endl<<"Difference between the maximum and minimum valued elements in the entire matrix : " << res[i];
     


}

SCREEN SHOT

#include<iostream> #include <stdlib.h> #include<time.h> using namespace std; /* r,c as global variable int r,c; /* function d

} max=0;min=v[@][@]; /* Difference between the maximum and minimum valued elements in the entire matrix */ for(i=0;i<r;i++) {

cout<<How many columns :; cin>>c; /* random integers taking in matrix */ srand(time()); for(i=0;i<r;i++) { for(j=0; j<c; j+

OUTPUT

L E:\min_max.exe How many rows :6 How many columns :7 Matrix is 28156 22026 6740 30268 2892 18829 2464 26857 2725 3288 13691

PROGRAM IN JAVA

/* import scanner class from util package */
import java.util.Scanner;
// using java.util.Random;
import java.util.Random;

class cal
{
/* function defined with array type for returning array */
public static int[] minandmax(int[][] v)
{
int r=v.length;
   int c=v[0].length;
   int difference_row[]=new int[r];
   int i,j;
int result[]=new int[r+1];
int max=0;
   int min=v[0][0];
   int difference_all;
   /*Difference between the maximum and minimum valued elements in each row.*/
   for(i=0;i<r;i++)
   {
       for(j=0;j<c;j++)
       {
           if(max<v[i][j])
           {
               max=v[i][j];
           }
           if(min>v[i][j])
           {
               min=v[i][j];
           }
       }
       /* first output argument difference_row is a vector */
       difference_row[i]=max-min;
       max=0;min=v[0][0];
      
   }
   max=0;
   min=v[0][0];
   /* Difference between the maximum and minimum valued elements in the entire matrix */
   for(i=0;i<r;i++)
   {
       for(j=0;j<c;j++)
       {
           if(max<v[i][j])
           {
               max=v[i][j];
           }
           if(min>v[i][j])
           {
               min=v[i][j];
           }
   }
}
/*The second output argument is difference_all*/
difference_all=max-min;
/* take two output arguments in a sing array named by result */
for(i=0;i<r;i++) result[i]=difference_row[i];
result[r]=difference_all;

   /* return the two arguments difference_row vector and difference_all with the array result*/
   return result;
}
}
public class res_min_max
{
public static void main(String[] args)
{
   int i,j;
   int r,c;
   /* pointer to array */
   Scanner sc=new Scanner(System.in);
   cal ob=new cal();
   /* console input */
   System.out.print("How many rows :");
   r=sc.nextInt();;
   System.out.print("How many columns :");
   c=sc.nextInt();;
   int v[][]=new int[r][c];
   /* random class */
   Random random = new Random();
   /* random integers taking in matrix */
   for(i=0;i<r;i++)
   {
      for(j=0;j<c;j++)
      {
      /* here we take any random integer considering positive in this program */
       /* so Math.abs function is used */
       v[i][j]=Math.abs(random.nextInt());  
       }
   }
   /* print matrix */
   System.out.println("\nMatrix is\n");
   for(i=0;i<r;i++)
   {
      for(j=0;j<c;j++)
      {
      System.out.print(v[i][j]+ "\t");  
       }
       System.out.println();
   }
   System.out.println();
   /* store starting address of returned array in res*/
   int res[]=ob.minandmax(v);
   /* print two desired returned values */
   System.out.println("Difference between the maximum and minimum valued elements in each row.\n");
   for(i=0;i<r;i++)
   {
      System.out.print(res[i] + " ");
   }
   System.out.println("\n\nDifference between the maximum and minimum valued elements in the entire matrix : " + res[i]);
     
}

}

SCREEN SHOT

/* import scanner class from usit package */ import java.util.Scanner; // using java.util. Random; import java.util.Random; c

difference_row[i]=max-min; max=0;min=v[0][0]; } max=0; min=v[0][0]; /* Difference between the maximum and minimum valued elem

public class res_min_max I { public static void main(String[] args) { int i, j; int r,c; /* pointer to array */ Scanner sc=ne

System.out.print (v[i][j]+ \t); } System.out.println(); } System.out.println(); /* store starting address of returned array

OUTPUT

C:\Program Files\Java\jdk1.8.0_131\bin>javac res_min_max.java C:\Program Files\Java\jdk1.8.0_131\bin>java res_min_max How man

.

Similar Solved Questions

1 answer
Question 1: (50% CLO 2 and 50% CLO3) 36 points, a 18, b6 and d=12 The...
Question 1: (50% CLO 2 and 50% CLO3) 36 points, a 18, b6 and d=12 The yield of a chemical process is beine studied. The two most important variables are thought to be the temperature (A) and the pressure (8). A factorial experiment with two replicates is performed. The yield data follow: Yield % Rep...
1 answer
The following concepts make Six Sigma a powerful approach for improvement EXCEPT? A) A focus on...
The following concepts make Six Sigma a powerful approach for improvement EXCEPT? A) A focus on measureable bottom-line results B) Lengthy project schedules C) A disciplined statistical approach to problem solving D) Organizational infrastructure...
1 answer
4x + 3 The function f(x) = x75, is one-to-one. 9 X-5 Find an equation for...
4x + 3 The function f(x) = x75, is one-to-one. 9 X-5 Find an equation for f'(x), the inverse function. F"(x)=,x+4 (Simplify your answer. Use integers or fractions for any numbers in the expression.)...
1 answer
Grass Chopper GrassChopper is North America's largest manufacturer of commercial and residential lawn mowing and turf...
Grass Chopper GrassChopper is North America's largest manufacturer of commercial and residential lawn mowing and turf equipment including mulchers, grass collectors, and edgers. GrassChopper also offers attachments for snow removal and stump cutting. Historically, GrassChopper has relied on two ...
1 answer
Basic concept template on enternal feedings
basic concept template on enternal feedings...
1 answer
Part b and c!!! please help! Consider the following observations on a receptor binding measure (adjusted...
part b and c!!! please help! Consider the following observations on a receptor binding measure (adjusted distribution volume) for a sample of 13 healthy individuals: 23, 39, 40, 41, 44, 48, 52, 58, 64, 67, 68, 69, 71. (a) Is it plausible that the population distribution from which this sample was se...
1 answer
Laboratory tests on a 2.5 cm thick clay sample that is drained on both sides indicates...
Laboratory tests on a 2.5 cm thick clay sample that is drained on both sides indicates that 50% consolidation occurs after 8.5 minutes (a) How long will it take for 50% consolidation for the same clay in the field that is 4 m thick but drained at the top only? (b) Find the time required for the same...
1 answer
Explain the different of low serum calcium on skeletal muscle and cardiac muscle
Explain the different of low serum calcium on skeletal muscle and cardiac muscle...
1 answer
= 29N ст 53N Х 13 2 cm sh a). k=9cm 105. m = 4cm TWO...
= 29N ст 53N Х 13 2 cm sh a). k=9cm 105. m = 4cm TWO STRINGS ARE ATTACHEN TO A Hook AND THE Tenslons ARE D-29 N AND E 53 N POR EACH. RESOLVE X AND E acond FORCE Y AXES. CALCULATE THE component (N) Acono AND Y AXI RESOLVE FORCE scono AD Y AXES. CALCULATE The componens (ue Konc x AND...
1 answer
How do you balance #H_2O + SO_3 -> H_2SO_4#?
How do you balance #H_2O + SO_3 -> H_2SO_4#?...
1 answer
Alosio Manufacturing Company manufactures a variety of tools and industrial equipment. The company operates three divisions....
Alosio Manufacturing Company manufactures a variety of tools and industrial equipment. The company operates three divisions. Each division is an investment centre. Operating data for the home division for the year ended December 31, 2020, and relevant budget data are as follows: Actual Compar...
1 answer
Computech Corporation is expanding rapidly and currently needs to retain all of its earnings; hence, it...
Computech Corporation is expanding rapidly and currently needs to retain all of its earnings; hence, it does not pay dividends. However, investors expect Computech to begin paying dividends, beginning with a dividend of $1.00 coming 3 years from today. The dividend should grow rapidly - at a rate of...
1 answer
Nutrition Facts Serving Size 1 cup (240mL) Servings Per Container about 4 Calories 160 Calories from...
Nutrition Facts Serving Size 1 cup (240mL) Servings Per Container about 4 Calories 160 Calories from Fat 70 Daily Value Total Fat Bg Saturated Fat 59 Trans Fat og Cholesterol 35mg Sedium 125mg Total Carbohydrate 139 Dietary Fborg Sugars 129 Protein Bg utrition Facts ving Size 1 cup (240mL) Servings ...
1 answer
Please type the answer. i can’t read hand writings metabolic rate Why do physiological parameters change...
please type the answer. i can’t read hand writings metabolic rate Why do physiological parameters change after carbohydrate (CHO) consumption?...
1 answer
Don't answer this question, It was a manipulation error. That is the correct question I want answer for (5) For a random sample of size n from a Uniform (0, 5+ ple of size n from a Uniform...
don't answer this question, It was a manipulation error. That is the correct question I want answer for (5) For a random sample of size n from a Uniform (0, 5+ ple of size n from a Uniform ( θ, 5+8) population, write estimators of o (both of which f which use the entire sample). Call t...
1 answer
2. a) Use the Laplace transform method to solve: y" + y' + 1.25 y =...
2. a) Use the Laplace transform method to solve: y" + y' + 1.25 y = t - UT y(0) = 0, y'(0) = 0. b) Draw a careful graph of the forcing function in this mass-spring-damper problem. c) Using a computer or calculator construct a careful graph of the function....
1 answer
Compute and Interpret Altman's Z-scores Following is selected financial information for ebay, for its fiscal years...
Compute and Interpret Altman's Z-scores Following is selected financial information for ebay, for its fiscal years 2005 and 2006. (In millions, except per share data) 2006 2005 Current assets $4,967.59 $3,180.24 Current liabilities 2,518.39 1,484.93 Total assets 13,491.01 11,785.99 Total liabili...
1 answer
2. Do the fore limbs and hind limbs have the same number of toes? What could...
2. Do the fore limbs and hind limbs have the same number of toes? What could be the reason for having webbing in between the toes?...
1 answer
Part B Gastric acid pH can range from 1 to 4, and most of the acid is HCI. For a sample of stomach acid that is 6...
Part B Gastric acid pH can range from 1 to 4, and most of the acid is HCI. For a sample of stomach acid that is 6.95x10- Min HCl, how many moles of HCl are in 12.9 mL of the stomach acid? Express the amount to three significant figures and include the appropriate units. View Available Hint(s) DHM&Au...