how to transform a program into a call by reference

Hi, last time we had a homework where we should create 3 functions, one that fills an array (2d) randomly, the other one where we sorted diagonally the array and finally the third one where we print it out. This time i have to change the type of the program to a call by reference using pointers and addresses. here's my code, can somebody help me fix the errors ?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <iomanip>
using namespace std;

const int M=6;
int c,tmp,x;

void FillTheArrayRandomly (int[M][M]);
void Print (int[M][M]);
void SortDiagonally (int[M][M]);
int *Arr[M][M];

int main()
{
	int Array[M][M];
	{for (int i=0; i<M ; i++)
		for (int j=0 ; j<M; j++)
			*Arr[M][M]=&Array[M][M];
	srand(time(0));
	FillTheArrayRandomly(Array);
	cout<<"Randomly chosen numbers in the array"<<endl;
	Print (Array);

	SortDiagonally (Array);
	Print (Array);

	return 0;
	}}

void FillTheArrayRandomly(int Array[M][M])
{
	
	for(int i=0;i<M;i++)
	{
		for(int j=0 ; j<M ;j++)
		{
			*(Arr[i]+j)=(rand()%955) + 44;
		}
	}
}

void Print(int Array[M][M])
{
	for(int i=0 ; i<M ;i++)
	{
		for(int j=0 ; j<M ;j++)
		{
			cout<<setw(13)<< *(Arr[i]+j);
		}
		cout<<'\n';
	}
}

void SortDiagonally(int Array[M][M])
{
	int W [M*M];
	int k=0;
	int tmp1=0;
	int tmp2=0;
	int x=0;
	int n=0;

	//copy to array W
	for (int i= 0; i<M ; i++){
		for (int j = 0; j<M; j++)
		{
			W[k] = *(Arr[i]+j);
			k++;
		}
	}

	//sort array W
	bool swapped=true;
	while(swapped){
		swapped=false;
		for (int o=1; o< M*M; o++){
			if ( W[o-1] > W[o]) {
				tmp1 = W[o-1];
				W[o-1] = W[o];
				W[o]= tmp1;
				swapped=true;
			}
		}
	}

	//copy sorted data back to array1
	k=0;
	for (int col=0; col<M; col++)
		for (int row=0; row<=col; row++)
			Array[row][col-row] = W[k++];


	for(c=M-1;c>-M;c--)
	{tmp=M-abs(c)-1;
	x=tmp;
	while(x>=0){
		if(c>=0){
			cout<<Array[x][tmp-x]<<", ";
		}
		else{
			cout<<Array[M-(tmp-x)-1][(M-1)-x]<<", ";
		}
		--x;
	}
	cout<<"\n";
	}
}
Can you please post the errors?
Error 1 error C2440: '=' : cannot convert from 'int *' to 'int' c:\users\sergegharib\documents\visual studio 2012\projects\consoleapplication26\consoleapplication26\source.cpp 20 1 ConsoleApplication26

4 IntelliSense: a value of type "int *" cannot be assigned to an entity of type "int" c:\Users\SergeGharib\Documents\Visual Studio 2012\Projects\ConsoleApplication26\ConsoleApplication26\Source.cpp 20 14 ConsoleApplication26

Here:
1
2
3
4
int Array[M][M];
	{for (int i=0; i<M ; i++)
		for (int j=0 ; j<M; j++)
			*Arr[M][M]=&Array[M][M]


No point in adding a reference operator.

1
2
3
4
int Array[M][M];
	{for (int i=0; i<M ; i++)
		for (int j=0 ; j<M; j++)
			*Arr[M][M]=Array[M][M]


--------------------------

You will get many runtime errors with this code, as you're assigning undefined values to variables. I think it's time to redesign it from scratch.
Topic archived. No new replies allowed.