Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

can any one help me with this code? the program needs to be well modularized wit

ID: 652171 • Letter: C

Question

can any one help me with this code?

the program needs to be well modularized with functions, including main, with 10 or less lines of code. This means you will have a function that checks if the rows and cols are valid, non-zero integers, bool is_valid_diminsions(char *m, char *n), and another function that creates the matrix of structs given the m x n dimensions, mult_div_values** create_table(int m, int n). In addition, you need to have functions that set the multiplication and division values, as well as delete your matrix from the heap:

void set_mult_values(mult_div_values **table, int m, int n) void set_div_values(mult_div_values **table, int m, int n) void delete_table(mult_div_values ***table, int m)

Then, call functions to print the tables. Example: ./prog 5 t You did not input a valid column.
Please enter an integer greater than 0 for a column:
5 Multiplication Table:

1 2 3 4 5
2 4 6 8 10
3 6 9 12 15
4 8 12 16 20
5 10 15 20 25

Division Table:
1.00   0.50 0.33 .025   0.20

2.00 1.00 0.67 0.50 0.40

3.00 1.50 1.00 0.75 0.60

4.00 2.00 1.33 1.00 0.80

5.00 2.50 1.67 1.25 1.00

Would you like to see a different size matrix (0-no, 1-yes)? 0

begin making an interface file that holds all this information for us.

Create a mult_div.h interface file that will contain all the function and struct declaration information we need:

struct mult_div_values { int mult;

float div; };

bool is_valid_diminsions(char *m, char *n); mult_div_values** create_table(int, int);
void set_mult_values(mult_div_values **, int, int); void set_div_values(mult_div_values **, int, int); void delete_table(mult_div_values ***table, int m);

Now, compile your program normally: g++ mult_div.cpp o mult_div

Lets take this a step further, and keep only your function definitions in this implementation file, i.e. mult_div.cpp, and put your main function in a separate implementation file called prog.cpp. Your prog.cpp file will have to include the mult_div.h file too.

After creating this file, then you can include it into your implementation, .cpp file, and remove these prototypes and struct definition from your file.

#include ./mult_div.h

Explanation / Answer

struct mult_div_values
{ int mult;
float div;
};

bool is_valid_diminsions(char *m, char *n){
   if(!isdigit(m)||m==0){
                cout<<"Enter a digit greater than zero for # no. of rows: ";
                cin>>m;
                is_valid_dimensions(m,n);
                }
        else if(!isdigit(n)||n==0){
                cout<<"Enter a digit greater than zero for # no. of rows: ";
                cin>>n;
                is_valid_dimensions(m,n);
                }
        else return true;
}

mult_div_values** create_table_twoD(int m, int n)
{
    mult_div_values **retTbl;
    retTbl=new mult_div_values*[m];             //allocate the memory for m no. of rows
    for (int i= 0;i<m;i++)
        retTbl[i]=new mult_div_values[n];    //allocate the memory for n no. of columns

    return retTable;
}

void set_mult_values(mult_div_values **table, int m, int n)
{
    for(int row=0;row<m;row ++)
    {
        for(int col=0;col<n;col++)
        {
            table[row][col].mult=(row+1)*(col+1);   // it is necessary to add one, since
        }                                                   // array index begins at 0
    }
    cout<<"Multiplication Table: ";
    for (int row=0;row<m;row++) {
             for (int col=0;col<n;col++)
                    cout<<table[row][col].mult<<" ";
             cout<<" ";
    }
}

void set_div_values(mult_div_values **table, int m, int n)
{
    for(int row=0;row<m;row++)
    {
        for(int col=0;col<n;col++)
        {
            table[row][col].div=(float(row+1))/(float(col+1));
        }
    }
    cout << "Division Array: ";
    for (int row=0;row<m;row++) {
            for (int col=0;col<n;col++)
                    cout<<setprecision(5)<<table[row][col].div << " ";
            cout<<" ";
    }
}

void delete_table(mult_div_values*** table, int m) {
        for (int i=0;i<m;i++) {
                cout<<"OK ";
                delete []table[i];
        }
        delete []table;
}

int main(const int argc, char **argv)
{
    bool doAgain = 1;
        while (doAgain) {
            while (!is_valid_dimensions(argv[1],argv[2])) {
                    cin >> argv[1];
                    cout << "Re enter the number of cols: ";
                    cin >> argv[2];
            }
            int rows=atoi(argv[1]),cols=atoi(argv[2]);
            mult_div_values** table = create_table(rows, cols);
            set_mult_values(table,rows,cols);
            set_div_values(table,rows,cols);
            delete_table(&table,rows);
            cout<<"Do you want to go again? (0=no,1=yes) ";
            cin>>doAgain;
        argv[1][0]= q';argv[2][0]='m';
    }
        return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote