Complete/Modify the code satisfying the following: (put comments pls) in C++, pls put COMMENTS in the code   1. Create a 10x10 matrix using rand function to fill the said matrix with random numbers 2. Print all the numbers in matrix form 3. Ask the user the following options OPTIONS: A. Total sum, average, median per row B. Total sum, average, median per column C. Display the same matrix but all ODD numbers are replaced with "-" (minus sign) D. Display the same matrix but all EVEn numbers are replaced with "+" (plus sign E. Display the same matrix but all PRIME numbers are replaced with "*" (asterisksign) F. Display the whole matrix with every row in ascending order G. Display the whole matrix with every row in descending order H. Display the whole matrix with every column in ascending order I. Display the whole matrix with every cloumn in descending order J. Generate new set of random numbers Q. Close the program After asking what option to display, Display again the previous numbers entered and the same options. Here's the code: #include #include #include ascendrow(int a[10]) {     int cntr1,cntr2,temp,b[10];     for(cntr1=0;cntr1<10;cntr1++)     {         b[cntr1] = a[cntr1];     }     for(cntr1=0;cntr1<10;cntr1++)     {         for(cntr2=cntr1;cntr2<10;cntr2++)         {             if(b[cntr1]>b[cntr2])             {                 temp = b[cntr1];                 b[cntr1] = b[cntr2];                 b[cntr2] = temp;             }         }     }     for(cntr1=0;cntr1<10;cntr1++)     {         printf("\t%d",b[cntr1]);     } } int matsum(int a[10]) {     int totalsum = 0,cntr1;     for(cntr1=0;cntr1<10;cntr1++)     {         totalsum = totalsum + a[cntr1];     }     return totalsum; } main() {     char rep;     rep = 'y';         int cntr=0,temp;         char option;         int x[10],y[10];          for(cntr=0;cntr<10;cntr++)     {         x[cntr] = rand() % 100;             }          while(rep=='y'||rep =='Y')     {         printf("\n\nGenerated nos are: \n");         for(cntr=0;cntr<10;cntr++)         {         printf("\t%d",x[cntr]);                 }     printf("\n\na: Display the total sum of the array.\n");     printf("b: Display ascending order.\n");     printf("q: Quit program.\n");     printf("--> ");     scanf("%s",&option);          switch(option)     {         case 'a':             temp = matsum(x);             printf("The total sum of the array is %d.\n",temp);             break;         case 'b':             printf("Ascending order\n");             ascendrow(x);             break;         case 'q':             rep = 'q';             printf("THANKS! BYE! :D");             break;                     default:             printf("Please choose from options a-b.\n");             break;     }     } }

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Complete/Modify the code satisfying the following: (put comments pls)

in C++, pls put COMMENTS in the code

 

1. Create a 10x10 matrix using rand function to fill the said matrix with random numbers

2. Print all the numbers in matrix form

3. Ask the user the following options

OPTIONS:

A. Total sum, average, median per row

B. Total sum, average, median per column

C. Display the same matrix but all ODD numbers are replaced with "-" (minus sign)

D. Display the same matrix but all EVEn numbers are replaced with "+" (plus sign

E. Display the same matrix but all PRIME numbers are replaced with "*" (asterisksign)

F. Display the whole matrix with every row in ascending order

G. Display the whole matrix with every row in descending order

H. Display the whole matrix with every column in ascending order

I. Display the whole matrix with every cloumn in descending order

J. Generate new set of random numbers

Q. Close the program

After asking what option to display, Display again the previous numbers entered and the same options.

Here's the code:

#include<stdio.h>
#include<math.h>
#include<stdlib.h>

ascendrow(int a[10])
{
    int cntr1,cntr2,temp,b[10];
    for(cntr1=0;cntr1<10;cntr1++)
    {
        b[cntr1] = a[cntr1];
    }
    for(cntr1=0;cntr1<10;cntr1++)
    {
        for(cntr2=cntr1;cntr2<10;cntr2++)
        {
            if(b[cntr1]>b[cntr2])
            {
                temp = b[cntr1];
                b[cntr1] = b[cntr2];
                b[cntr2] = temp;
            }
        }
    }
    for(cntr1=0;cntr1<10;cntr1++)
    {
        printf("\t%d",b[cntr1]);
    }
}

int matsum(int a[10])
{
    int totalsum = 0,cntr1;
    for(cntr1=0;cntr1<10;cntr1++)
    {
        totalsum = totalsum + a[cntr1];
    }
    return totalsum;
}


main()
{
    char rep;
    rep = 'y';

        int cntr=0,temp;
        char option;
        int x[10],y[10];
    
    for(cntr=0;cntr<10;cntr++)
    {
        x[cntr] = rand() % 100;        
    }
    
    while(rep=='y'||rep =='Y')
    {
        printf("\n\nGenerated nos are: \n");
        for(cntr=0;cntr<10;cntr++)
        {
        printf("\t%d",x[cntr]);        
        }
    printf("\n\na: Display the total sum of the array.\n");
    printf("b: Display ascending order.\n");
    printf("q: Quit program.\n");
    printf("--> ");
    scanf("%s",&option);
    
    switch(option)
    {
        case 'a':
            temp = matsum(x);
            printf("The total sum of the array is %d.\n",temp);
            break;
        case 'b':
            printf("Ascending order\n");
            ascendrow(x);
            break;
        case 'q':
            rep = 'q';
            printf("THANKS! BYE! :D");
            break;            
        default:
            printf("Please choose from options a-b.\n");
            break;
    }
    }
}

Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY