Problems Background work with multidimensional arrays. Your C program should enable the end-user to create any 2D...

70.2K

Verified Solution

Question

Programming

Problems Background

work with multidimensional arrays.Your C program should enable the end-user to create any 2D matrixof n number of rows and m number of columns. The end-user couldeither use random numbers to initialize the matrix data or enterthe values of his/her matrix using standard​ input methods such asa keyboard. After setting up the matrix data using an automatedrandom method or manual method, the end-user could perform anyfollowing operations.

We will use the following matrix as anexample to demonstrate the different operations.

4

6

32

12

1

9

5

7

3

Figure 1: Example of an InputMatrix

Switch Rows

This is a straightforward operationthat enables the end-user to switch the data of any two rows. Forexample switching rows 1 and 2 of the matrix mat in Figure 1 willresult in the following matrix.


This is a straightforward operation that enables the end-user toswitch the data of any two columns. For example, switching columns0 and 2 of the matrix mat in Figure 1 will result in the followingmatrix. Switch Columns

Rotate Matrix

This operation enables the end-user torotate or shift the matrix’s data to the left or right k times. Forexample, rotate the matrix mat in Figure 1 to the right 1 times (k= 1) will result in the following matrix

Each value moved 1 position to theright because k =1

Now rotate the matrix mat in Figure 1,to the left 2 times ( k= 2) will result in the followingmatrix.

Each value moved 2 positions to the left because k =2

Matrix Compress

The matrix compress operation is adata loss operation. It will compress any n by m matrix mat intoeither a vector (one-dimensional array) of size n in case ofrow-wise reduction or a vector of size m in case of column-wisereduction. The compression function is a simple digit sum. Recallfrom lab 2. ​digit sum of a number, say 152, isjust the ​digits' sum,​ 1+5+2=8. If the​sum of the digits is greaterthan nine, then the process is repeated. For example, the​sum of the digits for 786 is7+8+6=21, and the ​sum of the​digits for 21 is 3 so the ​digitsum of 786 is

3.

For example, the row-wise compressionof the matrix mat in Figure 1 will result in

For example, the column compression of the matrix mat in Figure1 will result in  

Implement a C program toenable the end-user to create, initialize a matrix and functionsneeded to perform the operations listed above. Make sure to use thecoding temple provided

Overall you should have oneprogram containing one main and 10 other functions. The functionsare called based on an interactive user menu in a separatefunction, as shown in the code template. Feel free to create anyadditional functions if needed.

#include

#include

#include

// generate random integer between lower and upper values

int GenerateRandomInt(int lower, int upper){

    int num =(rand()% (upper -lower+1))+lower;

    return num;

}

// use random number to set the values of the matrix

void InitializeMatrix(int row, int column, intmat[][column]){

}

// switch the data of rows with indices src and dst

void SwitchRow(int row, int column, int mat[][column], int src,int dst){

}

// switch the data of columns with indices src and dst

void SwitchColumn(int row, int column, int mat[][column], intsrc, int dst){

}

// enable the user to rotate the data of to the right by kpositions

void RotateMatrixRight(int row, int column, int mat[][column],int src, int dst){

}

// enable the user to rotate the data of to the left by kpositions

void RotateMatrixLeft(int row, int column, int mat[][column],int k){

}

// Use digit sum to compress the matrix by rows

void CompressMatrixByRows(int row, int column, intmat[][column], int k){

}

// Use digit sum to compress the matrix by columns

void CompressMatrixByColumn(int row, int column, intmat[][column], int k){

}

void PrintMatrixData(int row, int column, intmat[][column]){

}

void AppMenu( ){

    int option;

    do{

        printf(\"Select anynumber between 1 and 7\n\");

        printf(\"1 InitializeMatrix Using Random Numbers \n\");

        printf(\"2 Enable TheUser Set the Matrix Values \n\");

        printf(\"3 Switch Dataof Two Rows \n\");

        printf(\"4 Switch Dataof Two Columns \n\");

        printf(\"5 Rotate theMatrix Right by K Times \n\");

        printf(\"6 Rotate theMatrix Left by K Times\n\");

        printf(\"7 CompressMatrix by Rows Using Digit Sum \n\");

        printf(\"8 CompressMatrix by Columns Using Digit Sum\n\");

        printf(\"9 PrintMatrix\n\");

        scanf(\"%d\",&option);

        switch(option){

           case 1:

               break;

           case 2:

               break;

           case 3:

               break;

           case 4:

               break;

           case 5:

               break;

           case 6:

               break;

           case 7:

               break;

           case 8:

               break;

           case 9:

               break;

           default: ;//do nothing

        }

    }while(option > 1 && option <6);

}

int main() {

    // use current time as seed for randomgenerator, should only be called once.

    srand((unsigned int)time(NULL));

    int const max_row = 100;

    int const max_column =100;

    int matrix[max_row][max_column];

    int vector[max_column];

    int row, column;

    printf(\"Enter the number of rows of yourmatrix: \");

    scanf(\"%d\", &row);

    printf(\"Enter the number of columns of yourmatrix: \");

    scanf(\"%d\", &column);

    //call App Menu to interact with the enduser

    AppMenu();

    return 0;

}

Answer & Explanation Solved by verified expert
4.4 Ratings (630 Votes)
use random number to set the values    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students