diff options
Diffstat (limited to 'Beginning_C++_through_Game_Programming/ch8.ipynb')
-rwxr-xr-x | Beginning_C++_through_Game_Programming/ch8.ipynb | 239 |
1 files changed, 0 insertions, 239 deletions
diff --git a/Beginning_C++_through_Game_Programming/ch8.ipynb b/Beginning_C++_through_Game_Programming/ch8.ipynb deleted file mode 100755 index 75cf53be..00000000 --- a/Beginning_C++_through_Game_Programming/ch8.ipynb +++ /dev/null @@ -1,239 +0,0 @@ -{ - "metadata": { - "name": "ch8" - }, - "nbformat": 3, - "nbformat_minor": 0, - "worksheets": [ - { - "cells": [ - { - "cell_type": "heading", - "level": 1, - "metadata": {}, - "source": "Chapter 8 : Structures" - }, - { - "cell_type": "heading", - "level": 3, - "metadata": {}, - "source": "example 8.1 page no :77\n" - }, - { - "cell_type": "code", - "collapsed": false, - "input": "'''\nexample 8.1 page no :77\n'''\n\nclass Point:\n def __init__(self):\n self.x = 0.0\n self.y = 0.0\n\n\nb = Point()\nb.x = 3.0\nb.y = 4.0\n\nprint b.x , \", \" , b.y \ndistance = b.x * b.x + b.y * b.y\nprint \"Distance : \" , distance", - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": "3.0 , 4.0\nDistance : 25.0\n" - } - ], - "prompt_number": 1 - }, - { - "cell_type": "heading", - "level": 3, - "metadata": {}, - "source": "example 8.2 page no :79\n" - }, - { - "cell_type": "code", - "collapsed": false, - "input": "'''\nexample 8.2 page no :79\n'''\n\nclass Point:\n def __init__(self,x,y):\n self.x = x\n self.y = y\n\np1 = Point(3.0, 4.0)\np2 = p1\nprint p2.x , \", \" , p2.y ", - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": "3.0 , 4.0\n" - } - ], - "prompt_number": 2 - }, - { - "cell_type": "heading", - "level": 3, - "metadata": {}, - "source": "example 8.3 page no : 80\n" - }, - { - "cell_type": "code", - "collapsed": false, - "input": "'''\nexample 8.3 page no : 80\n'''\n\nclass Point:\n def __init__(self,x,y):\n self.x = x\n self.y = y\n\ndef printPoint(p):\n print \"(\" , p.x , \", \" , p.y , \")\" \n \np1 = Point(3.0, 4.0)\nprintPoint(p1)", - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": "( 3.0 , 4.0 )\n" - } - ], - "prompt_number": 3 - }, - { - "cell_type": "heading", - "level": 3, - "metadata": {}, - "source": "example 8.4 page no : 80\n" - }, - { - "cell_type": "code", - "collapsed": false, - "input": "'''\nexample 8.4 page no : 80\n'''\n\n\nclass Point:\n def __init__(self,x,y):\n self.x = x\n self.y = y\n\ndef distance(p1,p2):\n dx = p2.x - p1.x\n dy = p2.y - p1.y\n import math\n return math.sqrt(dx*dx + dy*dy)\n \np1 = Point(3.0, 4.0)\np2 = Point(4.0,5.0)\nprint distance(p1,p2)", - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": "1.41421356237\n" - } - ], - "prompt_number": 4 - }, - { - "cell_type": "heading", - "level": 3, - "metadata": {}, - "source": "example 8.5 page no : 81\n" - }, - { - "cell_type": "code", - "collapsed": false, - "input": "'''\nexample 8.5 page no : 81\n'''\nclass Point:\n def __init__(self,x,y):\n self.x = x\n self.y = y\n\ndef reflect(p):\n temp = p.x\n p.x = p.y\n p.y = temp\n\ndef printPoint(p):\n print \"(\" , p.x , \", \" , p.y , \")\" \n\nblank = Point(3.0, 4.0)\nprintPoint (blank)\nreflect (blank)\nprintPoint (blank)", - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": "( 3.0 , 4.0 )\n( 4.0 , 3.0 )\n" - } - ], - "prompt_number": 5 - }, - { - "cell_type": "heading", - "level": 3, - "metadata": {}, - "source": "example 8.6 page no : 84\n" - }, - { - "cell_type": "code", - "collapsed": false, - "input": "'''\nexample 8.6 page no : 84\n'''\n\nclass Point:\n def __init__(self,x,y):\n self.x = x\n self.y = y\n\nclass Rectangle:\n def __init__(self,p,x,y):\n self.corner = p\n self.width = x\n self.height = y\n\nc = Point(0.0, 0.0)\nb = Rectangle( c, 100.0, 200.0 )\nb.width += 50.0\nprint b.height ", - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": "200.0\n" - } - ], - "prompt_number": 6 - }, - { - "cell_type": "heading", - "level": 3, - "metadata": {}, - "source": "example 8.7 page no : 84\n" - }, - { - "cell_type": "code", - "collapsed": false, - "input": "'''\nexample 8.7 page no : 84\n'''\n\n\nclass Point:\n def __init__(self,x,y):\n self.x = x\n self.y = y\n\nclass Rectangle:\n def __init__(self,p,x,y):\n self.corner = p\n self.width = x\n self.height = y\n\ndef findCenter(box):\n x = box.corner.x + box.width/2\n y = box.corner.y + box.height/2\n result = Point(x, y)\n return result\n\ndef printPoint(p):\n print \"(\" , p.x , \", \" , p.y , \")\" \n\nbox = Rectangle( Point(0.0, 0.0), 100, 200)\ncenter = findCenter (box);\nprintPoint (center);", - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": "( 50.0 , 100.0 )\n" - } - ], - "prompt_number": 7 - }, - { - "cell_type": "heading", - "level": 3, - "metadata": {}, - "source": "example 8.8 page no : 84\n" - }, - { - "cell_type": "code", - "collapsed": false, - "input": "'''\nexample 8.8 page no : 84\n'''\n\ndef swap(x,y):\n temp = x[0]\n x[0] = y[0]\n y[0] = temp\n\ni = [7]\nj = [9]\nswap (i, j)\nprint i[0] , j[0]", - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": "9 7\n" - } - ], - "prompt_number": 8 - }, - { - "cell_type": "heading", - "level": 3, - "metadata": {}, - "source": "example 8.9 page no : 85\n" - }, - { - "cell_type": "code", - "collapsed": false, - "input": "'''\nexample 8.9 page no : 85\n'''\n\n# prompt the user for input86\nprint \"Enter an integer: \",\n# get input\ntry:\n x = int(raw_input())\n print x \n# check and see if the input statement succeeded\nexcept:\n print \"That was not an integer.\" \n\n# print the value we got from the user\n\nprint \"What is your name? \" , \nname = raw_input()\nprint name", - "language": "python", - "metadata": {}, - "outputs": [ - { - "output_type": "stream", - "stream": "stdout", - "text": "Enter an integer: " - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": "a\n" - }, - { - "output_type": "stream", - "stream": "stdout", - "text": " That was not an integer.\nWhat is your name? " - }, - { - "name": "stdout", - "output_type": "stream", - "stream": "stdout", - "text": "abc\n" - }, - { - "output_type": "stream", - "stream": "stdout", - "text": " abc\n" - } - ], - "prompt_number": 11 - }, - { - "cell_type": "code", - "collapsed": false, - "input": "", - "language": "python", - "metadata": {}, - "outputs": [] - } - ], - "metadata": {} - } - ] -}
\ No newline at end of file |