/
Messus
/
t_ascii
Обзор
Документация
Войти
/
Messus
/
t_ascii
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
class_matrix.cpp
70 строк
1 KB
Messus
upload files
27 фев 2025, 15:08
27 фев 2025, 15:08
36a829f
Код
Авторство
О чём код?
#include <iostream> #include <math.h> //создаем матрицу using namespace std; class matrix { private: double *m; size_t width, height; //??? public: matrix(size_t w, size_t h); matrix(const matrix& ml); matrix& operator = (matrix & ml); double get_val (size_t i, size_t j); void set_val(size_t i, size_t j, double val); ~matrix(); }; matrix::matrix(size_t w, size_t h) { m = new double [w*h]; width = w; height = h; } matrix::matrix(const matrix& ml) { width = ml.width; height = ml.height; int size = width*height; m = new double [size]; for (int i=0; i<size; i++) m[i]=ml.m[i]; } matrix& matrix::operator = (matrix& ml) { int size = ml.width*ml.height; if (size > width*height) size = width*height; m = new double [size]; for (int i=0; i<size; i++) m[i] = ml.m[i]; return *this; } matrix::~matrix() { delete[] m; } double matrix::get_val(size_t i, size_t j) { return m[i*width+j]; } void matrix::set_val(size_t i, size_t j, double val) { if ((i<width)&&(j<height)) m[i*width+j]=val; } int main() { matrix a(2,2); a.set_val(0,0,100); matrix b = a; b.set_val(0,0,200); cout << "a[0,0] = " << a.get_val(0,0) << "; " << "b[0,0] = " << b.get_val(0,0) << endl; }