Review


Problem 1
Write a program called MatrixSum to compute the summation of the elements of a matrix. Do not forget to activate the "Want Return" property so that the textbox accepts the "Return" key.
Escriba un programa llamado MatrixSum para calcular la suma de los elementos de una matriz. No se olvide de activar la propiedad de "Want Return" de tal forma que la caja de texto acepte la tecla de "Return".

MatrixSum

MatrixSum.cpp
void MatrixSum::Window_Open(Win::Event& e)
{
#ifdef _DEBUG
     tbxInput.Text = L"1, 2, 3\r\n4, 5, 6\r\n7, 8, 9";
#endif
}

void MatrixSum::btCalculate_Click(Win::Event& e)
{
     MATRIX input;
     Sys::Convert::ToMatrix(tbxInput.Text, input);
     const int rows = input.size();
     const int cols = (rows == 0) ? 0 : input[0].size();
     int i, j;
     double sum = 0.0;
     //________________________________ Method 1
     for(i = 0; i < rows; i++)
     {
          for(j = 0; j < cols; j++)
          {
               sum += input[i][j];
          }
     }
     //________________________________ Method 2
     //for(i = 0; i < rows; i++) sum += input[i].sum();

     tbxResult.DoubleValue = sum;
}

Problem 2
Write a program called Matrix to find the minimum and maximum value in a matrix indicating the position of these; remember that the index of the first row is zero and that the first column from left to right is the column zero.
Escriba un programa llamado Matrix que encuentre el mínimo y máximo en una matriz indicando donde están éstos; recuerde que el primer renglón es el cero y la primera columna de izquierda a derecha es la cero.

Matrix

Matrix.cpp
void Matrix::Window_Open(Win::Event& e)
{
}

void Matrix::btCalculate_Click(Win::Event& e)
{
     MATRIX matrix;
     Sys::Convert::ToMatrix(tbxInput.Text, matrix);

     const int rows = matrix.size();
     const int cols = (rows == 0) ? 0 : matrix[0].size();
     double minimum = matrix[0][0];
     double maximum = matrix[0][0];
     ...
}

Problem 3
Write a program called MatOper to add and subtract two matrices. Both matrices must be of the same size.
Escriba un programa llamado MatOper para sumar y restar dos matrices. Ambas matrices deben ser del mismo tamaño.

MatOper1

MatOper2

MatOper.h
#pragma once //______________________________________ MatOper.h
#include "resource.h"

class MatOper: public Win::Dialog
{
public:
     MatOper()
     {
     }
     ~MatOper()
     {
     }
     void Add(const MATRIX& inputA, const MATRIX& inputB, MATRIX& output);
     void Subtract(const MATRIX& inputA, const MATRIX& inputB, MATRIX& output);
protected:
     ...
};

MatOper.cpp
void MatOper::Window_Open(Win::Event& e)
{
}

void MatOper::btEqual_Click(Win::Event& e)
{
}

void MatOper::Add(const MATRIX& inputA, const MATRIX& inputB, MATRIX& output)
{
     ...
     if (rowsA != rowsB || colsA != colsB )
     {
          tbxA.ShowBalloonTip(L"MatOper", L"Both matrices must be of the same size", TTI_ERROR);
          return;
     }

     int i, j;
     //___________________________________ Create the output matrix
     output.resize(rowsA);
     for(i = 0; i < rowsA; i++) output[i].resize(colsA);
     //___________________________________ Add the matrices
     ...
}

void MatOper::Subtract(const MATRIX& inputA, const MATRIX& inputB, MATRIX& output)
{
}

Problem 4
Write a program called MatrixProducto to compute the product between two matrices. Remember, that the number of columns of the first matrix must be equal to the number of rows of the second one as shown.
Implemente un programa llamado MatrizProducto para calcular el producto de dos matrices como se muestra. Recuerde que el número de columnas de la primera matriz debe ser igual al número de renglones de la segunda como se muestra.

MatrixProduct

MatrixProduct1

MatrixProduct2

MatrixProduct.h
#pragma once //______________________________________ MatrizProducto.h
#include "resource.h"

class MatrizProducto: public Win::Dialog
{
public:
     MatrizProducto()
     {
     }
     ~MatrizProducto()
     {
     }
     void Product(const MATRIX& inputA, const MATRIX& inputB, MATRIX& output);
protected:
     ...
};

MatrixProduct.cpp
void MatrizProducto::Window_Open(Win::Event& e)
{
}

void MatrizProducto::btCalculate_Click(Win::Event& e)
{
     MATRIX a;
     Sys::Convert::ToMatrix(tbxA.Text, a);
     //
     MATRIX b;
     Sys::Convert::ToMatrix(tbxB.Text, b);
     //
     MATRIX result;
     Product(a, b, result);
     //
     wstring text;
     tbxResult.Text = Sys::Convert::ToString(result, text);
}

void MatrizProducto::Product(const MATRIX& inputA, const MATRIX& inputB, MATRIX& output)
{
     ...     
     int i, j, k;
     //___________________________________ Create the output matrix
     output.resize(rowsOutput);
     for(i = 0; i < rowsOutput; i++) output[i].resize(colsOutput);
     //___________________________________ Compute the product
     ...
}



© Copyright 2000-2021 Wintempla selo. All Rights Reserved. Jul 22 2021. Home