Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Education
KBruch
Commits
a7eda770
Commit
a7eda770
authored
Nov 04, 2022
by
Tobias Fella
Browse files
Port to Qt6
parent
e111f222
Changes
8
Hide whitespace changes
Inline
Side-by-side
src/ExerciseCompare.cpp
View file @
a7eda770
...
...
@@ -14,6 +14,7 @@
/* these includes are needed for Qt support */
#include
<QApplication>
#include
<QPushButton>
#include
<QRandomGenerator>
#ifdef DEBUG
#include
<QDebug>
...
...
@@ -190,12 +191,12 @@ void ExerciseCompare::update()
void
ExerciseCompare
::
createTask
()
{
// generate the first ratio
m_firstRatio
=
Ratio
(
int
((
double
(
qrand
())
/
RAND_MAX
)
*
10
+
1
)
,
int
((
double
(
qrand
())
/
RAND_MAX
)
*
10
+
1
)
)
;
m_firstRatio
=
Ratio
(
QRandomGenerator
::
global
()
->
bounded
(
10
)
+
1
,
QRandomGenerator
::
global
()
->
bounded
(
10
)
+
1
);
// now the second ratio, but make sure, the second ratio is different from
// the first one
do
{
m_secondRatio
=
Ratio
(
int
((
double
(
qrand
())
/
RAND_MAX
)
*
10
+
1
)
,
int
((
double
(
qrand
())
/
RAND_MAX
)
*
10
+
1
)
)
;
m_secondRatio
=
Ratio
(
QRandomGenerator
::
global
()
->
bounded
(
10
)
+
1
,
QRandomGenerator
::
global
()
->
bounded
(
10
)
+
1
);
}
while
(
m_firstRatio
==
m_secondRatio
);
return
;
...
...
src/ExerciseConvert.cpp
View file @
a7eda770
...
...
@@ -19,6 +19,7 @@
#include
<QLocale>
#include
<QPushButton>
#include
<QFrame>
#include
<QRandomGenerator>
#ifdef DEBUG
#include
<QDebug>
...
...
@@ -196,7 +197,7 @@ void ExerciseConvert::createTask()
{
// the tasks are hardcoded here; there are some algorithms to convert
// rational numbers to fractions, but it is not worth the effort here
switch
(
int
((
double
(
qrand
())
/
RAND_MAX
)
*
19
))
{
switch
(
QRandomGenerator
::
global
()
->
bounded
(
19
))
{
case
0
:
m_number
=
QLocale
().
toString
(
0.5
,
'f'
,
1
);
m_periodStart
=
2
;
m_periodLength
=
0
;
...
...
src/ExerciseFactorize.cpp
View file @
a7eda770
...
...
@@ -16,6 +16,7 @@
#include
<QGridLayout>
#include
<QLabel>
#include
<QPushButton>
#include
<QRandomGenerator>
#ifdef DEBUG
#include
<QDebug>
...
...
@@ -317,7 +318,7 @@ void ExerciseFactorize::createTask()
PrimeNumber
tmp_primenumber
;
// just pick one number out of the possible numbers to factorize
m_taskNumber
=
possibleTasks
[
uint
((
double
(
qrand
())
/
RAND_MAX
)
*
numberPossibleTasks
)];
m_taskNumber
=
possibleTasks
[
QRandomGenerator
::
global
()
->
bounded
(
numberPossibleTasks
)];
// now get the primefactors of the taskNumber
m_factorsResult
.
clear
();
...
...
src/ExerciseMixedNumbers.cpp
View file @
a7eda770
...
...
@@ -18,6 +18,7 @@
#include
<QIntValidator>
#include
<QPushButton>
#include
<QWidget>
#include
<QRandomGenerator>
#ifdef DEBUG
#include
<QDebug>
...
...
@@ -203,13 +204,13 @@ void ExerciseMixedNumbers::createTask()
int
denominator
=
1
;
do
{
// numerator should be between 1..15
numerator
=
int
((
double
(
qrand
())
/
RAND_MAX
)
*
15
+
1
)
;
numerator
=
QRandomGenerator
::
global
()
->
bounded
(
15
)
+
1
;
// denominator should be between 1..(numerator-1)
denominator
=
int
((
double
(
qrand
())
/
RAND_MAX
)
*
numerator
);
denominator
=
QRandomGenerator
::
global
()
->
bounded
(
numerator
);
// eventually make ratio negative
if
(
double
(
qran
d
(
)
)
/
RAND_MAX
>=
0.5
)
{
if
(
QRandomGenerator
::
global
()
->
bounde
d
(
2
)
==
1
)
{
numerator
*=
-
1
;
}
tmpRatio
.
setRatio
(
numerator
,
denominator
);
...
...
src/ExercisePercentage.cpp
View file @
a7eda770
...
...
@@ -15,6 +15,7 @@
#include
<QIntValidator>
#include
<QLineEdit>
#include
<QPushButton>
#include
<QRandomGenerator>
#ifdef DEBUG
#include
<QDebug>
...
...
@@ -183,7 +184,7 @@ void ExercisePercentage::createTask()
{
// the tasks are hardcoded here; there are some algorithms to convert
// rational numbers to fractions, but it is not worth the effort here
switch
(
int
((
double
(
qrand
())
/
RAND_MAX
)
*
19
))
{
switch
(
QRandomGenerator
::
global
()
->
bounded
(
19
))
{
case
0
:
//m_number = QLocale().toString(0.5, 'f', 1);
m_numberPercentage
=
QStringLiteral
(
"75"
);
...
...
src/FractionRingWidget.cpp
View file @
a7eda770
...
...
@@ -26,6 +26,7 @@
#include
<QString>
#include
<QTextEdit>
#include
<QWidgetAction>
#include
<QRandomGenerator>
#ifdef DEBUG
#include
<QDebug>
...
...
@@ -402,16 +403,16 @@ void FractionRingWidget::NewTask()
void
FractionRingWidget
::
resetFraction
(
bool
flag
=
true
)
{
int
denominator
=
int
((
double
(
qrand
())
/
RAND_MAX
)
*
5
)
+
2
;
int
numerator
=
int
((
double
(
qrand
())
/
RAND_MAX
)
*
(
denominator
-
1
)
)
+
1
;
int
denominator
=
QRandomGenerator
::
global
()
->
bounded
(
5
)
+
2
;
int
numerator
=
QRandomGenerator
::
global
()
->
bounded
(
denominator
-
1
)
+
1
;
rLeft
=
Ratio
(
numerator
,
denominator
,
false
);
int
denominator2
=
int
((
double
(
qrand
())
/
RAND_MAX
)
*
5
)
+
2
;
int
denominator2
=
QRandomGenerator
::
global
()
->
bounded
(
5
)
+
2
;
while
(
denominator2
==
denominator
)
{
denominator2
=
int
((
double
(
qrand
())
/
RAND_MAX
)
*
5
)
+
2
;
denominator2
=
QRandomGenerator
::
global
()
->
bounded
(
5
)
+
2
;
}
int
numerator2
=
int
((
double
(
qrand
())
/
RAND_MAX
)
*
(
denominator2
-
1
)
)
+
1
;
int
numerator2
=
QRandomGenerator
::
global
()
->
bounded
(
denominator2
-
1
)
+
1
;
rRight
=
Ratio
(
numerator2
,
denominator2
,
false
);
multLeft
=
1
;
...
...
src/KBruch.cpp
View file @
a7eda770
...
...
@@ -31,8 +31,6 @@
/* the main program */
int
main
(
int
argc
,
char
*
argv
[])
{
// init random generator
qsrand
(
time
(
nullptr
));
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QCoreApplication
::
setAttribute
(
Qt
::
AA_EnableHighDpiScaling
);
#endif
...
...
src/Task.cpp
View file @
a7eda770
...
...
@@ -12,13 +12,13 @@
#include
<cmath>
#include
<ctime>
#include
<QRandomGenerator>
#include
<QDebug>
/** constructor of class task */
Task
::
Task
()
{
qsrand
(
time
(
nullptr
));
#ifdef DEBUG
qDebug
()
<<
"constructor task"
;
#endif
...
...
@@ -410,7 +410,7 @@ unsigned short Task::make_operation(short padd_add, short padd_div, short padd_m
op_vector
.
push_back
(
SUB
);
}
else
{
do
{
operations
=
short
((
double
(
qrand
())
/
RAND_MAX
)
*
4
);
operations
=
QRandomGenerator
::
global
()
->
bounded
(
4
);
switch
(
operations
)
{
case
ADD
:
if
(
padd_add
==
YES
)
{
...
...
@@ -487,7 +487,7 @@ int Task::make_main_dn(unsigned int pmax_md, unsigned short max_product_length)
/* find a main denominator in the given limits by pmax_md and check
* if the main denominator has enough prime factors */
do
{
denominator
=
int
(((
double
(
qrand
())
/
RAND_MAX
)
*
pmax_md
)
+
1
)
;
denominator
=
QRandomGenerator
::
global
()
->
bounded
(
pmax_md
)
+
1
;
}
while
((
pmax_md
<
1
)
||
(
prim_factor_nr
(
denominator
)
<
max_product_length
));
...
...
@@ -542,8 +542,7 @@ void Task::make_numerators(int main_denominator, short pnr_ratios)
/* add a new ratio to the task and compute the numerator randomly */
for
(
short
tmpcounter
=
0
;
tmpcounter
<
pnr_ratios
;
tmpcounter
++
)
{
(
*
this
).
add_ratio
(
int
((
double
(
qrand
())
/
RAND_MAX
)
*
max_numerator
)
+
1
,
1
);
(
*
this
).
add_ratio
(
QRandomGenerator
::
global
()
->
bounded
(
max_numerator
)
+
1
,
1
);
}
return
;
}
...
...
@@ -577,7 +576,7 @@ void Task::make_denominators(int main_denominator, short pmax_md,
for
(
ratio_pointer
=
ratio_vector
.
begin
();
ratio_pointer
!=
ratio_vector
.
end
();
++
ratio_pointer
)
{
do
{
tmp_deno
=
int
((
double
(
qrand
())
/
RAND_MAX
)
*
pmax_md
)
+
1
;
tmp_deno
=
QRandomGenerator
::
global
()
->
bounded
(
pmax_md
)
+
1
;
}
while
(
main_denominator
%
tmp_deno
!=
0
);
(
*
ratio_pointer
).
setDenominator
(
tmp_deno
);
}
...
...
@@ -606,8 +605,7 @@ void Task::make_denominators(int main_denominator, short pmax_md,
/* the prim_fac_vector is sorted, but we do not want the
* factors in this sorted way as our denominators;
* so we choose one randomly */
next_fac
=
(
unsigned
short
)((
double
(
qrand
())
/
RAND_MAX
)
*
unused_fac
);
next_fac
=
QRandomGenerator
::
global
()
->
bounded
(
unused_fac
);
tmp_counter
=
0
;
/* check the prime factors, if they are unused */
...
...
@@ -641,8 +639,7 @@ void Task::make_denominators(int main_denominator, short pmax_md,
/* the prim_fac_vector is sorted, but we do not want the
* factors in this sorted way as our denominators;
* so we choose one randomly */
next_fac
=
(
unsigned
short
)((
double
(
qrand
())
/
RAND_MAX
)
*
unused_fac
);
next_fac
=
QRandomGenerator
::
global
()
->
bounded
(
unused_fac
);
tmp_counter
=
0
;
/* check the prime factors, if they are unused */
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment