Код: Выделить всё
class matrix
{
private:
int n,m,i,j;
int **matrica;
public:
matrix ();
~matrix(){};
int get(int ,int);
void print();
int size(int ,int);
};
int matrix::size(int n,int m)
{
cout<<"input the n:";
cin>>n;
cout<<"input the m:";
cin>>m;
return 0;
}
matrix::matrix()
{
matrica=new int*[n];
for ( i = 0; i < n; i++)
matrica[i] = new int[m];
for ( i = 0; i < n; i++)
for ( j = 0; j < m; j++)
matrica[i][j] = rand() % 10;
}
void matrix: :p rint()
{
for( i = 0; i < n; i++)
{
for(j = 0; j < m; j++)
cout<<matrica[i][j]<<' ';
cout<<"\n";
}
}
int matrix::get(int i,int j)
{
if(i>=n||j>=m)
return 0;
cout<<matrica[i][j]<<'\n';
}
int main ()
{
int m,n;
system("cls");
matrix object;
object.size(n,m);
object.print();
int i, j;
cout<<" get (i.j):"<<endl;
cout<<"Enter i: ";
cin>>i;
cout<<"Enter j: ";
cin>>j;
if(object.get(i,j)==0)
cout<<"i or j more or equal than n or m!\n";
system("PAUSE");
return 0;
}