How do I create a function that fills the original array sent to the function, rather than the one that is exclusively in the function? In my code so far I do it manually, but I would like to create a function that stores values and sorts the array. I'm not sure how to apply this to the original array rather than the one that is defined in the function parameters.
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <string>
using namespace std;
class Functions
{
private:
int input{};
int numRows{};
int numColumns{};
int holder{};
public:
void rndArrayMaxNumber (int x, int y)
{
int tempArray [x][y]{};
srand(time(0));
for (int j=0;j<x;j++)
{
for (int i=0;i<y;i++)
{
tempArray[j][i]= (rand()%99)+1;
}
}
for (int j=0;j<x;j++)
{
for (int i=0;i<x-1;i++)
{
for (int k=0;k<y-1;k++)
{
if (tempArray[i][k] < tempArray[i][k+1])
{
holder=tempArray[i][k];
tempArray[i][k]=tempArray[i][k+1];
tempArray[i][k+1]=holder;
}
}
}
}
for (int j=0;j<y;j++)
{
for (int i=0;i<y-1;i++)
{
for (int k=0;k<x-1;k++)
{
if (tempArray[k][i] < tempArray[k+1][i])
{
holder=tempArray[k][i];
tempArray[k][i]=tempArray[k+1][i];
tempArray[k+1][i]=holder;
}
}
}
}
for (int i=0;i<y;i++)
{
for (int k=0;k<x;k++)
{
cout << tempArray[i][k] << "\t";
}
cout << endl;
}
cout << endl << "The greatest number is " << tempArray[0][0];
}
void arrayChoice ()
{
cout << "Enter the number of rows: ";
cin >> numRows;
cout << "Enter the number of columns: ";
cin >> numColumns;
cout << endl;
}
void menu ()
{
while (input!=7)
{
cout << "1. 2D array random numbers and show highest number" << endl;
cout << "2. Exit" << endl << endl;
cout << "Enter the number of the menu option you want to proceed with: ";
cin >> input;
cout << endl;
switch (input)
{
case 1:
arrayChoice();
rndArrayMaxNumber(numRows, numColumns);
cout << endl << endl;
break;
}
}
}
};
int main()
{
Functions program;
program.menu();
return 0;
}