Professional Documents
Culture Documents
ЛР-1 Bodnar Danylo ОІ-16
ЛР-1 Bodnar Danylo ОІ-16
Звіт
до лабораторної роботи № 1
з дисципліни
Об’єктно-орієнтоване програмування
на тему:
“Класи та об’єкти C++ ”
Боднар Данило
Прийняла:
Ткачук К. I.
Львів – 2023
Лабораторна робота №1
Послідовність роботи:
Індивідуальне завдання:
class Matrix
{
private:
int rows;
int columns;
int **twoDimensionalArray;
public:
Matrix(int r, int c)
{
rows = r;
columns = c;
twoDimensionalArray = new int *[rows];
return resultMatrix;
}
Matrix operator-(const Matrix &secondMatrix)
{
if (rows != secondMatrix.rows || columns != secondMatrix.columns)
{
throw invalid_argument("Matrices must be of the same size.");
}
return resultMatrix;
}
Matrix operator*(const Matrix &secondMatrix)
{
if (columns != secondMatrix.rows)
{
throw invalid_argument("Matrices must be of the same size.");
}
return resultMatrix;
}
~Matrix()
{
for (int i = 0; i < rows; i++)
{
delete[] twoDimensionalArray[i];
}
delete[] twoDimensionalArray;
}
};
int main()
{
Matrix matrix1(2, 3), matrix2(3, 4);
cout << "Перша матриця" << endl;
matrix1.printMatrix();
cout << "Друга матриця" << endl;
matrix2.printMatrix();
return 0;
}
Результат роботи:
Висновок