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...

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

  • 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...

  • 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,...

  • PLEASE HELP ME WITH THIS TASK 3.1 (FLOWCHART) AND TASK 3.2 (SOURCE PROGRAM). THANK YOU! Hint:...

    PLEASE HELP ME WITH THIS TASK 3.1 (FLOWCHART) AND TASK 3.2 (SOURCE PROGRAM). THANK YOU! Hint: the number array in task 2 is work for task 3 in figure 1.   Given below is a partially completed C program, which you will use as a start to complete the given tasks. #define SIZE 9 #include <stdio.h> int compareAndCount (int[], int[]); double averageDifference (int[], int[]); void main() { } int compareAndCount(int arr1[SIZE], int arr2[SIZE]) { int count = 0; for (int i...

  • C++ Lab 11 – Is This Box a Magic Box? Objectives: Define a two dimensional array Understand h...

    C++ Lab 11 – Is This Box a Magic Box? Objectives: Define a two dimensional array Understand how to traverse a two dimensional array Code and run a program that processes a two dimensional array Instructions: A magic square is a matrix (two dimensional arrays) in which the sum of each row, sum of each column, sum of the main diagonal, and sum of the reverse diagonal are all the same value. You are to code a program to determine...

  • Program 5 Due 10/25 C-String and Two-dimensional Array Use An input data file starts with a...

    Program 5 Due 10/25 C-String and Two-dimensional Array Use An input data file starts with a student's name (on one line). Then, for each course the student took last semester, the file has 2 data lines. The course name is on the first line. The second line has the student's grade average (0 to 100) and the number of credits for the course Sample data: Jon P. Washington, Jr. Computer Science I 81 4 PreCalculus 75 3 Biology I 88...

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
ADVERTISEMENT