i think i would start with creating a module for fractions, with, and probably with a function that does all of the operations of fractions (add, subtract...). maybe you'll have to make it output the common denominator step inside the module though. so then you have something like ($frac1 + $frac2) / ($frac3 + $frac4) where $frac\d is of the type of your new fraction module. and then you might end up with another fraction... where $new_fraction's numerator is ($frac1 + $frac2) and it's denominator is ($frac3 + $frac4).
so (obvioulsy implementation is up to you) i would think of something a data structure for fraction as a hash with numerator and denominator, and your $new_fraction would be something like:
$new_frac => {
numerator => "5/3 + 7/13",
denominator => "5/2 - 3/7"
}
and then eventually something like
$new_frac => {
numerator => {
numerator => 86,
denominator => 39
},
denominator => {
numerator => 29,
denominator => 14
}
}
come to think of it, you may need to have a data structure or module to represent an "expression" too.
also, to parse the expression, you may want to look at postfix (although you can certainly still output the expressions in infix)
these are just my thoughts on how i'd approach it.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.