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

void ExerciseMixedNumbers::createTask (  ) [private]

creates a new task

Definition at line 208 of file ExerciseMixedNumbers.cpp.

References task::add_ratio(), ratio::denominator(), m_task, and ratio::setRatio().

Referenced by ExerciseMixedNumbers(), and nextTask().

{
    // generate ratio; constraints:
    // - reduced
    // - numerator is larger than denominator
    // - denominator is not 1
    ratio tmpRatio = ratio();
    int numerator = 0;
    int denominator = 1;
    do {
        // numerator should be between 1..15
        numerator = int ( (double (rand()) / RAND_MAX) * 15 + 1);

        // denominator should be between 1..(numerator-1)
        denominator = int ( (double (rand()) / RAND_MAX) * numerator);

        // eventually make ratio negative
        if (double (rand()) / RAND_MAX >= 0.5) {
            numerator *= -1;
        }
        tmpRatio.setRatio (numerator, denominator);
    } while (tmpRatio.denominator() == 1);

    // store new task
    m_task = task();
    m_task.add_ratio (tmpRatio);

    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