Review


Problem 1
Write a program called Matrices to compute the determinant of matrix using recursion.
Escriba un programa llamado Matrices para calcular el determinante de una matriz usando recursión.

Matrices1

Matrices2

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

class Matrices: public Win::Dialog
{
public:
     Matrices()
     {
     }
     ~Matrices()
     {
     }
     double Determinant(MATRIX& input);
     void ReduceMatriz(const MATRIX& input, MATRIX& output, int columnIndex);
protected:
     ...
};

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

void Matrices::btCalcular_Click(Win::Event& e)
{
     MATRIX input;
     Sys::Convert::ToMatrix(tbxInput.Text, input);
     tbxDeterminante.DoubleValue = Determinant(input);     
}

double Matrices::Determinant(MATRIX& input)
{
     const int rowCount = input.size();
     const int colCount = (rowCount == 0) ? 0 : input[0].size();
     if (rowCount != colCount) throw L"The number of rows must be equal to the number of columns";
     if (rowCount == 0) return 0.0;
     if (rowCount == 1) return input[0][0];
     if (rowCount == 2) return input[0][0]*input[1][1]-input[1][0]*input[0][1];
     //___________________________We get here when matrix size is 3x3, 4x4, 5x5, ...
     ...
}

// Returns an identical matrix to the input: without the first row and without the specified column
// Regresa una matrix identica a la de entrada: sin el primer renglon y sin la columna especificada
void Matrices::ReduceMatriz(const MATRIX& input, MATRIX& output, int columnIndex)
{
     ...
}

© Copyright 2000-2019 Wintempla selo. All Rights Reserved. Sep 05 2019. Home