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

I need help printing an array that has been returned from a function (see below)

ID: 3567168 • Letter: I

Question

I need help printing an array that has been returned from a function (see below).

#include <iostream>

#include <ctime>

using namespace std;

const int maxCol = 3;

const int maxRow = 3;

void fill2D(int array[][maxCol], int maxRow);

void print2D(int array[][maxCol], int maxRow);

void createCoords(int array[][maxCol], int maxRow, int table[][2], int &count);

void fillLocations(int array[][maxCol], int maxRow, int table[][2], int count);

int main()

{

   srand((unsigned int)time(0));

   int grid[maxRow][maxCol];

   int modTable[maxRow*maxCol][2];

   int totalPoints = 0;

   fill2D(grid, maxRow);

   print2D(grid, maxRow);

   createCoords(grid, maxRow, modTable, totalPoints);

   cout << "There were " << totalPoints << " numbers that were evenly divisible by 3. The coordinate table follows below." << endl;

/*this is where i need help.

   I need to get modTable to cout something like

   0,2

   1,1

2,0

   (the coordinate where the number % 3 == 0)

   any ideas?*/

   fillLocations(grid, maxRow, modTable, totalPoints);

   print2D(grid, maxRow);

   return 0;

}

void fill2D(int array[][maxCol], int maxRow)

{

   for (int row = 0; row < maxRow; row++)

   {

      for (int col = 0; col < maxCol; col++)

      {

         array[row][col] = rand() % 100 + 1;

      }

   }

}

void print2D(int array[][maxCol], int maxRow)

{

   for (int row = 0; row < maxRow; row++)

   {

      for (int col = 0; col < maxCol; col++)

      {

         cout << array[row][col] << " ";

      }

      cout << endl;

   }

}

void createCoords(int array[][maxCol], int maxRow, int table[][2], int &count)

{

   for (int row = 0; row < maxRow; row++)

   {

      for (int col = 0; col < maxCol; col++)

      {

         if (array[row][col] % 3 == 0)

         {

            table[count][0] = row;

            table[count][1] = col;

            count++;

         }

      }

   }

}

void fillLocations(int array[][maxCol], int maxRow, int table[][2], int count)

{

   for (int location = 0; location < count; location++)

   {

      array[table[location][0]][table[location][1]] = -1;

   }

}

Explanation / Answer

for (int i = 0; i < totalPoints; i++)

      {

cout<<" ";

cout<<modTable[i][0]<<","<<modTable[i][1];

      }

cout<<" ";

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