Answer to Question #323888 in C++ for khan

Question #323888

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.


1
Expert's answer
2022-04-05T09:30:16-0400
#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();
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS