Example #1
0
bool Matriz::permutacao()const{ //CERTO
    int soma=0,p=1;

    for(int linha = 0; linha<quantidadeDeLinhas;linha++){
        for(int coluna = 0;coluna<quantidadeDeColunas;coluna++)
            soma = soma + getElemento(linha,coluna);
        if(soma != 1)
            p=0;
        soma=0;
    }

    soma=0;

    for(int linha = 0; linha<quantidadeDeLinhas;linha++){
        for(int coluna = 0;coluna<quantidadeDeColunas;coluna++){
            soma = soma +getElemento(linha,coluna);
            }
    if(soma != 1)
        p=0;
    soma=0;
    }

    if(p==1)
        return true;
    else
        return false;
}
Example #2
0
bool Matriz::eMatrizDePermutacao()const {
    try {
        int aux=0;
        for(int linha=0; linha<quantidadeDeLinhas; linha++) {
            for(int coluna=0; coluna<quantidadeDeColunas; coluna++) {
                if( this->getElemento(linha,coluna) != 0 && this->getElemento(linha,coluna) !=1 )//verifica se ha apenas 1 e 0
                    return false;
                else
                    aux=getElemento(linha,coluna)+aux;//soma das linhas
            }
            if(aux!=1)return false;//verifica se a soma e 1
            aux=0;
        }

        for(int coluna=0; coluna<quantidadeDeColunas; coluna++) {
            for(int linha=0; linha<quantidadeDeLinhas; linha++) {
                aux=getElemento(linha,coluna)+aux;//somas das colunas
            }
            if(aux!=1)return false;//verifica se a soma e 1
            aux=0;
        }


        return true;

    } catch(int valorErro) {
        throw valorErro;
    }
}
Example #3
0
bool Matriz::matrizIdentidade()const{ //CERTO
    int p = 1;
    for(int i=0;i<getQuantidadeDeLinhas();i++){
            for(int j =0;j<getQuantidadeDeColunas();j++){
                if((i==j) && (getElemento(i,j) != 1))
                   p=0;
                else if((i != j) && (getElemento(i,j) != 0))
                   p=0;
            }
        }
    if(p==1)
        return true;
    else
        return false;
}
Example #4
0
QString Matriz::getMatriz()const{
    QString saida = "";
    for(int l=0; l<  getQuantidadeDeLinhas();l++){
        for(int c=0; c < getQuantidadeDeColunas(); c++){
            saida+= QString::number(getElemento(l,c));
            saida+= " ";
        }
        saida += "\n";
    }
    return saida;
}
Example #5
0
bool Matriz::matrizTriangInferior()const{ //CERTO
    int p=1;
    for (int i=0; i < getQuantidadeDeLinhas(); i++){
        for (int j=(i+1); j < getQuantidadeDeColunas();j++){
            if (getElemento(i,j) != 0)
                p=0;
        }
    }
    if(p==1)
        return true;
    else
        return false;
}
Example #6
0
bool Matriz::matrizTringSuperior()const{ //CERTO
    int p=1;
    for (int i=0; i < getQuantidadeDeLinhas(); i++){
        for (int j=0; (j<i) ;j++){
            if (getElemento(i,j) != 0)
                p=0;
        }
    }
    if(p==1)
        return true;
    else
        return false;
}
Example #7
0
Matriz* Matriz::multiplicarK(int n){ //CERTO
    try{
        Matriz *aux= new Matriz(quantidadeDeLinhas,quantidadeDeColunas);
        for(int linha = 0; linha<quantidadeDeLinhas;linha++)
            for(int coluna = 0;coluna<quantidadeDeColunas;coluna++){
                int valor = getElemento(linha,coluna)*n;
                aux->setElemento(valor,linha,coluna);
            }
        return aux;

    }catch(std::bad_alloc&){
        throw QString("Vai comprar memoria");
    }catch(QString &erro){
        throw QString("Matriz auxiliar nao criada nao podemos adicionar as matrizes");
    }
}