Question

Array processing Create a program that processes two-dimensional array according to task variant Additional requirements 1. 2. 3. 4. Input dimensions of array form keyboard (use dynamic memory allocation) Fill array with random numbers in range R. Processing of array should be implemented as function (using indices). Displaying the content of array should be implemented as function (using pointers) 5 12 8 2 8 3 3 16 1 22 215 34 0 11 88 13 22 6 5 81 76 23 56 118 5. 6. Program should output text message in case of errors. Program has to be written in C or C++ Task variants Last digit of number of Task student card 0 or 1 Define 3 smallest elements in array and their indices (number of row and column 100. 50
0 0
Add a comment Improve this question Transcribed image text
Answer #1

/*Source code of above program is given below in C++*/

#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
void process(int output[],int** array,int row,int col);
void display(int * op,int** array,int row,int col);

int main()
{
   int row,col;
   cout<<"Enter number of rows of array: ";
   cin>>row;
   cout<<"\nEnter number of columns of array: ";
   cin>>col;
   int count=0;
   //defining range [min,max)
   //random number would be generated within -100 and 50
   int min=-100;
   int max= 51;
   int** array = new int*[row];
   for(int i = 0; i < row; ++i)
       array[i] = new int[col];
   //filling the array with random numbers
   for(int i=0;i<row;i++)
   {  
       for(int j=0;j<col;j++)
       {
           static bool first = true;
            if ( first )
            {
                 srand(time(NULL)); //seeding for the first time only!
                 first = false;
           }
            array[i][j] = min + rand() % (max - min);  
            count++;
       }
   }
   if(count<3)
   {
   //if number of elements are less than 3
      cout<<"Error has ocured!!";
      exit(0);
   }
   //processing array
   int output[9];//for storing output
   process(output,array,row,col);
   display(output,array,row,col);
   return 0;
}
void display(int * op,int** array,int row,int col)
{
   cout<<"\nOriginal array: "<<endl;
   for(int i=0;i<row;i++)
   {  
       for(int j=0;j<col;j++)
       {
           cout<< *(*(array + i) + j)<<"\t";
       }
       cout<<endl;
   }

   for(int i=0;i<9;i++)
   {
       if(i==0)
           cout<<"\n Smallest element:"<<*(op+i);
       else
           cout<<"\n Next smallest element:"<<*(op+i);
       i=i+1;
       cout<<" row number: "<<*(op+i);
       i=i+1;
       cout<<" column number: "<<*(op+i);
   }      
}
void process(int output[],int** array,int row,int col)
{
   int k,l,min= 999,min1=999,min2=999;
   for(int i=0;i<row;i++)
   {  
       for(int j=0;j<col;j++)
       {
           if(min>array[i][j])
           {
               min=array[i][j];
               k=i;
               l=j;
           }
       }
   }
   output[0]=min;
   output[1]=k;
   output[2]=l;
   for(int i=0;i<row;i++)
   {  
       for(int j=0;j<col;j++)
       {
           if(array[i][j]==min)
               continue;
           if(min1>array[i][j])
           {
               min1=array[i][j];
               k=i;
               l=j;
           }
       }
   }
   output[3]=min1;
   output[4]=k;
   output[5]=l;
   for(int i=0;i<row;i++)
   {  
       for(int j=0;j<col;j++)
       {
           if(array[i][j]==min || array[i][j]==min1)
               continue;
           if(min2>array[i][j])
           {
               min2=array[i][j];
               k=i;
               l=j;
           }
       }
   }
   output[6]=min2;
   output[7]=k;
   output[8]=l;
}

/*For better understanding output screenshot is attached here*/

/*If this helps you, please let me know by giving a positive thumbs up. In case you have any queries, do let me know. I will revert back to you. Thank you!!*/

Add a comment
Know the answer?
Add Answer to:
Array processing Create a program that processes two-dimensional array according to task variant Additional requirements 1....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • array function • Create a function called show2D. • This function should accept a two-dimensional array...

    array function • Create a function called show2D. • This function should accept a two-dimensional array as parameter and display its contents that are odd numbers on the screen. • This function should work with any of the following arrays of different sizes: int hours[3][9]; int stamps[7][9]; int cities[15][9]; • Write a demo program to show how to use the function show2D. this is c++ program Task 2: Array functions • Create a function called show2D. • This function should...

  • In this project you will create a console C++ program that will have the user to...

    In this project you will create a console C++ program that will have the user to enter Celsius temperature readings for anywhere between 1 and 365 days and store them in a dynamically allocated array, then display a report showing both the Celsius and Fahrenheit temperatures for each day entered. This program will require the use of pointers and dynamic memory allocation. Getting and Storing User Input: For this you will ask the user how many days’ worth of temperature...

  • Use C: 3. In function main, declare a two-dimensional integer array with 5 rows and 4...

    Use C: 3. In function main, declare a two-dimensional integer array with 5 rows and 4 columns. Call the following functions from function main. Call a function createArray to seed the random number generator and to fill the two-dimensional array with random integers between -20 and +20. Parameters for this function should be the array and the number of rows and columns). Call a function signs to count the number of positive values, number of negative values and number of...

  • Write a program that randomly generates a 20 3 20 two-dimensional array, board, of type int....

    Write a program that randomly generates a 20 3 20 two-dimensional array, board, of type int. An element board[i][j] is a peak (either a maximum or a minimum) if all its neighbors (there should be either 3, 5, or 8 neighbors for any cell) are less than board[i][j], or greater than board[i][j]. The program should output all elements in board, with their indices, which are peak. It should also output if a peak is a maximum or a minimum. c++...

  • Write a C program to assign natural numbers 1 to 100 into a one-dimensional integer array....

    Write a C program to assign natural numbers 1 to 100 into a one-dimensional integer array. Display all the values in the array on the screen. For each number in the array, determine if the number contains digit 7 or is divisible by 7. Display all those numbers on the screen. Original array: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27...

  • Using C++ create a lotto program Lottery Design a program that simulates a lottery. Requirements:  The program...

    Using C++ create a lotto program Lottery Design a program that simulates a lottery. Requirements:  The program should have an array of 5 integers named lottery and should generate a random number in the range of 1 through 99 for each element of the array. The user should enter five digits, which should be stored in an integer array named user. The program is to compare the corresponding elements in the two arrays and keep a count of the digits that...

  • Write a C++ program that will test function described below that use pointers and dynamic memory...

    Write a C++ program that will test function described below that use pointers and dynamic memory allocation. Functions: You will write the function described below. Then you will call them from the main function, to demonstrate their correctness. concat_array: takes two int arrays and the arrays' sizes as arguments (that's 4 arguments). It should create a new array big enough to store both arrays. Then it should copy the contents of the first array to the new array, and then...

  • ASSEMBLY LANGUAGE The matrix (two-dimensional array) with ROWS and COLS dimensions of integer values is given....

    ASSEMBLY LANGUAGE The matrix (two-dimensional array) with ROWS and COLS dimensions of integer values is given. Perform various matrix processing activities according to the algorithms below. Store the results into the output vector (one-dimensional array) with appropriate size. For Grade 7) Count the number of odd values (n mod 2 <> 0) for each row. For Grade 9) Calculate the sum of positive values for each column. To obtain inputs and return the results, define appropriate type C/C++ functions. Please...

  • Write a program that uses a two-dimensional array to store the highest and lowest temperatures for each month of the year. The program should output the average high, average low, and the highest and...

    Write a program that uses a two-dimensional array to store the highest and lowest temperatures for each month of the year. The program should output the average high, average low, and the highest and lowest temperatures for the year. Your program must consist of the following functions 1. Function getData: This function reads and stores data in the two- dimensional array. 2. Function averageHigh: This function calculates and returns the aver- age high temperature for the year. 3. Function averageLow:...

  • I should use the array and loop to create a java program according to the instruction,...

    I should use the array and loop to create a java program according to the instruction, but I have no idea how to do it. Introduction This lab assignment continues to give you practice using loops, particularly loops with variable termination conditions, and it also provides you an opportunity to use one-dimensional arrays. Recall that an array is used to store a collection of data. The data can be values of Java primitive data types or else objects (for instance,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT