Help with assignment in OOP Class

I have an assignment that I am having problems with. I don't use C++ on a daily basis at work but needed to take the class for school and I am having trouble with this assignment. Here is the question:
"C++ Please A 2-D array has these 20 elements: 3 33 333 3333 5 55 555 5555 1 11 111 1111 4 44 444 4444 2 22 222 2222 Write an exchange maximum program to do the following: a. Sort the array so that it will look like this: 5 55 555 5555 4 44 444 4444 3 33 333 3333 2 22 222 2222 1 11 111 1111 b. Sort the array so that it will look like this: 1111 111 11 1 2222 222 22 2 3333 333 33 3 4444 444 44 4 5555 555 55 5"

Here is the code that I have done but I get 0's to return and when I enter the elements for the array they all come back as 3's. Thanks for any help.

#include<iostream>
using namespace std;
class matrix
{
private:
int mat[5][4];
public:
matrix();
void create();
void display();
void sorthigh(matrix &m1);
void sortlow(matrix &m2);
};

matrix::matrix()
{
for(int i=0;i<5;i++)
{
for(int j=0;j<4;j++)
mat[i][j]=0;
}
}
void matrix::create()
{
int n;
for(int i=0;i<5;i++)
{
for(int j=0;j<4;j++)
{
cin>>n;
mat[i][j]=n;
}
}
}
void matrix::display()
{
for(int i=0;i<5;i++)
{
for(int j=0;j<4;j++)
cout<<mat[i][j]<<" ";
cout<<endl;
}
}
void matrix::sorthigh(matrix &m1)
{
int high,i,j,a,row;
int end=5;
int temp1[4],temp2[4];

for (i=end-1;i>=0;i--)
{
high = mat[i][0];
for (j=i;j>=0;j--)
{
if (high >= mat[j][0])
{
high = mat[j][0];
row =j;
}
for (a=0;a<4;a++)
{
temp1[a] = mat[i][a];
temp2[a] = mat[row][a];
mat[i][a] = temp2[a];
mat[row][a] = temp1[a];
}
}
}
}
void matrix::sortlow(matrix &m1)
{
int low,i,j,a,row;
int end=5;
int temp1[4],temp2[4];

for (i=end-1;i>=0;i--)
{
low = mat[i][0];
for (j=i;j>=0;j--)
{
if (low <= mat[j][0])
{
low = mat[j][0];
row =j;
}
for (a=0;a<4;a++)
{
temp1[a] = mat[i][a];
temp2[a] = mat[row][a];
mat[i][a] = temp2[a];
mat[row][a] = temp1[a];
}
}
}
}
void main()
{
matrix mat1;
cout<<"\n Enter elements:\n";
mat1.create();
cout<<"\nMatrix Before sorting:\n";
mat1.display();

matrix mat2;
mat2.sortlow(mat1);
cout<<"\nSort Matrix in first form:\n";
mat2.display();

matrix mat3;
mat3.sorthigh(mat1);
cout<<"\nSort Matrix in second form:\n";
mat3.display();
system ("pause");
}




Topic archived. No new replies allowed.