12.07.2015 Views

OO Example: Fractions

OO Example: Fractions

OO Example: Fractions

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Using the Fraction class This is enough for us to create a Fraction object● a.k.a. “create a Fraction instance”● a.k.a. “instantiate the Fraction class” f1 = Fraction(2, 3) print f1 # “2 / 3” We can't do much with our Fraction object yet,so the next step is to implement some methods Multiple methods may want to check theconstraint of denom ≠ 0: make a helper methodCMPT140: <strong>OO</strong>: fractions 20 Nov 20094

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!