class named Matrix that shall contains private data member
matrix: integer type array of size 3 by 3;
constructor that should have default parameters that can set all elements to 0. Moreover, define a function called setMatrixValues(int matrixArray[3][3]) that can assign values of matrixArray (provided to the function in argument) to the matrix array (data member of the class Matrix) of the class. Along with it, define a function called displayMatrix() that can display all values of the matrix.
class named Matrix that shall contains private data member
matrix: integer type array of size 3 by 3;
constructor that should have default parameters that can set all elements to 0. Moreover,define a function called setMatrixValues(int matrixArray[3][3]) that can assign values of matrixArray (provided to the function in argument) to the matrix array (data member of the class Matrix) of the class. Along with it, define a function called displayMatrix() that can display all values of the matrix.
#include <iostream>
using namespace std;
class Matrix
{
int Array[3][3];
public:
Matrix()
{
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
Array[i][j] = 0;
}
}
}
void setMatrixValues(int matrixArray[3][3])
{
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
Array[i][j] = matrixArray[i][j];
}
}
}
void displayMatrix()
{
cout << "Matrix:\n";
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
cout<<Array[i][j]<<" ";
}
cout << endl;
}
}
};
int main()
{
int matrixArray[3][3];
Matrix x;
cout << "Please, enter values for an array: " << endl;
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
cout << "Please, enter value[" << i << "][" << j << "]:";
cin>>matrixArray[i][j];
}
}
x.setMatrixValues(matrixArray);
x.displayMatrix();
}
Comments
Leave a comment