| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package App::Math::Tutor::Cmd::VulFrac::Cmd::Cast; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
15818
|
use warnings; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
39
|
|
|
4
|
1
|
|
|
1
|
|
4
|
use strict; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
35
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
4
|
use vars qw(@ISA $VERSION); |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
72
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
App::Math::Tutor::Cmd::VulFrac::Cmd::Cast - Plugin for casting of vulgar fraction into decimal fraction and vice versa |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=cut |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $VERSION = '0.005'; |
|
15
|
|
|
|
|
|
|
|
|
16
|
1
|
|
|
1
|
|
5
|
use Moo; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
7
|
|
|
17
|
1
|
|
|
1
|
|
273
|
use MooX::Cmd; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
6
|
|
|
18
|
1
|
|
|
1
|
|
1651
|
use MooX::Options; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
7
|
|
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
has template_filename => ( |
|
21
|
|
|
|
|
|
|
is => "ro", |
|
22
|
|
|
|
|
|
|
default => "twocols" |
|
23
|
|
|
|
|
|
|
); |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
with "App::Math::Tutor::Role::VulFracExercise", "App::Math::Tutor::Role::DecFracExercise"; |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head2 chart |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
Enable chart for fraction approximation. |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
Warning: This is experimental and requires LaTeX::Driver 0.20+ and properly working xelatex |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
Default: 0 |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=cut |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
option chart => ( |
|
40
|
|
|
|
|
|
|
is => "ro", |
|
41
|
|
|
|
|
|
|
doc => "Enable chart for fraction approximation", |
|
42
|
|
|
|
|
|
|
long_doc => "Enable chart for fraction approximation\n\n" |
|
43
|
|
|
|
|
|
|
. "Warning: This is experimental and requires LaTeX::Driver 0.20+ and properly working xelatex\n\n" |
|
44
|
|
|
|
|
|
|
. "Default: 0", |
|
45
|
|
|
|
|
|
|
default => sub { 0 }, |
|
46
|
|
|
|
|
|
|
negativable => 1, |
|
47
|
|
|
|
|
|
|
); |
|
48
|
|
|
|
|
|
|
|
|
49
|
0
|
|
|
0
|
|
|
sub _build_command_names { qw(cast); } |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub _get_castable_numbers |
|
52
|
|
|
|
|
|
|
{ |
|
53
|
0
|
|
|
0
|
|
|
my ( $self, $quantity ) = @_; |
|
54
|
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
my @result; |
|
56
|
0
|
|
|
|
|
|
while ( $quantity-- ) |
|
57
|
|
|
|
|
|
|
{ |
|
58
|
0
|
|
|
|
|
|
my $vf; |
|
59
|
|
|
|
|
|
|
do |
|
60
|
0
|
|
0
|
|
|
|
{ |
|
61
|
0
|
|
|
|
|
|
$vf = $self->_guess_vulgar_fraction; |
|
62
|
|
|
|
|
|
|
} while ( !$self->_check_vulgar_fraction($vf) or !$self->_check_decimal_fraction($vf) ); |
|
63
|
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
push @result, $vf; |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
@result; |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub _build_exercises |
|
71
|
|
|
|
|
|
|
{ |
|
72
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
|
73
|
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
my (@tasks); |
|
75
|
0
|
|
|
|
|
|
foreach my $i ( 1 .. $self->quantity ) |
|
76
|
|
|
|
|
|
|
{ |
|
77
|
0
|
|
|
|
|
|
my @line; |
|
78
|
0
|
|
|
|
|
|
foreach my $j ( 0 .. 1 ) |
|
79
|
|
|
|
|
|
|
{ |
|
80
|
0
|
|
|
|
|
|
my ($a) = $self->_get_castable_numbers(1); |
|
81
|
0
|
|
|
|
|
|
push @line, [$a]; |
|
82
|
|
|
|
|
|
|
} |
|
83
|
0
|
|
|
|
|
|
push @tasks, \@line; |
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
my $exercises = { |
|
87
|
|
|
|
|
|
|
section => "Vulgar fraction <-> decimal fracion casting", |
|
88
|
|
|
|
|
|
|
caption => 'Fractions', |
|
89
|
|
|
|
|
|
|
label => 'vulgar_decimal_fractions', |
|
90
|
|
|
|
|
|
|
header => [ [ 'Vulgar => Decimal Fraction', 'Decimal => Vulgar Fraction' ] ], |
|
91
|
|
|
|
|
|
|
solutions => [], |
|
92
|
|
|
|
|
|
|
challenges => [], |
|
93
|
|
|
|
|
|
|
usepackages => [qw(pstricks pstricks-add)], |
|
94
|
|
|
|
|
|
|
}; |
|
95
|
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
my $digits = $self->digits; |
|
97
|
0
|
|
|
|
|
|
foreach my $line (@tasks) |
|
98
|
|
|
|
|
|
|
{ |
|
99
|
0
|
|
|
|
|
|
my ( @solution, @challenge ); |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
# cast vulgar fraction to decimal |
|
102
|
0
|
|
|
|
|
|
my ($a) = @{ $line->[0] }; |
|
|
0
|
|
|
|
|
|
|
|
103
|
0
|
|
|
|
|
|
push @challenge, sprintf( '$ %s = $', $a ); |
|
104
|
|
|
|
|
|
|
|
|
105
|
0
|
|
|
|
|
|
my @way; # remember Frank Sinatra :) |
|
106
|
0
|
|
|
|
|
|
push @way, "" . $a; |
|
107
|
0
|
|
|
|
|
|
$a = $a->_reduce; |
|
108
|
0
|
0
|
|
|
|
|
$a->num != $line->[0]->[0]->num and push @way, "" . $a; |
|
109
|
0
|
|
|
|
|
|
my $rd = $digits + length( int($a) ) + 1; |
|
110
|
0
|
|
|
|
|
|
push @way, sprintf( "%0.${rd}g", $a ); |
|
111
|
0
|
0
|
|
|
|
|
$self->chart and push @way, |
|
112
|
|
|
|
|
|
|
sprintf( |
|
113
|
|
|
|
|
|
|
'\begin{pspicture}(-0.25,-0.25)(0.25,0.25)\psChart[chartColor=color,chartSep=1pt]{%d,%d}{}{0.25}\end{pspicture}', |
|
114
|
|
|
|
|
|
|
$a->num % $a->denum, |
|
115
|
|
|
|
|
|
|
$a->denum - ( $a->num % $a->denum ) |
|
116
|
|
|
|
|
|
|
); |
|
117
|
0
|
|
|
|
|
|
push( @solution, '$ ' . join( " = ", @way ) . ' $' ); |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
# cast decimal to vulgar fraction |
|
120
|
0
|
|
|
|
|
|
@way = (); |
|
121
|
0
|
|
|
|
|
|
($a) = @{ $line->[1] }; |
|
|
0
|
|
|
|
|
|
|
|
122
|
0
|
|
|
|
|
|
$rd = $digits + length( int($a) ) + 1; |
|
123
|
0
|
|
|
|
|
|
push @challenge, sprintf( "\$ %0.${rd}g = \$", $a ); |
|
124
|
0
|
|
|
|
|
|
push @way, sprintf( "%0.${rd}g", $a ); |
|
125
|
0
|
|
|
|
|
|
$a = $a->_reduce; |
|
126
|
0
|
|
|
|
|
|
push @way, "" . $a; |
|
127
|
0
|
0
|
|
|
|
|
$self->chart and push @way, |
|
128
|
|
|
|
|
|
|
sprintf( |
|
129
|
|
|
|
|
|
|
'\begin{pspicture}(-0.25,-0.25)(0.25,0.25)\psChart[chartColor=color,chartSep=1pt]{%d,%d}{}{0.25}\end{pspicture}', |
|
130
|
|
|
|
|
|
|
$a->num % $a->denum, |
|
131
|
|
|
|
|
|
|
$a->denum - ( $a->num % $a->denum ) |
|
132
|
|
|
|
|
|
|
); |
|
133
|
0
|
|
|
|
|
|
push( @solution, '$ ' . join( " = ", @way ) . ' $' ); |
|
134
|
|
|
|
|
|
|
|
|
135
|
0
|
|
|
|
|
|
push( @{ $exercises->{solutions} }, \@solution ); |
|
|
0
|
|
|
|
|
|
|
|
136
|
0
|
|
|
|
|
|
push( @{ $exercises->{challenges} }, \@challenge ); |
|
|
0
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
} |
|
138
|
|
|
|
|
|
|
|
|
139
|
0
|
|
|
|
|
|
$exercises; |
|
140
|
|
|
|
|
|
|
} |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
Copyright 2010-2014 Jens Rehsack. |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
|
147
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
|
148
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=cut |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
1; |