diff options
18 files changed, 4684 insertions, 0 deletions
diff --git a/C++_in_Action_-_Industrial-Strength_Programming_Techniques/README.txt b/C++_in_Action_-_Industrial-Strength_Programming_Techniques/README.txt new file mode 100755 index 00000000..dad00691 --- /dev/null +++ b/C++_in_Action_-_Industrial-Strength_Programming_Techniques/README.txt @@ -0,0 +1,10 @@ +Contributed By: Ashutosh Kumar +Course: btech +College/Institute/Organization: Indian Institute of Technology - Bombay, CHAR Lab 2 +Department/Designation: Electrical Department +Book Title: C++ in Action - Industrial-Strength Programming Techniques +Author: Bartosz Milewski +Publisher: Addison Wesley Publishing Company +Year of publication: 2001 +Isbn: 0201699486 +Edition: 1st
\ No newline at end of file diff --git a/C++_in_Action_-_Industrial-Strength_Programming_Techniques/ch1.ipynb b/C++_in_Action_-_Industrial-Strength_Programming_Techniques/ch1.ipynb new file mode 100755 index 00000000..834bacf2 --- /dev/null +++ b/C++_in_Action_-_Industrial-Strength_Programming_Techniques/ch1.ipynb @@ -0,0 +1,284 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:2af50dca95bb8940069ca1eefad39c58f8f97bbf13a194cd9fff16b4f6521b4f" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter One : Naming" + ] + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 1.1 Page no : 2 \n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "strL = 0 # Not recommended\n", + "stringLength = 0 # Recommended" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "Example 2 Page no : 3\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "class EmcFruit:\n", + " def print_(self):\n", + " pass\n", + "\n", + "class EmcApple(EmcFruit):\n", + " def print_(self):\n", + " pass\n", + "\n", + "fp = EmcApple()\n", + "print fp " + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "<__main__.EmcApple instance at 0x9d29c8c>\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 1.3 Page no : 4\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "class Point:\n", + " def __init__(self,a,b):\n", + " self.x = a\n", + " self.y = b\n", + " def x1(self,a):\n", + " self.x = a\n", + "\n", + "p = Point(0,0) # a point in a 2-dimensional space\n", + "p.x1(1); # set X-coordinate\n", + "print p.x # prints X-coordinate, \"1\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "1\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 1.4 page no : 4\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "def check_assign(a,i,t):\n", + " if (i < len(a)):\n", + " a[i] = t;" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 1.5 Page no : 6\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "class String:\n", + " pass\n", + "\n", + "class DynamicArray:\n", + " pass" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 1.6 page no : 6\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "a = 'aaa' \n", + "s1 = 'xyz'\n", + "s = 'abc' # Emc::String s;\n" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 6 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 1.8 page no : 7\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "s1 = EmcString() # Belongs to the Emc Class Library\n", + "s2 = OtherString() # Belongs to the Other Class Library" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "ename": "NameError", + "evalue": "name 'EmcString' is not defined", + "output_type": "pyerr", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m<ipython-input-7-16beeed526dd>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m 4\u001b[0m \u001b[0mNote\u001b[0m \u001b[1;33m:\u001b[0m \u001b[0mthis\u001b[0m \u001b[0mwill\u001b[0m \u001b[0mgive\u001b[0m \u001b[0merror\u001b[0m \u001b[0mbecause\u001b[0m \u001b[0mfile\u001b[0m \u001b[0mdoesn\u001b[0m\u001b[0;31m'\u001b[0m\u001b[0mt\u001b[0m \u001b[0mhave\u001b[0m \u001b[1;32mclass\u001b[0m \u001b[0mEmcString\u001b[0m \u001b[1;32mand\u001b[0m \u001b[0mOtherString\u001b[0m\u001b[1;33m.\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 5\u001b[0m '''\n\u001b[1;32m----> 6\u001b[1;33m \u001b[0ms1\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mEmcString\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;31m# Belongs to the Emc Class Library\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 7\u001b[0m \u001b[0ms2\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mOtherString\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;31m# Belongs to the Other Class Library\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;31mNameError\u001b[0m: name 'EmcString' is not defined" + ] + } + ], + "prompt_number": 7 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 1.9 Page no : 8\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "import RWCstring #include \"RWCstring.h\" /* Recommended */\n", + "from rw import cstring #include \"rw/cstring.h\" /* Sometimes needed */" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "ename": "ImportError", + "evalue": "No module named RWCstring", + "output_type": "pyerr", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[1;31mImportError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m<ipython-input-8-4593d91551b4>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m 5\u001b[0m \u001b[0mNote\u001b[0m \u001b[1;33m:\u001b[0m \u001b[0mthis\u001b[0m \u001b[0mwould\u001b[0m \u001b[0mgive\u001b[0m \u001b[0merror\u001b[0m \u001b[0mbecause\u001b[0m \u001b[0mwe\u001b[0m \u001b[0mdont\u001b[0m \u001b[0mhave\u001b[0m \u001b[0mpackages\u001b[0m \u001b[0mwritten\u001b[0m \u001b[0mhere\u001b[0m\u001b[1;33m.\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 6\u001b[0m '''\n\u001b[1;32m----> 7\u001b[1;33m \u001b[1;32mimport\u001b[0m \u001b[0mRWCstring\u001b[0m \u001b[1;31m#include \"RWCstring.h\" /* Recommended */\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 8\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[0mrw\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mcstring\u001b[0m \u001b[1;31m#include \"rw/cstring.h\" /* Sometimes needed */\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;31mImportError\u001b[0m: No module named RWCstring" + ] + } + ], + "prompt_number": 8 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 1.10 page no : 9\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "i__j = 11;\n", + "_K = 22;\n", + "_m = 33;\n" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 9 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [], + "language": "python", + "metadata": {}, + "outputs": [] + } + ], + "metadata": {} + } + ] +}
\ No newline at end of file diff --git a/C++_in_Action_-_Industrial-Strength_Programming_Techniques/ch10.ipynb b/C++_in_Action_-_Industrial-Strength_Programming_Techniques/ch10.ipynb new file mode 100755 index 00000000..52781089 --- /dev/null +++ b/C++_in_Action_-_Industrial-Strength_Programming_Techniques/ch10.ipynb @@ -0,0 +1,497 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:70f9ab632bffbd9fecc3bdcee575cac266cb09d4df74fddec4e595d028f134df" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "<h1> Chapter Ten : Object-oriented programming </h1>" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "<h3>Example 10.1 page no :105" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "s = \"hello\" # length() == 5\n", + "print s\n", + "print len(s)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "hello\n", + "5" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "<h3>EXAMPLE 10.2 page no : 106" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "s = \"Hello\"\n", + "\n", + "s = s.lower()\n", + "print s" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "hello" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "<h3> example 10.3 page no :107" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "class EmcCollection:\n", + " \n", + " def insert(self,t):\n", + " pass\n", + " \n", + " def operator(self, coll):\n", + " pass\n", + "\n", + "class EmcArrayCollection(EmcCollection):\n", + " initialSize = 10\n", + "\n", + " def __init__(self,maxsize):\n", + " pass\n", + "\n", + "\n", + "class InvalidCollectionType(EmcException):\n", + " \n", + " def __init__(self,i):\n", + " pass\n", + "\n", + "class EmcCollectionFactory:\n", + " def __init__(self):\n", + " pass\n", + "\n", + " def create(self,type):\n", + " pass\n", + "\n", + " def createArray(self):\n", + " pass" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "ename": "NameError", + "evalue": "name 'EmcException' is not defined", + "output_type": "pyerr", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m/home/jay/<ipython-input-3-5d8a499d2644>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 22\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 23\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 24\u001b[0;31m \u001b[0;32mclass\u001b[0m \u001b[0mInvalidCollectionType\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mEmcException\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 25\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 26\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m__init__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mNameError\u001b[0m: name 'EmcException' is not defined" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "<h3>example 10.4 page no :109" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "factory = EmcCollectionFactory()\n", + "collection = factory.create(ArrayId)\n", + "collection.insert(42); # EmcArrayCollection<int>::insert() is called\n", + "print collection" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "ename": "NameError", + "evalue": "name 'EmcCollectionFactory' is not defined", + "output_type": "pyerr", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m/home/jay/<ipython-input-4-9ee6096719fb>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 5\u001b[0m '''\n\u001b[1;32m 6\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 7\u001b[0;31m \u001b[0mfactory\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mEmcCollectionFactory\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 8\u001b[0m \u001b[0mcollection\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mfactory\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcreate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mArrayId\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 9\u001b[0m \u001b[0mcollection\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0minsert\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m42\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m;\u001b[0m \u001b[0;31m# EmcArrayCollection<int>::insert() is called\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mNameError\u001b[0m: name 'EmcCollectionFactory' is not defined" + ] + } + ], + "prompt_number": 4 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "<h3>example 10.5 page no : 111" + ] + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "\n", + "class EmcCollection:\n", + " def __del__(self):\n", + " pass\n", + "\n", + "class EmcArrayCollection( EmcCollection):\n", + " def __del__(self):\n", + " pass" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 5 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "<h3>example 10.6 page no :112" + ] + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "\n", + "class EmcLogged:\n", + " def writeClassName(self,o):\n", + " pass\n", + "\n", + " def writeValue(self,o):\n", + " pass\n", + "\n", + " def logMessage(self,message):\n", + " pass\n", + "\n", + " def __del__(self):\n", + " pass\n", + "\n", + "class EmcLoggedCollection(EmcCollection):\n", + "\n", + " def writeValue(self,o):\n", + " pass\n", + "\n", + " def __del__(self):\n", + " pass " + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 6 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "<h3>EXAMPLE 10.7 Page no : 117" + ] + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "\n", + "\n", + "\n", + "class EmcIntStack:\n", + " def empty(self):\n", + " pass\n", + "\n", + " def full(self):\n", + " pass\n", + " \n", + " def top(self):\n", + " pass\n", + " \n", + " def push(self,i):\n", + " pass\n", + " \n", + " def pop(self):\n", + " pass" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 7 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "<h3>EXAMPLE 10.8 Page no : 117" + ] + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "\n", + "\n", + "def makeString(stack):\n", + " returnValue = ''\n", + " copy = stack\n", + " while (not copy.empty()):\n", + " # loop condition makes precondition valid\n", + " print copy.pop() # Precondition: ! copy.empty()\n", + " returnValue += copy.pop\n", + "\n", + " return returnValue;" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 8 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "<h3>EXAMPLE 10.9 page no : 118" + ] + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "\n", + "\n", + "class EmcString:\n", + " def cStr(self):\n", + " pass\n", + " # cStr() returns 0-terminated string\n", + "\n", + " def length(self):\n", + " pass" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 9 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "<h3>EXAMPLE 10.10 page no : 119" + ] + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "\n", + "\n", + "class EmcCollection:\n", + " def __del__(self):\n", + " pass\n", + "\n", + " def insert(self,T):\n", + " pass\n", + "\n", + " def clear(self):\n", + " pass\n", + "\n", + " def remove(self):\n", + " pass" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 10 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "<h3>EXAMPLE 10.11 page no : 120" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "factrory = EmcCollectionFactory()\n", + "collection = factory.create(ArrayId);\n", + "if (not collection.isFull()):\n", + " collection.insert(42);" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "ename": "NameError", + "evalue": "name 'EmcCollectionFactory' is not defined", + "output_type": "pyerr", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m/home/jay/<ipython-input-11-0508dec5ea10>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 5\u001b[0m '''\n\u001b[1;32m 6\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 7\u001b[0;31m \u001b[0mfactrory\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mEmcCollectionFactory\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 8\u001b[0m \u001b[0mcollection\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mfactory\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcreate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mArrayId\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m;\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 9\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0;32mnot\u001b[0m \u001b[0mcollection\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0misFull\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mNameError\u001b[0m: name 'EmcCollectionFactory' is not defined" + ] + } + ], + "prompt_number": 11 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "<h3>EXAMPLE 10.12 page no : 121" + ] + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "\n", + "def insertObject(c,element):\n", + " \n", + " if (not c.isFull()):\n", + " c.insert(element)\n", + " return True\n", + " return False" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 12 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "<h3>EXAMPLE 10.13 Page no : 121" + ] + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "\n", + "def insert(T):\n", + " pass" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 13 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "<h3>EXAMPLE 10.14 page no : 123" + ] + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "\n", + "\n", + "class EmcCollection:\n", + " pass" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 14 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "<h3>EXAMPLE 10.15 page no : 124" + ] + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "\n", + "class EmcCollection:\n", + " def templateRequirements(self):\n", + " pass\n", + "\n", + " def templateRequirements(self):\n", + " \n", + " t1 = T1()\n", + " \n", + " t2 =t1\n", + "\n", + " t2 = t1;\n", + " # Assignable\n", + " b = (t2 == t1); # EqualityComparable" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 15 + }, + { + "cell_type": "code", + "collapsed": true, + "input": [], + "language": "python", + "metadata": {}, + "outputs": [] + } + ], + "metadata": {} + } + ] +}
\ No newline at end of file diff --git a/C++_in_Action_-_Industrial-Strength_Programming_Techniques/ch11.ipynb b/C++_in_Action_-_Industrial-Strength_Programming_Techniques/ch11.ipynb new file mode 100755 index 00000000..9dc6882e --- /dev/null +++ b/C++_in_Action_-_Industrial-Strength_Programming_Techniques/ch11.ipynb @@ -0,0 +1,79 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:2e265a79f479b0afc28156201c75dda9d71f161b6acb07438df53ecda65f24e0" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "<h1>Chapter Eleven : Assertions" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "<h3>EXAMPLE 11.1 page no : 130" + ] + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "\n", + "\n", + "def check(answer):\n", + " assert answer ==42" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 1 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "<h3>EXAMPLE 11.2 page no : 131" + ] + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "\n", + "class EmcString:\n", + " def at(self,index):\n", + " if (index >= self.lengthM):\n", + " raise Exception;\n", + " return self.cpM[index];\n", + "\n", + " # Unchecked version\n", + " def operator(self,index):\n", + " assert(index < self.lengthM)\n", + " return self.cpM[index];" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 2 + }, + { + "cell_type": "code", + "collapsed": true, + "input": [], + "language": "python", + "metadata": {}, + "outputs": [] + } + ], + "metadata": {} + } + ] +}
\ No newline at end of file diff --git a/C++_in_Action_-_Industrial-Strength_Programming_Techniques/ch12.ipynb b/C++_in_Action_-_Industrial-Strength_Programming_Techniques/ch12.ipynb new file mode 100755 index 00000000..a4d7907e --- /dev/null +++ b/C++_in_Action_-_Industrial-Strength_Programming_Techniques/ch12.ipynb @@ -0,0 +1,363 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:3fda869111a137bc83ae4b79f3c57ac84f247031c3e08ac7d6dfb9bb168b3105" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "<h1>Chapter Twelve : Error handling" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "<h3>EXAMPLE 12.1 page no : 135" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "socketfd = socket(AF_UNIX, SOCK_STREAM, 0);\n", + "if(socketfd < 0):\n", + " pass" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "ename": "NameError", + "evalue": "name 'socket' is not defined", + "output_type": "pyerr", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m/home/jay/<ipython-input-1-7161141a3c7c>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 10\u001b[0m \u001b[0;34m//\u001b[0m \u001b[0mcreate\u001b[0m \u001b[0msocket\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 11\u001b[0m '''\n\u001b[0;32m---> 12\u001b[0;31m \u001b[0msocketfd\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0msocket\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mAF_UNIX\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mSOCK_STREAM\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m;\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 13\u001b[0m \u001b[0;32mif\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msocketfd\u001b[0m \u001b[0;34m<\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 14\u001b[0m \u001b[0;32mpass\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mNameError\u001b[0m: name 'socket' is not defined" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "<h3>EXAMPLE 12.2 page no : 136" + ] + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "\n", + "class EmcException:\n", + " def operator(self,n):\n", + " pass\n", + "\n", + "class EmcSystemException( EmcException):\n", + " def __init__(self,m):\n", + " pass\n", + " \n", + " def emcSocket(self,family,t,protocol):\n", + " # create socket\n", + " socketfd = socket(family, t, protocol);\n", + " if (socketfd < 0): # check status value\n", + " raise EmcSystemException(\"emcSocket\");\n", + " return socketfd;" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 2 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "<h3>EXAMPLE 12.3 page no : 139" + ] + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "\n", + "\n", + "def __init__(self,cp):\n", + " self.lengthM = len(cp)\n", + " self.cpM = cp" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 13 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "<h3>EXAMPLE 12.5 page no : 141" + ] + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "\n", + "class EmcLog:\n", + " def __init__(self,filename):\n", + " pass\n", + "\n", + " def message(self,EmcString):\n", + " pass\n", + "\n", + " def __del__(self):\n", + " if uncaught_exception():\n", + " self.flush()\n", + " \n", + " def flush(self):\n", + " if ( not uncaught_exception()):\n", + " raise EmcSystemException(\"EmcLog::flush()\")" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 4 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "<h3>EXAMPLE 12.6 page no : 142" + ] + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "\n", + "class EmcException:\n", + " def __init__(self,m):\n", + " maxSizeM = 100\n", + " actualLength = len(m);\n", + " self.lengthM = min(maxSizeM,actualLength);\n", + " self.messageM = message" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 5 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "<h3>EXAMPLE 12.7" + ] + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "\n", + "\n", + "def f():\n", + " ip = 1\n", + " g(ip)\n", + "\n", + "\n", + "def g(i):\n", + " raise Exception(i)" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 6 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "<h3>EXAMPLE 12.8 page no : 146" + ] + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "\n", + "\n", + "def f():\n", + " ip = 1\n", + " g(ip)\n", + "\n", + "def g(i):\n", + " raise Exception(i)" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 7 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "<h3>EXAMPLE 12.9 page no :146" + ] + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "\n", + "def f():\n", + " ip = 1\n", + " g(ip)" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 8 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "<h3>EXAMPLE 12.10 page no : 148" + ] + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "\n", + "class EmcStack:\n", + " defaultSizeM = 100\n", + " def __init__(self,size = 100):\n", + " pass\n", + "\n", + " def __del__(self):\n", + " pass\n", + "\n", + " def operator(self,s):\n", + " pass\n", + "\n", + " def empty(self):\n", + " pass\n", + " \n", + " def top(self):\n", + " pass\n", + "\n", + " def push(self,i):\n", + " pass\n", + " \n", + " def pop(self):\n", + " pass" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 9 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "<h3>EXAMPLE 12.12 page no : 151" + ] + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "\n", + "class EmcException:\n", + " def __init__(self,m):\n", + " pass\n", + " \n", + " def operator(self,o,EmcException):\n", + " pass\n", + "\n", + " def printOn(self,o): \n", + " print self.messageM;" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 10 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "<h3>EXAMPLE 12.13 page no : 153" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "try:\n", + " socketfd = emcSocket(AF_UNIX, SOCK_STREAM, 0);\n", + "except Exception,e:\n", + " print e" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "name 'emcSocket' is not defined" + ] + } + ], + "prompt_number": 11 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "<h3>EXAMPLE 12.14 page no : 155" + ] + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "\n", + "\n", + "def at(s,pos):\n", + " if (pos > len(s)):\n", + " raise Exception;" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 12 + }, + { + "cell_type": "code", + "collapsed": true, + "input": [], + "language": "python", + "metadata": {}, + "outputs": [] + } + ], + "metadata": {} + } + ] +}
\ No newline at end of file diff --git a/C++_in_Action_-_Industrial-Strength_Programming_Techniques/ch13.ipynb b/C++_in_Action_-_Industrial-Strength_Programming_Techniques/ch13.ipynb new file mode 100755 index 00000000..a23bdf0e --- /dev/null +++ b/C++_in_Action_-_Industrial-Strength_Programming_Techniques/ch13.ipynb @@ -0,0 +1,352 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:121cbe714f8e854e8d9ce1fe8dcdc370535cc7140b2f83bdae09063602e644f9" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "<h1> Chapter Thirteen : Parts of C++ to avoid" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "<h3>EXAMPLE 13.1 page no : 159" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "s = 'abc' #raw_input()\n", + "print s" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "abc" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "<h3>EXAMPLE 13.2 page no : 160" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "class DangerousString:\n", + " def __init__(self,cp):\n", + " pass\n", + " \n", + " def char(self):\n", + " pass\n", + "\n", + "hello = \"Hello World!\";\n", + "print hello # Works perfectly\n", + "print \"%s\"%hello" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Hello World!\n", + "Hello World!" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "<h3>EXAMPLE 13.3 page no : 160" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "class EmcString:\n", + " def __init__(self,cp):\n", + " pass\n", + "\n", + "\n", + "s = \"Hello World!\";\n", + "print s " + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Hello World!" + ] + } + ], + "prompt_number": 4 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "<h3>EXAMPLE 13.4 page no :161" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "SIZE = 1024;\n", + "print SIZE" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "1024" + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "<h3>EXAMPLE 13.5 page no : 162" + ] + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "\n", + "class X:\n", + " class Color:\n", + " green = 1\n", + " yellow = 2\n", + " red = 3" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 6 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "<h3>EXAMPLE 13.6 page no : 162" + ] + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "\n", + "class X:\n", + " maxBuf = 1024\n", + " class Color:\n", + " green = 1\n", + " yellow = 2\n", + " red = 3" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 7 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "<h3>EXAMPLE 13.7 page no : 162" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "def SQUARE(x):\n", + " return x*x\n", + "\n", + "i = SQUARE(3 + 4); \n", + "print i" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "49" + ] + } + ], + "prompt_number": 8 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "<h3>EXAMPLE 13.8 page no : 163" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "def square(x):\n", + " return x * x;\n", + "c = 2;\n", + "d = square(c)\n", + "print d" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "4" + ] + } + ], + "prompt_number": 9 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "<h3>EXAMPLE 13.9 page no : 163" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "def SQUARE(x):\n", + " return x*x\n", + "i = SQUARE(\"hello\");\n", + "print i" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "ename": "TypeError", + "evalue": "can't multiply sequence by non-int of type 'str'", + "output_type": "pyerr", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m/home/jay/<ipython-input-10-df398cb9cbc0>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 6\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mSQUARE\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 7\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mx\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 8\u001b[0;31m \u001b[0mi\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mSQUARE\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"hello\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m;\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 9\u001b[0m \u001b[0;32mprint\u001b[0m \u001b[0mi\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m/home/jay/<ipython-input-10-df398cb9cbc0>\u001b[0m in \u001b[0;36mSQUARE\u001b[0;34m(x)\u001b[0m\n\u001b[1;32m 5\u001b[0m '''\n\u001b[1;32m 6\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mSQUARE\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 7\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mx\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 8\u001b[0m \u001b[0mi\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mSQUARE\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"hello\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m;\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 9\u001b[0m \u001b[0;32mprint\u001b[0m \u001b[0mi\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mTypeError\u001b[0m: can't multiply sequence by non-int of type 'str'" + ] + } + ], + "prompt_number": 10 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "<h3>EXAMPLE 13.10 page no : 163" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "#define Velocity int\n", + "#typedef int Velocity;\n", + "# Not recommended" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "metadata": {}, + "output_type": "pyout", + "prompt_number": 11, + "text": [ + "'\\nEXAMPLE 13.10 page no : 163\\nHow to define synonyms for a type\\nNote : Python doesnot have synonyms for type as we do not have to explicitely \\ndeclare variables.\\n'" + ] + } + ], + "prompt_number": 11 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "<h3>EXAMPLE 13.11 page no : 164" + ] + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "\n", + "\n", + "def printFruits(fruits,size):\n", + " for i in range(size):\n", + " print fruits[i] " + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 12 + }, + { + "cell_type": "code", + "collapsed": true, + "input": [], + "language": "python", + "metadata": {}, + "outputs": [] + } + ], + "metadata": {} + } + ] +}
\ No newline at end of file diff --git a/C++_in_Action_-_Industrial-Strength_Programming_Techniques/ch15.ipynb b/C++_in_Action_-_Industrial-Strength_Programming_Techniques/ch15.ipynb new file mode 100755 index 00000000..32ad5666 --- /dev/null +++ b/C++_in_Action_-_Industrial-Strength_Programming_Techniques/ch15.ipynb @@ -0,0 +1,623 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:24f5f3b754e3fd6e8afab7bcb99e41e817ec5bce9faae498ba9fb75dd53f93ff" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "<h1> Chapter Fifteen : Portability" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "<h3>EXAMPLE 15.1 page no : 172" + ] + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "\n", + "c = -100;\n", + "if (c < 0):\n", + " pass" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 1 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "<h3>EXAMPLE 15.2 page no : 173" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "class BasicAttrType:\n", + " counterGauge = 0x1000\n", + " counterPeg = 0x2000\n", + " conterAcc = 0x3000\n", + " \n", + "\n", + "\n", + "t = BasicAttrType.counterGauge\n", + "print t" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "4096" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "<h3>EXAMPLE 15.3 page no : 173" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "a = ''\n", + "print a" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "<h3>example 15.5 page no : 174" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "result = 1234 * 567\n", + "print result" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "699678" + ] + } + ], + "prompt_number": 4 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "<h3>Example 15.6 page no : 175" + ] + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "\n", + "import math # python has only one way to importing file.\n", + "from math import *" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 5 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "<h3>exmaple 15.7 page no : 176" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + " \n", + "# import inc.MyFile\n", + "# import inc.MyFile\n", + "\n", + "# import gui.xinterface" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "metadata": {}, + "output_type": "pyout", + "prompt_number": 6, + "text": [ + "'\\nexmaple 15.7 page no : 176\\nDirectory names in include directives\\nNote : python has . operator to import a file from directory\\n'" + ] + } + ], + "prompt_number": 6 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "<h3>EXAMPLE 15.8 page no : 176" + ] + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "\n", + "\n", + "import math\n" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 7 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "<h3>EXAMPLE 15.9 page no : 178" + ] + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "\n", + "\n", + "class PersonRecord:\n", + " ageM = ''\n", + " phoneNumberM = 0\n", + " nameM = ''" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 8 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "<h3>EXAMPLE 15.10 page no : 178" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "def stepAndConvert(a,n):\n", + " b = a + str(n) # step n chars ahead\n", + " return b # NO: Dangerous cast of const char* to int*\n", + "\n", + "\n", + "data = \"abcdefghijklmnop\"\n", + "anInt = 3;\n", + "i = stepAndConvert(data, anInt)\n", + "print i" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "abcdefghijklmnop3" + ] + } + ], + "prompt_number": 9 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "<h3>EXAMPLE 15.11 page no : 179" + ] + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "\n", + "INT_MIN = -2147483648\n", + "INT_MAX = 2147483647\n", + "UINT_MAX = 4294967295\n", + "i = 42\n", + "ui = 2222222242;\n", + "j = i - ui;\n", + "print j" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "-2222222200" + ] + } + ], + "prompt_number": 10 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "<h3>EXAMPLE 15.12 page no : 180" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "zero = 0;\n", + "one = 1;\n", + "minusOne = zero - one;\n", + "print minusOne\n", + "result = one + minusOne;\n", + "print result" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "-1\n", + "0" + ] + } + ], + "prompt_number": 11 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "<h3>EXAMPLE 15.13 page no : 180" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "pid1 = fork(); # NO: should use pid_t\n", + "\n", + "pid2 = fork();" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "ename": "NameError", + "evalue": "name 'fork' is not defined", + "output_type": "pyerr", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m/home/jay/<ipython-input-12-ef16c6a16507>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0mNote\u001b[0m \u001b[0;34m:\u001b[0m \u001b[0mIt\u001b[0m \u001b[0mwould\u001b[0m \u001b[0mshoot\u001b[0m \u001b[0merror\u001b[0m \u001b[0mbecause\u001b[0m \u001b[0mfork\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0mdefined\u001b[0m \u001b[0mhere\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m '''\n\u001b[0;32m----> 6\u001b[0;31m \u001b[0mpid1\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mfork\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m;\u001b[0m \u001b[0;31m# NO: should use pid_t\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 7\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 8\u001b[0m \u001b[0mpid2\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mfork\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m;\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mNameError\u001b[0m: name 'fork' is not defined" + ] + } + ], + "prompt_number": 12 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "<h3>EXAMPLE 15.14 page no : 181" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "famousClimber = \"Edmund Hillary\"; # Uses Emc as prefix\n", + "print famousClimber" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Edmund Hillary" + ] + } + ], + "prompt_number": 13 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "<h3>EXAMPLE 15.15 page no : 183" + ] + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "\n", + "\n", + "class EmcArray:\n", + " def __init__(self,size):\n", + " pass" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 14 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "<h3>EXAMPLE 15.16 page no : 183" + ] + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "\n", + "\n", + "\n", + "false = 0;\n", + "true = 1;" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 15 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "<h3>EXAMPLE 15.17 page no : 184" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "i = 0;\n", + "for i in range(last()):\n", + " pass\n", + "\n", + "for i in range(first()):\n", + " pass" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "ename": "NameError", + "evalue": "name 'last' is not defined", + "output_type": "pyerr", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m/home/jay/<ipython-input-16-119935826b55>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 5\u001b[0m '''\n\u001b[1;32m 6\u001b[0m \u001b[0mi\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m;\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 7\u001b[0;31m \u001b[0;32mfor\u001b[0m \u001b[0mi\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mrange\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlast\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 8\u001b[0m \u001b[0;32mpass\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 9\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mNameError\u001b[0m: name 'last' is not defined" + ] + } + ], + "prompt_number": 16 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "<h3>EXAMPLE 15.18 page no : 185" + ] + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "\n", + "\n", + "def emcMax(a, b):\n", + " if a>b:\n", + " return a\n", + " return b\n", + "\n", + "def foo(i,j):\n", + " m = emcMax(i, j); # usage of emcMax\n", + "\n", + "q = 0 # usage of class EmcQueue<int> and\n", + "s = 0 # EmcQueue<int>:s default constructor" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 1 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "<h3>EXAMPLE 15.19 page no : 186" + ] + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "\n", + "class EmcQueue:\n", + " pass" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 2 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "<h3>EXAMPLE 15.20 page no : 187" + ] + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "\n", + "\n", + "class DangerousString:\n", + " def __init__(self,cp):\n", + " pass\n", + "\n", + " def char(self):\n", + " pass" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 3 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "<h3>example 15.22 page no : 189" + ] + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "\n", + "def main(self):\n", + " return 0" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 4 + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "<h3>EXAMPLE 15.23" + ] + }, + { + "cell_type": "code", + "collapsed": true, + "input": [ + "\n", + "\n", + "func(f1(), f2(), f3()) # f1 may be evaluated before f2 and f3,\n", + "# but don't depend on it!" + ], + "language": "python", + "metadata": {}, + "outputs": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "<h3>EXAMPLE 15.24 page no : 189" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "a = [0,0,0]\n", + "i = 0\n", + "a[i] = i;\n", + "i += 1\n", + "print i \n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "1" + ] + } + ], + "prompt_number": 6 + }, + { + "cell_type": "code", + "collapsed": true, + "input": [], + "language": "python", + "metadata": {}, + "outputs": [] + } + ], + "metadata": {} + } + ] +}
\ No newline at end of file diff --git a/C++_in_Action_-_Industrial-Strength_Programming_Techniques/ch2.ipynb b/C++_in_Action_-_Industrial-Strength_Programming_Techniques/ch2.ipynb new file mode 100755 index 00000000..8660012f --- /dev/null +++ b/C++_in_Action_-_Industrial-Strength_Programming_Techniques/ch2.ipynb @@ -0,0 +1,260 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:025b4c65298f5bb6d48b99d717b6d0fce940f5a97ad7eb75ea5897c4c9595891" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter : Two : Organizing the code" + ] + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 2.1 Page no : 12\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "import EmcArray # EmcArray.py\n", + "import iostream # The rest of the EmcArray.cc file " + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "ename": "ImportError", + "evalue": "No module named EmcArray", + "output_type": "pyerr", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[1;31mImportError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m<ipython-input-1-b23807a66872>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m 4\u001b[0m \u001b[0mNote\u001b[0m \u001b[1;33m:\u001b[0m \u001b[0mwould\u001b[0m \u001b[0mgive\u001b[0m \u001b[0merror\u001b[0m \u001b[0mbecause\u001b[0m \u001b[0mwe\u001b[0m \u001b[0mdont\u001b[0m \u001b[0mhave\u001b[0m \u001b[0mEmcArray\u001b[0m \u001b[1;32mand\u001b[0m \u001b[0miostream\u001b[0m \u001b[0mpackages\u001b[0m\u001b[1;33m.\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 5\u001b[0m '''\n\u001b[1;32m----> 6\u001b[1;33m \u001b[1;32mimport\u001b[0m \u001b[0mEmcArray\u001b[0m \u001b[1;31m# EmcArray.py\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 7\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0miostream\u001b[0m \u001b[1;31m# The rest of the EmcArray.cc file\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;31mImportError\u001b[0m: No module named EmcArray" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 2.2 page no : 13\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + " \n", + "\n", + "class X :\n", + " def __init__(self):\n", + " pass #self.aM = A()\n", + " \n", + " def returnA(self):\n", + " pass #return self.aM\n", + " \n", + " def withAParameter(self,a):\n", + " pass #self.aM = a" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 2.3 page no :14\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "class Y :\n", + " def __init__(self):\n", + " pass #self.bM = B()\n", + " \n", + " def returnBPtr(self):\n", + " pass #return self.aM\n", + " \n", + " def withAParameter(self,b):\n", + " pass #self.bM = a\n" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 2.4 page no : 15\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "def module_exists(module_name):\n", + " try:\n", + " __import__(module_name)\n", + " except ImportError:\n", + " return False\n", + " else:\n", + " return True" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 2.5 page no : 15\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "def cStr(cpM):\n", + " return cpM\n" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 2.6 page no : 17\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "\n", + "def max_(x,y):\n", + " if x > y:\n", + " return x\n", + " return y\n", + "\n", + "def function(i,j):\n", + " m = max_(i,j) # must instantiate max(int,int)\n", + " print m\n", + "\n", + "function(5,10) \n", + " " + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "10\n" + ] + } + ], + "prompt_number": 6 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 2.7 page no : 17\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "class EmcQueue:\n", + " def __init__(self):\n", + " pass\n", + " \n", + " def insert(self,t):\n", + " pass\n", + "\n", + "q = EmcQueue()\n", + "q.insert(42);" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 7 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 2.8 page no : 18\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "class EmcQueue:\n", + " pass" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 8 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [], + "language": "python", + "metadata": {}, + "outputs": [] + } + ], + "metadata": {} + } + ] +}
\ No newline at end of file diff --git a/C++_in_Action_-_Industrial-Strength_Programming_Techniques/ch3.ipynb b/C++_in_Action_-_Industrial-Strength_Programming_Techniques/ch3.ipynb new file mode 100755 index 00000000..ce027b4e --- /dev/null +++ b/C++_in_Action_-_Industrial-Strength_Programming_Techniques/ch3.ipynb @@ -0,0 +1,144 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:dbc95d125151940c8402c8ffda427c3e959c7eb724b40434b79a3b03a164fff8" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter Three : Comments" + ] + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 3.1 Page no : 22\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "rcsid = \"$Id: $\"\n", + "print rcsid" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "$Id: $\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 3.2 Page no : 22\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "cpM = ''; # A String variable\n", + "lenM = 0 # The length of the character array " + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "Example 3.3 Page no : 22\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "''' No: this nesting of C-style comments will not work !!!\n", + "char* cpM;\n", + "int lenM;\n", + "# A pointer to the characters\n", + "# The length of the character array \n", + "'''" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "metadata": {}, + "output_type": "pyout", + "prompt_number": 2, + "text": [ + "' No: this nesting of C-style comments will not work !!!\\nchar* cpM;\\nint lenM;\\n# A pointer to the characters\\n# The length of the character array \\n'" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 1 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 1 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 1 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [], + "language": "python", + "metadata": {}, + "outputs": [] + } + ], + "metadata": {} + } + ] +}
\ No newline at end of file diff --git a/C++_in_Action_-_Industrial-Strength_Programming_Techniques/ch4.ipynb b/C++_in_Action_-_Industrial-Strength_Programming_Techniques/ch4.ipynb new file mode 100755 index 00000000..16c0834c --- /dev/null +++ b/C++_in_Action_-_Industrial-Strength_Programming_Techniques/ch4.ipynb @@ -0,0 +1,237 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:814e2a9ffe7448c8830af394019244e2f81fe0819c83f253105a48f1b6c7edaf" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter Four : Control flow" + ] + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "Example 4.1 page no : 27\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "numberOfObjects = 42;\n", + "a = []\n", + "for i in range(numberOfObjects):\n", + " # Recommended\n", + " print i \n", + " a.append(i)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "0\n", + "1\n", + "2\n", + "3\n", + "4\n", + "5\n", + "6\n", + "7\n", + "8\n", + "9\n", + "10\n", + "11\n", + "12\n", + "13\n", + "14\n", + "15\n", + "16\n", + "17\n", + "18\n", + "19\n", + "20\n", + "21\n", + "22\n", + "23\n", + "24\n", + "25\n", + "26\n", + "27\n", + "28\n", + "29\n", + "30\n", + "31\n", + "32\n", + "33\n", + "34\n", + "35\n", + "36\n", + "37\n", + "38\n", + "39\n", + "40\n", + "41\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 4.2 page no :27\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "numberOfObjects = 42;\n", + "a = []\n", + "for i in range(numberOfObjects):\n", + " # Recommended\n", + " a.append(i)\n", + "\n", + "print \"Enter value: \";\n", + "value = int(raw_input())\n", + "\n", + "if value == 1 or value==2:\n", + " print \"1 or 2: \" , a[value] \n", + "else:\n", + " if (value > 2 and value < numberOfObjects):\n", + " print \"Not 1 or 2: \" , a[value] " + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter value: \n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "10\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Not 1 or 2: 10\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 4.3 page no : 28\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "class Status:\n", + " red = 1\n", + " green = 2\n", + "\n", + "def convertStatus(status):\n", + " if status == Status.red:\n", + " return \"Red\"\n", + " elif status == Status.green:\n", + " return \"Green\"\n", + " else: \n", + " return \"Illegal value\" \n", + "\n", + "print convertStatus(1) \n", + "print convertStatus(2)\n", + "print convertStatus(5)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Red\n", + "Green\n", + "Illegal value\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 4.4 page no : 29" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "m = 10;\n", + "errorflag = False;\n", + "\n", + "for i in range(m):\n", + " if (True):\n", + " errorflag = True;\n", + " break; # leaves loop\n", + "\n", + "# no goto needed\n", + "if(errorflag):\n", + " pass" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 4 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [], + "language": "python", + "metadata": {}, + "outputs": [] + } + ], + "metadata": {} + } + ] +}
\ No newline at end of file diff --git a/C++_in_Action_-_Industrial-Strength_Programming_Techniques/ch5.ipynb b/C++_in_Action_-_Industrial-Strength_Programming_Techniques/ch5.ipynb new file mode 100755 index 00000000..4e630070 --- /dev/null +++ b/C++_in_Action_-_Industrial-Strength_Programming_Techniques/ch5.ipynb @@ -0,0 +1,366 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:862ed788d417ee363a92882e2a970648b380a2f974a44d4fd4e62dfc3b0fcdf2" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter Five : Object Life Cycle" + ] + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "Example 5.1 page no: 32\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "i = 10;\n", + "j = 10;" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "Example 5.2 page no : 33\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "string1 = \"hello\";\n", + "string2 = \"hello\"; \n", + "print string1, string2" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "hello hello\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 5.3 page no : 33\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "i = int(raw_input()) # no reason to initialize i\n", + "print i" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "5\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "5\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 5.4 page no : 34\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "oldLm = 0;\n", + "newLm = 0;" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 5.5 page no : 34\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "charMapSize = 256;\n", + "for i in range(charMapSize):\n", + " pass" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 5.6 page no : 36\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "class Base:\n", + " def __init__(self,i=0):\n", + " self.iM = 0\n", + "\n", + "class Derived(Base):\n", + " def __init__(self,i=0):\n", + " Base.__init__(self,i)\n", + " self.jM = i" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 6 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 5.7 page no : 37\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "class Base:\n", + " def __init__(self,i=0):\n", + " self.iM = 0\n", + "\n", + "class Derived(Base):\n", + " def __init__(self,i=0):\n", + " self.jM = i\n", + " bm = Base(i)" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 7 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "example 5.8 page no : 40\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "def dangerous():\n", + " i = 5;\n", + " return i\n", + "j = dangerous(); # NO: j is dangerous to use\n", + "print j;\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "5\n" + ] + } + ], + "prompt_number": 8 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 5.9 page no : 41\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "class CommunicationPort:\n", + " def __init__(self,port):\n", + " pass\n", + " \n", + " def __del__(self):\n", + " pass" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 9 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 5.10 page no : 42\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "class EmcIntStack:\n", + " def __init__(self,d):\n", + " self.allocatedM = d\n", + " self.vectorM = []\n", + "\n", + " def __del__():\n", + " pass " + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 10 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "example 5.11 page no : 43\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "s = \"Aguirre\";\n", + "s = s;\n", + "print s " + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Aguirre\n" + ] + } + ], + "prompt_number": 11 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "example 5.12 page no : 43\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "s = \"Aguirre\";\n", + "r = s;\n", + "print r" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Aguirre\n" + ] + } + ], + "prompt_number": 12 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [], + "language": "python", + "metadata": {}, + "outputs": [] + } + ], + "metadata": {} + } + ] +}
\ No newline at end of file diff --git a/C++_in_Action_-_Industrial-Strength_Programming_Techniques/ch6.ipynb b/C++_in_Action_-_Industrial-Strength_Programming_Techniques/ch6.ipynb new file mode 100755 index 00000000..3f83e4d0 --- /dev/null +++ b/C++_in_Action_-_Industrial-Strength_Programming_Techniques/ch6.ipynb @@ -0,0 +1,252 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:7e4ca4515204ca5f28b7ad14f25998ad16f2910d212e32a1071b57e6d0d7e56b" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter Six : Conversions" + ] + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 6.1 page no : 48\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "large = 456789; # Potentially dangerous conversion\n", + "size = float(large)\n", + "print size" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "456789.0\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 6.2 page no : 49\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "class DangerousString :\n", + " def __init__(self):\n", + " pass # self.s = ''\n", + "\n", + " def __str__(self):\n", + " pass # return self.s" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 6.3 page no : 51\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "large = 456789\n", + "size = int(large);\n", + "three = \"three\" \n", + "print large,size,three" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "456789 456789 three\n" + ] + } + ], + "prompt_number": 9 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 6.4 page no : 51\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "class B:\n", + " pass\n", + " \n", + "class D( B):\n", + " pass\n", + "\n", + "class E:\n", + " pass\n", + " \n", + "def dynamicCast(b):\n", + " \n", + " return D(b)\n", + "\n", + "def constCast(d1):\n", + " \n", + " return D(d1)\n", + "\n", + "def reinterpretCast(d):\n", + " \n", + " return E(d)" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 6.5 page no : 52\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "def addToFileList(s):\n", + " pass\n", + " \n", + "def addFiles(s):\n", + " m = len(s)\n", + " for i in range(m):\n", + " addToFileList(s[i])" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 6 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 6.6 page no : 52\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + " \n", + "ci = 22;\n", + "pi = ci # NO: Const cast away\n", + "i = pi; # OK\n", + " \n", + "pi = 7 \n", + "print ci, pi, i " + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "22 7 22\n" + ] + } + ], + "prompt_number": 7 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "example 6.7 page no : 53\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "class EmcMatrix:\n", + " def __init__(self):\n", + " self.isDirtyM = False\n", + " self.detM = 0.0\n", + "\n", + " def calculateDeterminant(self):\n", + " pass\n", + "\n", + " def determinant(self):\n", + " if(isDirtyM):\n", + " # OK, access to mutable data members\n", + " self.detM = self.calculateDeterminant();\n", + " self.isDirtyM = False;\n", + " return self.detM;" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 8 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [], + "language": "python", + "metadata": {}, + "outputs": [] + } + ], + "metadata": {} + } + ] +}
\ No newline at end of file diff --git a/C++_in_Action_-_Industrial-Strength_Programming_Techniques/ch7.ipynb b/C++_in_Action_-_Industrial-Strength_Programming_Techniques/ch7.ipynb new file mode 100755 index 00000000..f8b112a8 --- /dev/null +++ b/C++_in_Action_-_Industrial-Strength_Programming_Techniques/ch7.ipynb @@ -0,0 +1,796 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:fbefe45753ab0203894f5afad5e792e20da756faab0edd14dfdedec2c8be513a" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter Seven : The class interface" + ] + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 7.1 page no : 57\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "class Point:\n", + " def __init__(self,x,y):\n", + " self.xM = x\n", + " self.yM = y\n", + "\n", + " def x(self):\n", + " return self.xM\n", + " \n", + " def y(self):\n", + " return self.yM\n", + "\n", + " def x_(self,x):\n", + " self.xM = x\n", + " \n", + " def y_(self,y):\n", + " self.yM = y\n", + "\n", + " def __add__(self,p2): \n", + " return Point(self.x() + p2.x(), self.y() + p2.y())" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "example 7.2 page no : 59\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "def valueFunc(t):\n", + " pass\n", + "\n", + "def pointerFunc(tp):\n", + " pass\n", + "\n", + "def referenceFunc(tr):\n", + " pass" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "example 7.3 page no : 60\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "def func1(c):\n", + " pass\n", + "\n", + "def func2(i):\n", + " pass\n", + " \n", + "def func3(d):\n", + " pass\n", + " \n", + "def func(c):\n", + " pass" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 7.4 page no : 61\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "class EmcMathVector:\n", + " def __init__(self,x,y):\n", + " self.xM = x\n", + " self.yM = y\n", + "\n", + " def __mul__(self,i):\n", + " self.xM *= i\n", + " self.yM *= i\n", + "\n", + " def x(self):\n", + " return self.xM\n", + " \n", + " def y(self):\n", + " return self.yM\n", + "\n", + " def x_(self,x):\n", + " self.xM = x\n", + " \n", + " def y_(self,y):\n", + " yM = y\n", + "\n", + "a = EmcMathVector(5,10)\n", + "print a.xM,a.yM\n", + "a * 5\n", + "print a.xM,a.yM" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "5 10\n", + "25 50\n" + ] + } + ], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 7.5 page no : 63\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "class vector:\n", + " def __init__(self,first,last):\n", + " pass\n", + "\n", + " def begin(self):\n", + " pass\n", + "\n", + " def push_back(self,x):\n", + " pass\n", + " \n", + " def insert(self,x):\n", + " pass" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 7.6 page no : 64\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "class basic_ofstream:\n", + " def __init__(self,x,y):\n", + " self.x = x\n", + " self.y = y\n", + "\n", + " def print_(self):\n", + " print self.x , \", \" , self.y;\n", + "\n", + "\n", + "v = basic_ofstream(1.2, 5.5);\n", + "v.print_()" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "1.2 , 5.5\n" + ] + } + ], + "prompt_number": 6 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 7.7 page no : 65 \n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "def uselessPrint(v):\n", + " # NO: Compile error\n", + " print v.x() , \", \" , v.y();" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 7 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "example 7.8 page no : 65\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "\n", + "array = ['','','']\n", + "# assign to first element\n", + "arrayPointer = 42 #*(arrayPointer = array) = 42\n", + "print arrayPointer" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "42\n" + ] + } + ], + "prompt_number": 8 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 7.10 page no : 67\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "def arraySum(array,first,last):\n", + " s = 0\n", + " for i in array:\n", + " # It is possible to update first since\n", + " # it has not been declared const.\n", + " s += i\n", + " return s;\n", + " \n", + "print arraySum([5,4,3,2],5,2) " + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "14\n" + ] + } + ], + "prompt_number": 9 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 7.11 page no : 68\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "class EmcStack:\n", + " def __init__(self):\n", + " self.repM = []\n", + " self.allocatedM = 0\n", + " self.topM = 0\n", + " \n", + " def push(t):\n", + " if self.topM == allocatedM : # allocate more memory\n", + " pass #size_t newSize = 2 * allocatedM;\n", + " self.repM.append(t)\n", + " self.topM +=1" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 10 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 7.12 page no : 69\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "message1 = \"Calling Orson\";\n", + "message2 = \"Ice Hockey\";\n", + "message3 = \"Terminator\";\n", + "message4 = \"I like candy\"\n", + "\n", + "print message1\n", + "print message2\n", + "print message3\n", + "print message4" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Calling Orson\n", + "Ice Hockey\n", + "Terminator\n", + "I like candy\n" + ] + } + ], + "prompt_number": 11 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 7.13 page no : 70\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "class UselessString:\n", + " def __init__(self,c=None):\n", + " pass\n", + " \n", + " def cStr(self):\n", + " pass\n", + " \n", + " def length(self):\n", + " pass\n", + " \n", + " def at(self,index):\n", + " pass\n", + " \n", + " def print_(self):\n", + " print self.s " + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 12 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 7.14 page no : 71\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "class Silly:\n", + " def __init__(self,val):\n", + " self.valM = val\n", + " \n", + " def me(self,s):\n", + " pass" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 13 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 7.15 page no : 72\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "name = \"John Bauer\";\n", + "print name[0]" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "J\n" + ] + } + ], + "prompt_number": 14 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 7.16 page no : 75\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "cosmonaut = \"Juri Gagarin\"\n", + "c = 'a';\n", + "cValue = c in cosmonaut # cValue == true\n", + "uri = \"uri\"\n", + "uriValue = uri in cosmonaut # uriValue == true\n", + "print cValue\n", + "print uriValue" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "True\n", + "True\n" + ] + } + ], + "prompt_number": 15 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 7.17 page no : 76 \n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "def max_(x,y):\n", + " if (x > y): # could use: < instead\n", + " # We also expect that:\n", + " # y < x\n", + " return x;\n", + " else:\n", + " # We also expect that:\n", + " # x <= y\n", + " return y;\n", + "\n", + "x = 42;\n", + "y = 0;\n", + "print max(x,y)\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "42\n" + ] + } + ], + "prompt_number": 16 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 7.18 page no : 76\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "'''\n", + "Implementation of closely related operators\n", + "Python has inbuilt this facility. No need to write functions for that.\n", + "''' " + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "metadata": {}, + "output_type": "pyout", + "prompt_number": 17, + "text": [ + "'\\nEXAMPLE 7.18 page no : 76\\nImplementation of closely related operators\\nPython has inbuilt this facility. No need to write functions for that.\\n'" + ] + } + ], + "prompt_number": 17 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 7.19 page no : 77\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "class Base:\n", + " def f(char):\n", + " pass\n", + " def f(i):\n", + " pass\n", + " def v(char):\n", + " pass\n", + "\n", + "class Derived(Base):\n", + " def __init__(self):\n", + " pass\n", + "\n", + " def f(self,i):\n", + " pass\n", + " \n", + " def v(self,c):\n", + " self.f(c)" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 18 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 7.20 page no : 79\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "class EmcCollection:\n", + " def isEqual(self):\n", + " pass\n", + " \n", + "class EmcBoundedCollection(EmcCollection):\n", + "\n", + " def isEqual(a):\n", + " pass" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 19 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "example 7.21 page no : 80\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "def f(x,y = 2):\n", + " print x\n", + " print y\n", + " \n", + "f(1)\n", + "f(2,3)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "1\n", + "2\n", + "2\n", + "3\n" + ] + } + ], + "prompt_number": 20 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 7.22 page no : 80\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "class RanDraw:\n", + " def __init__(self, limit,seed, t = 'Good' ):\n", + " pass # Default argument for t in class definition\n" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 21 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 7.23 page no : 82\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "class Other:\n", + " def __init__(self,a): #No implicit conversion from Any\n", + " pass\n", + " \n", + " def foo(self,o):\n", + " pass" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 22 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "example 7.24 page no : 82\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "class EmcString:\n", + " def cStr(): # conversion to const char*\n", + " pass\n", + "\n", + " def log(cp): \n", + " pass\n", + "\n", + "magicPlace =\"Ngoro-Ngoro crater at dusk\"\n", + "print magicPlace # Explicit conversion from String to const char*" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Ngoro-Ngoro crater at dusk\n" + ] + } + ], + "prompt_number": 23 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [], + "language": "python", + "metadata": {}, + "outputs": [] + } + ], + "metadata": {} + } + ] +}
\ No newline at end of file diff --git a/C++_in_Action_-_Industrial-Strength_Programming_Techniques/ch8.ipynb b/C++_in_Action_-_Industrial-Strength_Programming_Techniques/ch8.ipynb new file mode 100755 index 00000000..657c42ba --- /dev/null +++ b/C++_in_Action_-_Industrial-Strength_Programming_Techniques/ch8.ipynb @@ -0,0 +1,173 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:9aeef576f29f7c783f96768a664cb437cbd4922734a99612921a48bd58c127b5" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter Eight : new and delete" + ] + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 8.1 page no : 89\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "sp = \"Hello\" \n", + "arraySize = 5;\n", + "sa = []\n", + "print sp, arraySize\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Hello 5\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 8.2 page no : 90\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "sp = \"Hello\"\n", + "print sp\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Hello\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 8.3 page no : 90\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "class W:\n", + " def __init__(self):\n", + " pass\n", + "\n", + " def goAway(self):\n", + " pass\n", + " \n", + " def foo(self):\n", + " pass\n", + " \n", + " def bar(self):\n", + " pass" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 8.4 page no : 91\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "maxSize = 100; # get storage for object\n", + "storage = [] # call placement new to create object\n", + " " + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 8.5 page no : 93 \n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "class BadArgument:\n", + " def __init__(self):\n", + " pass\n", + "\n", + "class A:\n", + " def __init__(self):\n", + " pass" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 5 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [], + "language": "python", + "metadata": {}, + "outputs": [] + } + ], + "metadata": {} + } + ] +}
\ No newline at end of file diff --git a/C++_in_Action_-_Industrial-Strength_Programming_Techniques/ch9.ipynb b/C++_in_Action_-_Industrial-Strength_Programming_Techniques/ch9.ipynb new file mode 100755 index 00000000..35b80cf8 --- /dev/null +++ b/C++_in_Action_-_Industrial-Strength_Programming_Techniques/ch9.ipynb @@ -0,0 +1,248 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:bb23348ad3296a941665bd16b2187a89f9e17bfa05baf675e9a0cf4ac9ab49e8" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter Nine : Static Objects" + ] + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 9.1 page no : 97\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "def randomValue(seed):\n", + " oldValue = seed; # calculate new value\n", + " return oldValue\n", + " \n", + "print randomValue(5) " + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "5\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 9.2 page no : 97\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "class EmcSingleton:\n", + " def instance():\n", + " pass\n", + " \n", + " def create(i = 0):\n", + " self.instanceM = EmcSingleton(i)\n", + "\n", + " def __init__(self,i):\n", + " pass\n", + "\n" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 6 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 9.3 page no : 98\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "sccsid = \"@(#)myfile.cc\"\n", + "print sccsid" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "@(#)myfile.cc\n" + ] + } + ], + "prompt_number": 7 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 9.4 page no : 98\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "sccsid = \"@(#)myfile.cc\"\n", + "print sccsid" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "@(#)myfile.cc\n" + ] + } + ], + "prompt_number": 8 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 9.5 page no : 98\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "class EmcLog:\n", + " def __init__(self,out=None):\n", + " print \"Creating log\"\n", + "\n", + "t = EmcLog()" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Creating log\n" + ] + } + ], + "prompt_number": 10 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 9.6 page no : 100\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "sccsid = \"@(#)myfile.cc\"\n", + "release = \"@(#)Emc Class Library, 1.2\"\n", + "print sccsid, release" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "@(#)myfile.cc @(#)Emc Class Library, 1.2\n" + ] + } + ], + "prompt_number": 11 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "EXAMPLE 9.7 page no : 100\n" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "\n", + "\n", + "class EmcObject:\n", + " def __init__(self):\n", + " pass\n", + " \n", + " def __del__(self):\n", + " pass\n", + " \n", + " def initialize(self):\n", + " pass\n", + " \n", + " def finalize(self):\n", + " pass" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 12 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [], + "language": "python", + "metadata": {}, + "outputs": [] + } + ], + "metadata": {} + } + ] +}
\ No newline at end of file diff --git a/C++_in_Action_-_Industrial-Strength_Programming_Techniques/screenshots/error-handling.png b/C++_in_Action_-_Industrial-Strength_Programming_Techniques/screenshots/error-handling.png Binary files differnew file mode 100755 index 00000000..34176fe4 --- /dev/null +++ b/C++_in_Action_-_Industrial-Strength_Programming_Techniques/screenshots/error-handling.png diff --git a/C++_in_Action_-_Industrial-Strength_Programming_Techniques/screenshots/include-guard.png b/C++_in_Action_-_Industrial-Strength_Programming_Techniques/screenshots/include-guard.png Binary files differnew file mode 100755 index 00000000..f8e97ce5 --- /dev/null +++ b/C++_in_Action_-_Industrial-Strength_Programming_Techniques/screenshots/include-guard.png diff --git a/C++_in_Action_-_Industrial-Strength_Programming_Techniques/screenshots/inline-member.png b/C++_in_Action_-_Industrial-Strength_Programming_Techniques/screenshots/inline-member.png Binary files differnew file mode 100755 index 00000000..0d803671 --- /dev/null +++ b/C++_in_Action_-_Industrial-Strength_Programming_Techniques/screenshots/inline-member.png |