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

I am writing a program that is going to require a list of coordinates to plot a

ID: 3656897 • Letter: I

Question

I am writing a program that is going to require a list of coordinates to plot a graph. Your job is to create a program that will generate that list of coordinates. You are also going to have to write code that will test your functionality. Specifics: Write a function called fill2D that will fill a 20 x 20 2d array with random numbers in the range of 1 to 100. Write a function called print2D that will print a 20 x 20 2D array. Write a function called createCoords that will search the 2D array looking for any value that is evenly divisible by 3. Once you have found a number you should log the row, column location. This means when your function finishes it should produce a list of coordinates that I can use to plot my graph. This function must also return the number of of coordinates that are divisible by 3 so that I know how many points there are to plot. I am not particular as to how the coordinates are returned back as long as I get a list of the row, column locations. So, I will leave it to you to work out a mechanism for returning the values. Some possibilities are: String Array 2D Array To test that you have logged the coordinates create another function called fillLocations that will fill the locations in the array you have logged with -1. So, your program should flow in this order fill2DArray print2DArray createCoords fillLocations print2DArray What not to do Using any of the following will drop your grade for this assignment by 70% global variables cin in any funciton other than main cout in any funciton other than main and print2DArray goto statements

Explanation / Answer

please rate - thanks

#include <iostream>
#include <ctime>
#include<iomanip>
using namespace std;
void fill2D(int[][20]);
void print2D(int[][20]);
void createCoords(int[][20],int[][2],int&);
void fillLocations(int[][20],int[][2],int );
int main()
{int a[20][20],numcoords=0,coords[400][2];
srand(time(0));
fill2D(a);
cout<<"After random fill ";
print2D(a);
createCoords(a,coords,numcoords);
fillLocations(a,coords,numcoords);
cout<<"After -1 filled ";
print2D(a);
system("pause");
return 0;
}
void fill2D(int a[][20])
{int i,j;
for(i=0;i<20;i++)
    for(j=0;j<20;j++)
        a[i][j]=rand()%100+1;
}
void print2D(int a[][20])
{int i,j;
for(i=0;i<20;i++)
    {for(j=0;j<20;j++)
        {cout<<setw(4)<<a[i][j];
        }
     cout<<endl;
     }
}
void createCoords(int a[][20], int coords[][2],int& num)
{int i,j;
for(i=0;i<20;i++)
     for(j=0;j<20;j++)
        if(a[i][j]%3==0)
             {coords[num][0]=i;
             coords[num][1]=j;
             num++;
             }
}
void fillLocations(int a[][20],int coords[][2],int num)
{int i;
for(i=0;i<num;i++)
    a[coords[i][0]][coords[i][1]]=-1;
}

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