Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 29 additions & 5 deletions pretext/Introduction/ObjectOrientedProgrammingDefiningClasses.ptx
Original file line number Diff line number Diff line change
Expand Up @@ -285,21 +285,45 @@ class Fraction {

int main() {
Fraction fraca(3, 5);
Fraction fracb(3);
Fraction fracc; //notice there are no parentheses here.
// cout << fraca << endl; //uncomment to see error
fraca.show();

Fraction fracb(3);
fracb.show();

Fraction fracc; //notice there are no parentheses here.
fracc.show();

// cout << fraca << endl; //uncomment to see error

return 0;
}
</input></program></statement>
</task>
<task xml:id="showmethod-py" label="showmethod_py">
<title>Python</title>
<statement><program interactive="activecode" language="python" label="showmethod_py-prog"><input>
def show(self):
print(self.num,"/",self.den)
class Fraction:

def __init__(self,top = 0,bottom = 1):

self.num = top
self.den = bottom
def show(self):
print(self.num,"/",self.den)

def main():
fraca = Fraction(3,5)
fraca.show()

fracb = Fraction(3)
fracb.show()

fracc = Fraction()# notice no parameters are passed
fracc.show()

# notice print(fraca) will give you an unexpected output

main()
</input></program></statement>
</task>
</exploration>
Expand Down