Logo Search packages:      
Sourcecode: kbruch version File versions  Download package

void ExerciseMixedNumbers::showResult (  ) [private]

checks result and shows solution

Definition at line 293 of file ExerciseMixedNumbers.cpp.

References task::get_ratio_n(), m_isMixedTask, m_task, ratio::reduce(), ratio::setRatio(), ResultWidget::setResult(), signalExerciseSolvedCorrect(), and signalExerciseSolvedWrong().

Referenced by slotCheckButtonClicked().

{
    bool wrong = false;

    // update UI while solution is shown
    m_checkButton->setToolTip (i18n ("Click this button to get the next question."));
    m_checkButton->setText (i18n ("N&ext"));
    m_integerEdit->setEnabled (false);
    m_numerEdit->setEnabled (false);
    m_denoEdit->setEnabled (false);
    m_skipButton->setEnabled (false);

    // an empty numerator field is interpreted as 0
    if (m_numerEdit->text().isEmpty()) {
        m_numerEdit->setText ("0");
    }
    int resultNumerator = m_numerEdit->text().toInt();

    // an empty denominator field is interpreted as 1
    if (m_denoEdit->text().isEmpty()) {
        m_denoEdit->setText ("1");
    }
    int resultDenominator = m_denoEdit->text().toInt();
    if (resultDenominator == 0) {
        // don't allow denominator to be 0
        wrong = true;
    }

    // get integer if user had to input it
    int resultInteger = 0;
    if (! m_isMixedTask) {
        resultInteger = m_integerEdit->text().toInt();

        // in mixed notation, numerator must be smaller than denominator
        if (qAbs (resultNumerator) >= qAbs (resultDenominator)) {
            wrong = true;
        }
    }

    // create result ratio, but don't try to reduce it yet
    ratio resultRatio = ratio();
    resultRatio.setRatio (resultInteger, resultNumerator, resultDenominator,
                          false);

    // check for correct solution
    ratio solutionRatio = m_task.get_ratio_n (0);
    if (! (resultRatio == solutionRatio)) {
        wrong = true;
    }

    // wrong solution, try to give some hints what might be wrong
    if (wrong) {
        // emit the signal for wrong
        signalExerciseSolvedWrong();
        m_resultWidget->setAnswerMixed (! m_isMixedTask);
        m_resultWidget->setResult (solutionRatio, 0);

        // check if user entered 0 as denominator
        if (resultDenominator == 0) {
            KMessageBox::information (this, i18n ("You entered 0 as the denominator. This means division by zero, which is not allowed. This question will be counted as not correctly solved."));
        } else {
            // first reduce entered result to identify more problems
            resultRatio.reduce();
            if ( (! m_isMixedTask) && (resultRatio == solutionRatio) &&
                    (qAbs (resultNumerator) >= qAbs (resultDenominator))) {
                // maybe didn't enter mixed number notation
                KMessageBox::information (this, i18n ("You entered the correct result, but not in the mixed number notation. This question will be counted as not correctly solved."));
            } else if (resultRatio == solutionRatio) {
                // maybe the user entered the correct result but not reduced
                KMessageBox::information (this, i18n ("You entered the correct result, but not reduced. This question will be counted as not correctly solved."));
            }
        }
    } else {
        // emit the signal for correct
        signalExerciseSolvedCorrect();
        m_resultWidget->setResult (solutionRatio, 1);
    }

    return;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Generated by  Doxygen 1.6.0   Back to index