Программы на C++. Форум разработчиков
Anonymous
Функция Void не печатает элементы матрицы C++
Сообщение
Anonymous » 11 окт 2025, 14:17
Я пытаюсь распечатать элементы матрицы (пример будет ниже). Вот следующий код, написанный на Dev-C++:
Код: Выделить всё
#include
using namespace std;
class Matrix {
private:
int **data;
int rows, columns;
public:
Matrix(int, int);
~Matrix();
void setValue(int, int, int);
void printMatrix() const;
};
Matrix::Matrix(int rows, int columns) {
data = new int*[rows];
for (int i = 0; i < rows; ++i)
data[i] = new int[columns];
}
// setValue method
void Matrix::setValue(int row, int column, int value) {
if (row > 0 && row < rows && column > 0 && column < columns)
data[row][column] = value;
}
// This function doesn't print elements of matrix
void Matrix::printMatrix() const {
for (int i = 0; i < rows; ++i) {
for (int j = 0; j < columns; ++j) {
cout
Подробнее здесь: [url]https://stackoverflow.com/questions/79787964/void-function-doesnt-print-elements-of-matrix-c[/url]
1760181468
Anonymous
Я пытаюсь распечатать элементы матрицы (пример будет ниже). Вот следующий код, написанный на Dev-C++: [code]#include using namespace std; class Matrix { private: int **data; int rows, columns; public: Matrix(int, int); ~Matrix(); void setValue(int, int, int); void printMatrix() const; }; Matrix::Matrix(int rows, int columns) { data = new int*[rows]; for (int i = 0; i < rows; ++i) data[i] = new int[columns]; } // setValue method void Matrix::setValue(int row, int column, int value) { if (row > 0 && row < rows && column > 0 && column < columns) data[row][column] = value; } // This function doesn't print elements of matrix void Matrix::printMatrix() const { for (int i = 0; i < rows; ++i) { for (int j = 0; j < columns; ++j) { cout Подробнее здесь: [url]https://stackoverflow.com/questions/79787964/void-function-doesnt-print-elements-of-matrix-c[/url]