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

I cant seem to find a way to figure out this particular Q1 on this CS assigment.

ID: 3732618 • Letter: I

Question

I cant seem to find a way to figure out this particular Q1 on this CS assigment. I coded out the print two dimensional array void function, but I can get it it to compile correctly like what is asked on the assigment. If you need A screen shot of all the code just comment. c++ win32 console application

Q1) //Add a void function called PrintTwoDimArray, which takes as an argument the two
//dimensional array called matrix and prints the values of all its elements.Print the matrix
//elements in a grid(table), with all elements right justified.

==============================================
// ConsoleApplication1.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include
#include
#include
#include
using namespace std;

//Function Prototypes
//====================================
void PrintArray( string, int[], int);
int LargestElementsIndex( int[], int);
int SmallestElementIndex(int[], int);
int RandomNumber(int, int);
void InitializeGenerator(unsigned int);

//====================================
//Constants
//======================
const int MIN_RANDOM_NUMBER = 1;
const int MAX_RANDOM_NUMBER = 100;
const int ARRAY_SIZE = 10;
//=============================
//=================
//THE MAIN FUNCTION
//=================
int main() {
int n;
int row;
int col;
int arrayIndex;
int vector[ARRAY_SIZE]; //A one dimesional array.
int matrix[ARRAY_SIZE][ARRAY_SIZE];// A two dimensional array.
int arr[ARRAY_SIZE][ARRAY_SIZE];
InitializeGenerator(1);
//==============================================================
//Fill the array called vector with randomly generated values.
//==============================================================
n = 0;
while (n < ARRAY_SIZE) {
vector[n] = RandomNumber(MIN_RANDOM_NUMBER, MAX_RANDOM_NUMBER);
n++;
}//while
PrintArray("Vector", vector, ARRAY_SIZE);
arrayIndex = LargestElementsIndex(vector, ARRAY_SIZE);
cout << " The index of the largest element is = " << arrayIndex << endl;
cout << endl;
cout << "Largest element = " << vector[arrayIndex] << endl;
cout << endl;

PrintArray("Vector", vector, ARRAY_SIZE);
arrayIndex = SmallestElementIndex(vector, ARRAY_SIZE);
cout << " The index of the smallest element is = " << arrayIndex << endl;
cout << endl;
cout << "Smallest element = " << vector[arrayIndex] << endl;
cout << endl;
// =================================================================
// Fill the Two-Dimensional array called matrix with integer values
// =================================================================
row = 0;
col = 0;
while (row < ARRAY_SIZE) {
col = 0;
while (col < ARRAY_SIZE) {
matrix[row][col] = row + col;
col++;
}
row++;
}//Outer while
return 0;
}//Function Main
//===============================
// Function LargestElementsIndex
//===============================
int LargestElementsIndex(int arrayData[], int numberOfElements) {
int index;
int maximumIndex;
maximumIndex = 0;
for (index = 1; index < numberOfElements; index++) {
if (arrayData[index] > arrayData[maximumIndex])
maximumIndex = index;
}//for
return maximumIndex;
}//LargestElementIndex
int SmallestElementIndex(int digits[], int size) {
int ind = 0;
for (int i = 0; i < size; ++i) {
if (digits[i] < digits[ind]) {
ind = i;
}
}
int smallest = digits[ind];
//cout << "Smallest element is = " << smallest << endl;
//cout << "it is found at indices ";
for (int i = 0; i < size; ++i) {
if (digits[i] == smallest) {
//cout << i << " ";
}
}
cout << endl;
return ind;
}
void PrintArray(string name, int arrayData[], int numberOfElements) {
int row;
row = 0;
while (row < numberOfElements) {
cout << name + "[" << row << "] = " << arrayData[row] << endl;
row++;
}//while
cout << endl;
}//Function PrintArray
void InitializeGenerator(unsigned int seed) {
srand(seed);
}// Function InitializeGenerator
int RandomNumber(int minNumber, int maxNumber) {
return (minNumber + rand() % (maxNumber - minNumber + 1));
}//Function RandomNumber
void PrintTwoDimArray(int arr[][3], int rows, int cols) {
for (int i = 0;i < rows; ++i) { //irrate through each row  
for (int j = 0; j < cols; ++j) { // irrate through each column
cout << arr[i][j] << " ";
}
cout << endl;
}
}

Explanation / Answer

Given below is the modified code for the question. In main, it calls PrintTwoDimArray() to print the matrix. Let me know if this is not what you wanted.
Please do rate the answer if it was helpful. Thank you


// ConsoleApplication1.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <string>
#include <iostream>
#include <iomanip>
using namespace std;


//====================================
//Constants
//======================
const int MIN_RANDOM_NUMBER = 1;
const int MAX_RANDOM_NUMBER = 100;
const int ARRAY_SIZE = 10;


//Function Prototypes
//====================================
void PrintArray( string, int[], int);
int LargestElementsIndex( int[], int);
int SmallestElementIndex(int[], int);
int RandomNumber(int, int);
void InitializeGenerator(unsigned int);
void PrintTwoDimArray(int arr[][ARRAY_SIZE], int rows, int cols);

//=============================
//=================
//THE MAIN FUNCTION
//=================
int main() {
int n;
int row;
int col;
int arrayIndex;
int vector[ARRAY_SIZE]; //A one dimesional array.
int matrix[ARRAY_SIZE][ARRAY_SIZE];// A two dimensional array.
int arr[ARRAY_SIZE][ARRAY_SIZE];
InitializeGenerator(1);
//==============================================================
//Fill the array called vector with randomly generated values.
//==============================================================
n = 0;
while (n < ARRAY_SIZE) {
vector[n] = RandomNumber(MIN_RANDOM_NUMBER, MAX_RANDOM_NUMBER);
n++;
}//while
PrintArray("Vector", vector, ARRAY_SIZE);
arrayIndex = LargestElementsIndex(vector, ARRAY_SIZE);
cout << " The index of the largest element is = " << arrayIndex << endl;
cout << endl;
cout << "Largest element = " << vector[arrayIndex] << endl;
cout << endl;

PrintArray("Vector", vector, ARRAY_SIZE);
arrayIndex = SmallestElementIndex(vector, ARRAY_SIZE);
cout << " The index of the smallest element is = " << arrayIndex << endl;
cout << endl;
cout << "Smallest element = " << vector[arrayIndex] << endl;
cout << endl;
// =================================================================
// Fill the Two-Dimensional array called matrix with integer values
// =================================================================
row = 0;
col = 0;
while (row < ARRAY_SIZE) {
col = 0;
while (col < ARRAY_SIZE) {
matrix[row][col] = row + col;
col++;
}
row++;
}//Outer while

PrintTwoDimArray(matrix, ARRAY_SIZE, ARRAY_SIZE);
return 0;
}//Function Main
//===============================
// Function LargestElementsIndex
//===============================
int LargestElementsIndex(int arrayData[], int numberOfElements) {
int index;
int maximumIndex;
maximumIndex = 0;
for (index = 1; index < numberOfElements; index++) {
if (arrayData[index] > arrayData[maximumIndex])
maximumIndex = index;
}//for
return maximumIndex;
}//LargestElementIndex
int SmallestElementIndex(int digits[], int size) {
int ind = 0;
for (int i = 0; i < size; ++i) {
if (digits[i] < digits[ind]) {
ind = i;
}
}
int smallest = digits[ind];
//cout << "Smallest element is = " << smallest << endl;
//cout << "it is found at indices ";
for (int i = 0; i < size; ++i) {
if (digits[i] == smallest) {
//cout << i << " ";
}
}
cout << endl;
return ind;
}
void PrintArray(string name, int arrayData[], int numberOfElements) {
int row;
row = 0;
while (row < numberOfElements) {
cout << name + "[" << row << "] = " << arrayData[row] << endl;
row++;
}//while
cout << endl;
}//Function PrintArray
void InitializeGenerator(unsigned int seed) {
srand(seed);
}// Function InitializeGenerator
int RandomNumber(int minNumber, int maxNumber) {
return (minNumber + rand() % (maxNumber - minNumber + 1));
}//Function RandomNumber
void PrintTwoDimArray(int arr[][ARRAY_SIZE], int rows, int cols) {
for (int i = 0;i < rows; ++i) { //irrate through each row
for (int j = 0; j < cols; ++j) { // irrate through each column
cout << setw(5) << arr[i][j];
}
cout << endl;
}
}

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