diff options
author | root | 2014-07-11 14:35:18 +0530 |
---|---|---|
committer | root | 2014-07-11 14:35:18 +0530 |
commit | 69aa63da6cb2bc3f5822533e3f97c46d7efbaafc (patch) | |
tree | db5ac9972c8af377f2f7f03f5be882d008412a38 /Schaum's_Outlines_-_Programming_with_C++/ch11.ipynb | |
parent | e9c8c9201198909af53ace24755d70e30bc24950 (diff) | |
download | Python-Textbook-Companions-69aa63da6cb2bc3f5822533e3f97c46d7efbaafc.tar.gz Python-Textbook-Companions-69aa63da6cb2bc3f5822533e3f97c46d7efbaafc.tar.bz2 Python-Textbook-Companions-69aa63da6cb2bc3f5822533e3f97c46d7efbaafc.zip |
removing books
Diffstat (limited to 'Schaum's_Outlines_-_Programming_with_C++/ch11.ipynb')
-rwxr-xr-x | Schaum's_Outlines_-_Programming_with_C++/ch11.ipynb | 704 |
1 files changed, 0 insertions, 704 deletions
diff --git a/Schaum's_Outlines_-_Programming_with_C++/ch11.ipynb b/Schaum's_Outlines_-_Programming_with_C++/ch11.ipynb deleted file mode 100755 index d65c28e3..00000000 --- a/Schaum's_Outlines_-_Programming_with_C++/ch11.ipynb +++ /dev/null @@ -1,704 +0,0 @@ -{ - "metadata": { - "name": "", - "signature": "sha256:e48eb1ccc0a3bcda7cfb3c8c85a4d3a8e98cd5fdd1c8b0533a2ba81289b5dcbf" - }, - "nbformat": 3, - "nbformat_minor": 0, - "worksheets": [ - { - "cells": [ - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "class Ratio:\n", - " def __init__(self,n=None,d=None):\n", - " if d==None:\n", - " self.num = n.num\n", - " self.den = n.den\n", - " elif n==None:\n", - " self.num = 0\n", - " self.den = 1\n", - " else:\n", - " self.num = n\n", - " self.den = d\n", - " \n", - " def equals(self):\n", - " return self # retuns calling object." - ], - "language": "python", - "metadata": {}, - "outputs": [], - "prompt_number": 1 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "class Ratio:\n", - " def __init__(self,n=None,d=None):\n", - " pass\n", - " \n", - " def equals(self):\n", - " pass\n" - ], - "language": "python", - "metadata": {}, - "outputs": [], - "prompt_number": 2 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "class Ratio:\n", - " def __init__(self,n=None,d=None):\n", - " if d==None:\n", - " self.num = n.num\n", - " self.den = n.den\n", - " elif n==None:\n", - " self.num = 0\n", - " self.den = 1\n", - " else:\n", - " self.num = n\n", - " self.den = d\n", - " \n", - "\n", - "z = Ratio(22,7)\n", - "y = z\n", - "x = z\n", - "\n", - "x = Ratio(22,7)\n", - "y = Ratio(x)\n", - "z = x\n", - "w = x" - ], - "language": "python", - "metadata": {}, - "outputs": [], - "prompt_number": 3 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "\n", - "class Ratio:\n", - " def __init__(self,n=None,d=None):\n", - " self.num = n\n", - " self.den = d\n", - " def __mul__(self,y):\n", - " pass\n" - ], - "language": "python", - "metadata": {}, - "outputs": [], - "prompt_number": 4 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "def gcd(m,n):\n", - " \n", - " if (m<n):\n", - " m,n = n,m\n", - " while (n>0):\n", - " r = m % n\n", - " m = n\n", - " n = r\n", - " return m\n", - "\n", - "\n", - "class Ratio:\n", - " def __init__(self,n=None,d=None):\n", - " self.num = n\n", - " self.den = d\n", - " self.reduce()\n", - " def __mul__(self,y):\n", - " z = Ratio(self.num * y.num, self.den * y.den)\n", - " return z\n", - " def print_(self):\n", - " print self.num , '/', self.den\n", - " \n", - " def reduce(self):\n", - " # enforce invariant(den > 0):\n", - " if (self.num == 0 or self.den == 0):\n", - " self.num = 0\n", - " self.den = 1\n", - " return\n", - " if (self.den < 0):\n", - " self.den *= -1\n", - " self.num *= -1\n", - " # enforce invariant(gcd(num,den) == 1):\n", - " if (self.den == 1):\n", - " return\n", - " # it's already reduced\n", - " sgn = 0\n", - " if self.num < 0:\n", - " sgn = -1\n", - " else:\n", - " sgn = 1\n", - " g = gcd(sgn*self.num,self.den)\n", - " self.num /= g\n", - " self.den /= g\n", - "x = Ratio(22,7)\n", - "y = Ratio(-3,8)\n", - "z = x\n", - "z.print_()\n", - "x = y*z\n", - "x.print_()\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "22 / 7\n", - "-33 / 28\n" - ] - } - ], - "prompt_number": 5 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "def gcd(m,n):\n", - " \n", - " if (m<n):\n", - " m,n = n,m\n", - " while (n>0):\n", - " r = m % n\n", - " m = n\n", - " n = r\n", - " return m\n", - "\n", - "\n", - "class Ratio:\n", - " def __init__(self,n=None,d=None):\n", - " self.num = n\n", - " self.den = d\n", - " self.reduce()\n", - " def __imul__(self,y):\n", - " self.num = self.num * y.num\n", - " self.den = self.den * y.den\n", - " def print_(self):\n", - " print self.num , '/', self.den" - ], - "language": "python", - "metadata": {}, - "outputs": [], - "prompt_number": 6 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "\n", - "class Ratio:\n", - " def __init__(self,n=None,d=None):\n", - " self.num = n\n", - " self.den = d\n", - " self.reduce()\n", - " def __imul__(self,y):\n", - " self.num = self.num * y.num\n", - " self.den = self.den * y.den\n", - " def __eq__(self,y):\n", - " return (x.num * y.den == y.num * x.den)\n", - " def print_(self):\n", - " print self.num , '/', self.den\n", - "\n" - ], - "language": "python", - "metadata": {}, - "outputs": [], - "prompt_number": 7 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "\n", - "class Ratio:\n", - " def __init__(self,n=None,d=None):\n", - " self.num = n\n", - " self.den = d\n", - " def __imul__(self,y):\n", - " self.num = self.num * y.num\n", - " self.den = self.den * y.den\n", - " def __eq__(self,y):\n", - " return (x.num * y.den == y.num * x.den)\n", - " def print_(self):\n", - " print self.num , '/', self.den\n", - "\n", - "\n", - "x = Ratio(22,7)\n", - "y = Ratio(-3,8)\n", - "x.print_() , y.print_()\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "22 / 7\n", - "-3 / 8\n" - ] - }, - { - "metadata": {}, - "output_type": "pyout", - "prompt_number": 8, - "text": [ - "(None, None)" - ] - } - ], - "prompt_number": 8 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "def gcd(m,n):\n", - "\n", - " if (m<n):\n", - " m,n = n,m\n", - " while (n>0):\n", - " r = m % n\n", - " m = n\n", - " n = r\n", - " return m\n", - "class Ratio:\n", - " def __init__(self,n=0,d=1):\n", - " self.num = n\n", - " self.den = d\n", - " self.reduce()\n", - " def __mul__(self,y):\n", - " z = Ratio(self.num * y.num, self.den * y.den)\n", - " return z\n", - " def print_(self):\n", - " print self.num , '/', self.den\n", - " \n", - " def input(self):\n", - " self.num = int(raw_input('Numerator : '))\n", - " self.den = int(raw_input('Denominator : '))\n", - " self.reduce()\n", - " def reduce(self):\n", - " # enforce invariant(den > 0):\n", - " if (self.num == 0 or self.den == 0):\n", - " self.num = 0\n", - " self.den = 1\n", - " return\n", - " if (self.den < 0):\n", - " self.den *= -1\n", - " self.num *= -1\n", - " # enforce invariant(gcd(num,den) == 1):\n", - " if (self.den == 1):\n", - " return\n", - " # it's already reduced\n", - " sgn = 0\n", - " if self.num < 0:\n", - " sgn = -1\n", - " else:\n", - " sgn = 1\n", - " g = gcd(sgn*self.num,self.den)\n", - " self.num /= g\n", - " self.den /= g\n", - "\n", - "\n", - "x = Ratio()\n", - "y = Ratio()\n", - "x.input()\n", - "y.input()\n", - "x.print_()\n", - "y.print_()\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Numerator : -10\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Denominator : -24\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Numerator : 36\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": [ - "Denominator : -20\n" - ] - }, - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "5 / 12\n", - "-9 / 5\n" - ] - } - ], - "prompt_number": 1 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "def gcd(m,n):\n", - "\n", - " if (m<n):\n", - " m,n = n,m\n", - " while (n>0):\n", - " r = m % n\n", - " m = n\n", - " n = r\n", - " return m\n", - "class Ratio:\n", - " def __init__(self,n=0,d=1):\n", - " self.num = n\n", - " self.den = d\n", - " self.reduce()\n", - " def __mul__(self,y):\n", - " z = Ratio(self.num * y.num, self.den * y.den)\n", - " return z\n", - " def print_(self):\n", - " print self.num , '/', self.den\n", - " \n", - " def input(self):\n", - " self.num = int(raw_input('Numerator : '))\n", - " self.den = int(raw_input('Denominator : '))\n", - " self.reduce()\n", - " def __float__(self):\n", - " return float(self.num)/self.den\n", - " def reduce(self):\n", - " # enforce invariant(den > 0):\n", - " if (self.num == 0 or self.den == 0):\n", - " self.num = 0\n", - " self.den = 1\n", - " return\n", - " if (self.den < 0):\n", - " self.den *= -1\n", - " self.num *= -1\n", - " # enforce invariant(gcd(num,den) == 1):\n", - " if (self.den == 1):\n", - " return\n", - " # it's already reduced\n", - " sgn = 0\n", - " if self.num < 0:\n", - " sgn = -1\n", - " else:\n", - " sgn = 15.py\n", - " g = gcd(sgn*self.num,self.den)\n", - " self.num /= g\n", - " self.den /= g\n", - "\n", - "x = Ratio(-5,8)\n", - "print \"x = \" , \n", - "x.print_() \n", - "print \", float(x) = \" , float(x) \n", - "P = Ratio(22,7)\n", - "PI = float(P)\n", - "print \"P = \" ,\n", - "P.print_() \n", - "print \", PI = \" , PI\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "x = -5 / 8\n", - ", float(x) = -0.625\n", - "P = 22 / 7\n", - ", PI = 3.14285714286\n" - ] - } - ], - "prompt_number": 3 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "def gcd(m,n):\n", - " \n", - " if (m<n):\n", - " m,n = n,m\n", - " while (n>0):\n", - " r = m % n\n", - " m = n\n", - " n = r\n", - " return m\n", - "class Ratio:\n", - " def __init__(self,n=0,d=1):\n", - " self.num = n\n", - " self.den = d\n", - " self.reduce()\n", - " def __mul__(self,y):\n", - " z = Ratio(self.num * y.num, self.den * y.den)\n", - " return z\n", - " def print_(self):\n", - " print self.num , '/', self.den\n", - " \n", - " def __iadd__(self,n):\n", - " self.num += self.den\n", - " return self\n", - " def reduce(self):\n", - " # enforce invariant(den > 0):\n", - " if (self.num == 0 or self.den == 0):\n", - " self.num = 0\n", - " self.den = 1\n", - " return\n", - " if (self.den < 0):\n", - " self.den *= -1\n", - " self.num *= -1\n", - " # enforce invariant(gcd(num,den) == 1):\n", - " if (self.den == 1):\n", - " return\n", - " # it's already reduced\n", - " sgn = 0\n", - " if self.num < 0:\n", - " sgn = -1\n", - " else:\n", - " sgn = 1\n", - " g = gcd(sgn*self.num,self.den)\n", - " self.num /= g\n", - " self.den /= g\n", - "\n", - "x = Ratio(22,7)\n", - "x += 1\n", - "y = x\n", - "print \"y = \" ,\n", - "y.print_()\n", - "print \", x = \",\n", - "x.print_()\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "y = 29 / 7\n", - ", x = 29 / 7\n" - ] - } - ], - "prompt_number": 5 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "def gcd(m,n):\n", - " \n", - " if (m<n):\n", - " m,n = n,m\n", - " while (n>0):\n", - " r = m % n\n", - " m = n\n", - " n = r\n", - " return m\n", - "class Ratio:\n", - " def __init__(self,n=0,d=1):\n", - " self.num = n\n", - " self.den = d\n", - " self.reduce()\n", - " def __mul__(self,y):\n", - " z = Ratio(self.num * y.num, self.den * y.den)\n", - " return z\n", - " def print_(self):\n", - " print self.num , '/', self.den\n", - " \n", - " def __iadd__(self,n):\n", - " self.num += self.den\n", - " return self\n", - " def reduce(self):\n", - " # enforce invariant(den > 0):\n", - " if (self.num == 0 or self.den == 0):\n", - " self.num = 0\n", - " self.den = 1\n", - " return\n", - " if (self.den < 0):\n", - " self.den *= -1\n", - " self.num *= -1\n", - " # enforce invariant(gcd(num,den) == 1):\n", - " if (self.den == 1):\n", - " return\n", - " # it's already reduced\n", - " sgn = 0\n", - " if self.num < 0:\n", - " sgn = -1\n", - " else:\n", - " sgn = 1\n", - " g = gcd(sgn*self.num,self.den)\n", - " self.num /= g\n", - " self.den /= g\n", - "\n", - "x = Ratio(22,7)\n", - "y = Ratio(x.num,x.den)\n", - "x += 1\n", - "print \"y = \" ,\n", - "y.print_()\n", - "print \", x = \",\n", - "x.print_()\n", - "\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "y = 22 / 7\n", - ", x = 29 / 7\n" - ] - } - ], - "prompt_number": 9 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "\n", - "def gcd(m,n):\n", - " \n", - " if (m<n):\n", - " m,n = n,m\n", - " while (n>0):\n", - " r = m % n\n", - " m = n\n", - " n = r\n", - " return m\n", - "class Ratio:\n", - " def __init__(self,n=0,d=1):\n", - " self.num = n\n", - " self.den = d\n", - " self.reduce()\n", - " def __mul__(self,y):\n", - " z = Ratio(self.num * y.num, self.den * y.den)\n", - " return z\n", - " def print_(self):\n", - " print self.num , '/', self.den\n", - " \n", - " def __getitem__(self,k):\n", - " if k == 1:\n", - " return self.num\n", - " else:\n", - " return self.den\n", - " def reduce(self):\n", - " # enforce invariant(den > 0):\n", - " if (self.num == 0 or self.den == 0):\n", - " self.num = 0\n", - " self.den = 1\n", - " return\n", - " if (self.den < 0):\n", - " self.den *= -1\n", - " self.num *= -1\n", - " # enforce invariant(gcd(num,den) == 1):\n", - " if (self.den == 1):\n", - " return\n", - " # it's already reduced\n", - " sgn = 0\n", - " if self.num < 0:\n", - " sgn = -1\n", - " else:\n", - " sgn = 1\n", - " g = gcd(sgn*self.num,self.den)\n", - " self.num /= g\n", - " self.den /= g\n", - "\n", - "x = Ratio(22,7)\n", - "print \"x = \" ,\n", - "x.print_()\n", - "print \"x[1] = \" , x[1] , \", x[2] = \" , x[2]\n" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": [ - "x = 22 / 7\n", - "x[1] = 22 , x[2] = 7\n" - ] - } - ], - "prompt_number": 2 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [], - "language": "python", - "metadata": {}, - "outputs": [], - "prompt_number": 2 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [], - "language": "python", - "metadata": {}, - "outputs": [], - "prompt_number": 2 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [], - "language": "python", - "metadata": {}, - "outputs": [] - } - ], - "metadata": {} - } - ] -}
\ No newline at end of file |