From 36a03d6d76bac315dba73b2ba9555c7e3fe0234f Mon Sep 17 00:00:00 2001 From: nice Date: Thu, 9 Oct 2014 18:07:00 +0530 Subject: updated books --- Structured_Programing_with_C++/Chapter1.ipynb | 104 ++++ Structured_Programing_with_C++/Chapter2.ipynb | 288 +++++++++ Structured_Programing_with_C++/Chapter3.ipynb | 540 ++++++++++++++++ Structured_Programing_with_C++/Chapter4.ipynb | 563 +++++++++++++++++ Structured_Programing_with_C++/Chapter5.ipynb | 745 +++++++++++++++++++++++ Structured_Programing_with_C++/Chapter6.ipynb | 549 +++++++++++++++++ Structured_Programing_with_C++/Chapter7.ipynb | 478 +++++++++++++++ Structured_Programing_with_C++/Chapter8.ipynb | 352 +++++++++++ Structured_Programing_with_C++/Chapter9.ipynb | 274 +++++++++ Structured_Programing_with_C++/README.txt | 10 + Structured_Programing_with_C++/screenshots/1.png | Bin 0 -> 52546 bytes Structured_Programing_with_C++/screenshots/2.png | Bin 0 -> 50577 bytes Structured_Programing_with_C++/screenshots/3.png | Bin 0 -> 75264 bytes 13 files changed, 3903 insertions(+) create mode 100755 Structured_Programing_with_C++/Chapter1.ipynb create mode 100755 Structured_Programing_with_C++/Chapter2.ipynb create mode 100755 Structured_Programing_with_C++/Chapter3.ipynb create mode 100755 Structured_Programing_with_C++/Chapter4.ipynb create mode 100755 Structured_Programing_with_C++/Chapter5.ipynb create mode 100755 Structured_Programing_with_C++/Chapter6.ipynb create mode 100755 Structured_Programing_with_C++/Chapter7.ipynb create mode 100755 Structured_Programing_with_C++/Chapter8.ipynb create mode 100755 Structured_Programing_with_C++/Chapter9.ipynb create mode 100755 Structured_Programing_with_C++/README.txt create mode 100755 Structured_Programing_with_C++/screenshots/1.png create mode 100755 Structured_Programing_with_C++/screenshots/2.png create mode 100755 Structured_Programing_with_C++/screenshots/3.png (limited to 'Structured_Programing_with_C++') diff --git a/Structured_Programing_with_C++/Chapter1.ipynb b/Structured_Programing_with_C++/Chapter1.ipynb new file mode 100755 index 00000000..4a8d6e2e --- /dev/null +++ b/Structured_Programing_with_C++/Chapter1.ipynb @@ -0,0 +1,104 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:c86efa8d98a193b995064bd56ef312e9a7c9cee5247409d33d46defcf953f275" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 1 : Introduction to Programming" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 1.1, Page No 21" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "print \"Hello world\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Hello world\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 1.2, Page No 22" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "dblPrice = float(raw_input(\"Enter Price Per Unit : \"))\n", + "iNo = int(raw_input(\"Enter Quantity : \"))\n", + "dblTotal = dblPrice * iNo\n", + "print \"The Total Price Is : %d\" % dblTotal " + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter Price Per Unit : 100\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter Quantity : 10\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The Total Price Is : 1000\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [], + "language": "python", + "metadata": {}, + "outputs": [] + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/Structured_Programing_with_C++/Chapter2.ipynb b/Structured_Programing_with_C++/Chapter2.ipynb new file mode 100755 index 00000000..d373f52c --- /dev/null +++ b/Structured_Programing_with_C++/Chapter2.ipynb @@ -0,0 +1,288 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:8f653af2e0b44c81d67d541bdc64870a18188d9d1a401e0b96b1b859a01ca59f" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapeter 2 : Variables" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 2.1, Page No 29" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "iNo = raw_input(\"Specify Quantity: \")\n", + "print iNo" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Specify Quantity: 10\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "10\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 2.2, Page No 31" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "iNo = raw_input(\"Specify Quantity: \")\n", + "print \"You entered\", iNo" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "specify quantity22\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "You entered 22\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 2.3, Page No 32" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "iNo = raw_input(\"specify quantity: \")\n", + "dPrice = raw_input(\"Specify unit Price: \")\n", + "print \"You entered the quantity \", iNo , \" and the price \" , dPrice" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "specify quantity: 5\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Specify unit Price: 12.45\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "You entered the quantity 5 and the price 12.45\n" + ] + } + ], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 2.4, Page No 36" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "dTaxPerc = 25.0\n", + "iNo = int(raw_input(\"Specify Quantity: \"))\n", + "dUnitPr = float(raw_input(\"Specify Unit Price: \"))\n", + "dPriceExTax = dUnitPr * iNo\n", + "dTax = dPriceExTax * dTaxPerc / 100\n", + "dCustPrice = dPriceExTax + dTax\n", + "print \"INVOICE\"\n", + "print \"========\"\n", + "print \"Quantity: \", iNo\n", + "print \"Price per Unit: \", dUnitPr\n", + "print \"Total Price: \", dCustPrice\n", + "print \"Tax: \",dTax" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Specify Quantity: 5\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Specify Unit Price: 12.4\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "INVOICE\n", + "========\n", + "Quantity: 5\n", + "Price per Unit: 12.4\n", + "Total Price: 77.5\n", + "Tax: 15.5\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 2.5, Page No 38" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "iNoOfSec = int(raw_input(\"Speicfy No. of Seconds: \"))\n", + "iNoOfMin = iNoOfSec / 60\n", + "iSecLeft = iNoOfSec % 60\n", + "iNoOfHours = iNoOfMin / 60\n", + "iMinLeft = iNoOfMin % 60\n", + "print \"Number of hours = \", iNoOfHours\n", + "print \"Number of Minutes = \", iNoOfMin\n", + "print \"Number of Seconds = \", iSecLeft" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Speicfy No. of Seconds: 10000\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Number of hours = 2\n", + "Number of Minutes = 166\n", + "Number of Seconds = 40\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 2.6, Page No 41" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import random\n", + "iNo = 5\n", + "iRoll1 = random.randint(0,100) % 6 + 1\n", + "iRoll2 = random.randint(0,100) % 6 + 1\n", + "iRoll3 = random.randint(0,100) % 6 + 1\n", + "iRoll4 = random.randint(0,100) % 6 + 1\n", + "iRoll5 = random.randint(0,100) % 6 + 1\n", + "dAverage = float(iRoll1 + iRoll2 + iRoll3 + iRoll4 + iRoll5) / iNo;\n", + "print \"Number of Rolls: \", iNo\n", + "print \"Average Score: \", dAverage" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Number of Rolls: 5\n", + "Average Score: 3.0\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [], + "language": "python", + "metadata": {}, + "outputs": [] + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/Structured_Programing_with_C++/Chapter3.ipynb b/Structured_Programing_with_C++/Chapter3.ipynb new file mode 100755 index 00000000..bca740d6 --- /dev/null +++ b/Structured_Programing_with_C++/Chapter3.ipynb @@ -0,0 +1,540 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:16d6a5d7a0f2261d7c4bbdc27385a261d6311ef3eb7e569b90710460f45fff6c" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 3 : Selections and Loops" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 3.1, Page No 48" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "dLimit = 500\n", + "iNo = int(raw_input(\"Specify Quantity : \"))\n", + "dUnitPrice = float(raw_input(\"Specify Unit Price : \"))\n", + "dGross = iNo * dUnitPrice\n", + "if(dGross > dLimit):\n", + " dDisc = 10\n", + "else:\n", + " dDisc = 0;\n", + "dNet = (100 - dDisc) * dGross / 100\n", + "print \"Total Price : %d\" % dNet" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Specify Quantity : 100\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Specify Unit Price : 10\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Total Price : 900\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 3.2, Page No 54" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "dNo1 = int(raw_input(\"Enter Number 1 : \"))\n", + "dNo2 = int(raw_input(\"Enter Number 2 : \"))\n", + "\n", + "print \"1. Greatest\"\n", + "print \"2. Least\"\n", + "print \"3. Average\"\n", + "\n", + "iOpt = int(raw_input(\"Select : \"))\n", + "\n", + "if iOpt == 1:\n", + " if dNo1 > dNo2:\n", + " print dNo1\n", + " else:\n", + " print dNo2\n", + " print \" is the greatest\"\n", + "elif iOpt == 2:\n", + " if dNo1 < dNo2:\n", + " print dNo1\n", + " else:\n", + " print dNo2\n", + " print \" is the least\"\n", + "elif iOpt == 3:\n", + " print \"The average is : \" , (dNo1 + dNo2)/2\n", + "else:\n", + " print \"wrong Choice\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter Number 1 : 10\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter Number 2 : 15\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "1. Greatest\n", + "2. Least\n", + "3. Average\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Select : 1\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "15\n", + " is the greatest\n" + ] + } + ], + "prompt_number": 6 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 3.3, Page No 58" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "iLimit = int(raw_input(\"Enter limit : \"))\n", + "iSum = 0\n", + "for i in range(1,iLimit+1):\n", + " iSum = iSum + i\n", + "\n", + "print \"The Sum Is : \" , iSum" + ], + "language": "python", + "metadata": {}, + "outputs": [] + }, + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Example 3.4, Page No 61" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "print \"Calculation Of Product\"\n", + "\n", + "for i in range(1,37):\n", + " for j in range(1,37):\n", + " if (i * j) == 36:\n", + " print i , \" and \" , j" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Calculation Of Product\n", + "1 and 36\n", + "2 and 18\n", + "3 and 12\n", + "4 and 9\n", + "6 and 6\n", + "9 and 4\n", + "12 and 3\n", + "18 and 2\n", + "36 and 1\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 3.5, Page No 62" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import random\n", + "\n", + "iRoll = 0\n", + "iNoOfRolls = 0\n", + "\n", + "while iRoll != 6:\n", + " iRoll = random.randint(1,200) % 6 + 1\n", + " iNoOfRolls = iNoOfRolls + 1\n", + "\n", + "print iNoOfRolls" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "8\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 3.6, Page No 63" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "# Do while concept is not in python thats way the program is implemented using WHILE\n", + "import random\n", + "\n", + "iRoll = 0\n", + "iNoOfRolls = 0\n", + "\n", + "while iRoll != 6:\n", + " iRoll = random.randint(1,200) % 6 +1\n", + " iNoOfRolls = iNoOfRolls + 1\n", + "\n", + "print iNoOfRolls" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "1\n" + ] + } + ], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 3.7, Page No 64" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import random\n", + "\n", + "iCounter = 0\n", + "iRoll1 = random.randint(1,200) % 6 + 1\n", + "iRoll2 = random.randint(1,200) % 6 + 1\n", + " \n", + "\n", + "while iRoll1 != iRoll2:\n", + " iRoll1 = random.randint(1,200) % 6 + 1\n", + " iRoll2 = random.randint(1,200) % 6 + 1\n", + " iCounter = iCounter + 1\n", + "\n", + "print \"The rolls were = \" , iRoll1\n", + "print \"Number of attempts = \" , iCounter" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The rolls were = 4\n", + "Number of attempts = 2\n" + ] + } + ], + "prompt_number": 9 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 3.8, Page No 64" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "iSum = 0\n", + "i = 0\n", + "iNo = raw_input(\"Enter a number : \")\n", + "\n", + "while iNo.isdigit():\n", + " iSum = iSum + int(iNo)\n", + " i = i + 1\n", + " iNo = raw_input(\"Enter one more number : \")\n", + "\n", + "print \"Average = \" , (float)((iSum)/i)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter a number : 4\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter one more number : 6\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter one more number : 5\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter one more number : c\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Average = 5.0\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 3.9, Page No 66" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import random\n", + "iNO = 0\n", + "for i in range(1,14):\n", + " iNo = random.randint(1,200) % 3\n", + " if iNo == 0:\n", + " print \"1\"\n", + " elif iNo == 1:\n", + " print \"X\"\n", + " elif iNO == 2:\n", + " print \"2\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "X\n", + "X\n", + "X\n", + "X\n", + "1\n", + "1\n", + "X\n", + "1\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 3.10, Page No 68" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "iNo = 0\n", + "iRoot = 1\n", + "while iNo < 2 and iRoot <=100:\n", + " LP = iRoot * (iRoot - 6) * (iRoot + 8)\n", + " if LP == 0:\n", + " iNo = iNo + 1\n", + " print iRoot\n", + " iRoot = iRoot + 1" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "6\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 3.11, Page No 69" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import math\n", + "\n", + "while 1 == 1:\n", + " dNo = int(raw_input(\"Enter a number : \"))\n", + " if dNo <= 0:\n", + " break\n", + " print \"The square root of the number is \",math.sqrt(dNo)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter a number : 100\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The square root of the number is 10.0\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter a number : 0\n" + ] + } + ], + "prompt_number": 4 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [], + "language": "python", + "metadata": {}, + "outputs": [] + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/Structured_Programing_with_C++/Chapter4.ipynb b/Structured_Programing_with_C++/Chapter4.ipynb new file mode 100755 index 00000000..aff2c5eb --- /dev/null +++ b/Structured_Programing_with_C++/Chapter4.ipynb @@ -0,0 +1,563 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:a27de4c3e22de467837d62cdd94a3b4f20a866984babfe11880e076feb1374ad" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 4 : Arrays" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 4.1, Page No 79" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Declarations\n", + "\n", + "iNoOfDays = 31\n", + "dSum = 0\n", + "dblTempApr=[[0 for col in range(31)] for row in range(31)]\n", + "\n", + "\n", + "#Entry and calculation\n", + "\n", + "for i in range(1,iNoOfDays):\n", + " dblTempApr[i] = raw_input(\"Temperature Day %d: \" % i)\n", + " dSum += dblTempApr[i]\n", + "\n", + "dAvg = dSum / iNoOfDays\n", + "\n", + "#Printout\n", + "\n", + "print \"Average temperature: %f\" % dAvg\n", + "print \"Temperatures exceeding average: \"\n", + "\n", + "for i in range(1,iNoOfDays):\n", + " if (dblTempApr[i] > dAvg):\n", + " print \"Day no.: %d\" % i,\n", + " print \" temp: %d\" % dblTempApr[i]" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Temperature Day 1: 32\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Temperature Day 2: 33\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Temperature Day 3: 35\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Temperature Day 4: 36\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Temperature Day 5: 34\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Temperature Day 6: 32\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Temperature Day 7: 31\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Temperature Day 8: 29\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Temperature Day 9: 28\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Temperature Day 10: 27\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Temperature Day 11: 25\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Temperature Day 12: 26\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Temperature Day 13: 35\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Temperature Day 14: 36\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Temperature Day 15: 35\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Temperature Day 16: 50\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Temperature Day 17: 40\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Temperature Day 18: 42\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Temperature Day 19: 44\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Temperature Day 20: 43\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Temperature Day 21: 41\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Temperature Day 22: 38\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Temperature Day 23: 37\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Temperature Day 24: 3\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Temperature Day 25: 36\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Temperature Day 26: 35\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Temperature Day 27: 45\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Temperature Day 28: 32\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Temperature Day 29: 21\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Temperature Day 30: 15\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Average temperature: 32.000000\n", + "Temperatures exceeding average: \n", + "Day no.: 2 temp: 33\n", + "Day no.: 3 temp: 35\n", + "Day no.: 4 temp: 36\n", + "Day no.: 5 temp: 34\n", + "Day no.: 13 temp: 35\n", + "Day no.: 14 temp: 36\n", + "Day no.: 15 temp: 35\n", + "Day no.: 16 temp: 50\n", + "Day no.: 17 temp: 40\n", + "Day no.: 18 temp: 42\n", + "Day no.: 19 temp: 44\n", + "Day no.: 20 temp: 43\n", + "Day no.: 21 temp: 41\n", + "Day no.: 22 temp: 38\n", + "Day no.: 23 temp: 37\n", + "Day no.: 25 temp: 36\n", + "Day no.: 26 temp: 35\n", + "Day no.: 27 temp: 45\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 4.2, Page No 83" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Declaration\n", + "\n", + "iMaxNo = 100\n", + "dLimit = 5000\n", + "perc1 = 0.1\n", + "perc2 = 0.15\n", + "sales = [[0 for col in range(1)] for row in range(iMaxNo)]\n", + "\n", + "#Initialize array\n", + "\n", + "for i in range(0,iMaxNo):\n", + " sales[i] = 0\n", + "\n", + "#Enter Salesman info\n", + "nr=input(\"Enter Salesman no. : \")\n", + "dAmount=input(\"Enter sales amount: \")\n", + "\n", + "while (nr and dAmount):\n", + " if(nr<1 or nr>iMaxNo or dAmount<0):\n", + " print \"Input error\"\n", + " break;\n", + " else:\n", + " sales[nr-1]+= dAmount\n", + " nr=int(raw_input(\"Enter Salesman no. : \"))\n", + " dAmount=float(raw_input(\"Enter sales amount: \"))\n", + "\n", + "#Print summary\n", + "\n", + "print \"Number Amount Fee\"\n", + "print \"====== ====== ===\"\n", + "\n", + "for i in range(0,iMaxNo):\n", + " if (sales[i] > 0):\n", + " if(sales[i] <= dLimit):\n", + " dFee = perc1 * sales[i]\n", + " else:\n", + " dFee = perc1 * dLimit + perc2*(sales[i] - dLimit)\n", + " j=i;\n", + " j=j+1;\n", + " print \"%4d\" % j,\n", + " print \"%13d\" % sales[i],\n", + " print \"%10.0f\" % dFee" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter Salesman no. : 1\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter sales amount: 1000\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter Salesman no. : 2\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter sales amount: 2000\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter Salesman no. : 3\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter sales amount: 3000\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter Salesman no. : 4\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter sales amount: 4000\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter Salesman no. : 5\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter sales amount: 5000\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter Salesman no. : 6\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter sales amount: 00\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Number Amount Fee\n", + "====== ====== ===\n", + " 1 1000 100\n", + " 2 2000 200\n", + " 3 3000 300\n", + " 4 4000 400\n", + " 5 5000 500\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 4.3, Page No 92" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Declaration\n", + "l=0\n", + "r=30\n", + "iFound=0\n", + "# Array is in sorted form\n", + "iProdid= [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31]\n", + "\n", + "iSrch = raw_input(\"Enter the searched product id: \")\n", + "\n", + "if(iSrch == iProdid[0]):\n", + " iPos = 0\n", + " iFound= 1\n", + "\n", + "if (iSrch == iProdid[30]):\n", + " iPos = 30\n", + " iFound = 1\n", + "\n", + "while not (iFound):\n", + " iMid = (int)(l + ((r-l)/2))\n", + " if(iSrch == iProdid[iMid]):\n", + " iFound = 1\n", + " iPos = iMid\n", + "\n", + " if(iSrch > iProdid[iMid]):\n", + " l=iMid\n", + " else:\n", + " r=iMid" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter the searched product id: 15\n" + ] + } + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [], + "language": "python", + "metadata": {}, + "outputs": [] + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/Structured_Programing_with_C++/Chapter5.ipynb b/Structured_Programing_with_C++/Chapter5.ipynb new file mode 100755 index 00000000..bf5b3697 --- /dev/null +++ b/Structured_Programing_with_C++/Chapter5.ipynb @@ -0,0 +1,745 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:708386728a0ddd9fd0fa033f85042eb5d454abc98a33806d4ca4cc0500a010f0" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 5 : Strings" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 5.1, Page No. 97" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "print \"Menu\"\n", + "print \"=====\"\n", + "print \"A. Order\"\n", + "print \"B. Invoice\"\n", + "print \"C. Warehouse\"\n", + "print \"D. Finance\"\n", + "cSel = raw_input(\"Select: \")\n", + "if cSel=='A' :\n", + " print \"You Selected Order\"\n", + "elif cSel=='B' :\n", + " print \"You Selected Invoice\"\n", + "elif cSel=='C':\n", + " print \"You Selected Warehouse\"\n", + "elif cSel=='D' :\n", + " print \"You Selected Finance\"\n", + "else :\n", + " print \"Erroneous Choice\"\n", + " " + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Menu\n", + "=====\n", + "A. Order\n", + "B. Invoice\n", + "C. Warehouse\n", + "D. Finance\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Select: A\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "You Selected Order\n" + ] + } + ], + "prompt_number": 6 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 5.2, Page No.99" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "cSal = 'A'\n", + "while cSal!='X':\n", + " print \"Menu\"\n", + " print \"=====\"\n", + " print \"A. Order\"\n", + " print \"B. Invoice\"\n", + " print \"C. Warehouse\"\n", + " print \"D. Finance\"\n", + " print \"X. Exit\"\n", + " cSel = raw_input(\"Select: \")\n", + "\n", + " \n", + " if cSel=='A' :\n", + " print \"You Selected Order\"\n", + " elif cSel=='B' :\n", + " print \"You Selected Invoice\"\n", + " elif cSel=='C':\n", + " print \"You Selected Warehouse\"\n", + " elif cSel=='D' :\n", + " print \"You Selected Finance\"\n", + " elif cSel=='X':\n", + " sys.exit()\n", + " else :\n", + " print \"Erroneous Choice\"\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Menu\n", + "=====\n", + "A. Order\n", + "B. Invoice\n", + "C. Warehouse\n", + "D. Finance\n", + "X. Exit\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Select: A\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "You Selected Order\n", + "Menu\n", + "=====\n", + "A. Order\n", + "B. Invoice\n", + "C. Warehouse\n", + "D. Finance\n", + "X. Exit\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Select: B\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "You Selected Invoice\n", + "Menu\n", + "=====\n", + "A. Order\n", + "B. Invoice\n", + "C. Warehouse\n", + "D. Finance\n", + "X. Exit\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Select: X\n" + ] + }, + { + "ename": "SystemExit", + "evalue": "", + "output_type": "pyerr", + "traceback": [ + "An exception has occurred, use %tb to see the full traceback.\n", + "\u001b[1;31mSystemExit\u001b[0m\n" + ] + }, + { + "output_type": "stream", + "stream": "stderr", + "text": [ + "To exit: use 'exit', 'quit', or Ctrl-D.\n" + ] + } + ], + "prompt_number": 8 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 5.3, Page No. 102" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "x = 'X' \n", + "blank = ' '\n", + "for i in range(10, -1, -1):\n", + " for j in range(i):\n", + " print blank,\n", + " print x,\n", + " for j in range(10-i):\n", + " print x, x,\n", + " print ''\n", + "for i in range(2):\n", + " for j in range(10):\n", + " print blank,\n", + " print x" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + " X \n", + " X X X \n", + " X X X X X \n", + " X X X X X X X \n", + " X X X X X X X X X \n", + " X X X X X X X X X X X \n", + " X X X X X X X X X X X X X \n", + " X X X X X X X X X X X X X X X \n", + " X X X X X X X X X X X X X X X X X \n", + " X X X X X X X X X X X X X X X X X X X \n", + "X X X X X X X X X X X X X X X X X X X X X \n", + " X\n", + " X\n" + ] + } + ], + "prompt_number": 21 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 5.4, Page No. 105" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import sys\n", + "cName = raw_input(\"Enter your name: \")\n", + "print \"Your name is \" , cName\n", + "print \"Your name is \" , len(cName), \" Characters long\"\n", + "print \"Your entire string is \" , sys.getsizeof(cName), \" characters long\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter your name: John Smith\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Your name is John Smith\n", + "Your name is 10 Characters long\n", + "Your entire string is 31 characters long\n" + ] + } + ], + "prompt_number": 22 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 5.5, Page No. 106" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "cName=range(30)\n", + "cName = raw_input(\"Enter your name in lower case: \")\n", + "iLen = len(cName)\n", + "for ltr in cName:\n", + " print ltr.lower(),\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter your name in lower case: ABCD\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "a b c d\n" + ] + } + ], + "prompt_number": 17 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 5.6, Page No. 107" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "cName = raw_input(\"Enter your name: \")\n", + "iLen = len(cName)\n", + "cInt = []\n", + "cInt.append(cName[0])\n", + "for i in range(1, iLen):\n", + " if cName[i] == ' ':\n", + " cInt.append(cName[i+1])\n", + "print \"Your Initials are \", ''.join(cInt)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter your name: Kjell Backman\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Your Initials are KB\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 5.7, Page No. 109" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "cName1 = raw_input(\"Enter a Name: \")\n", + "cName2 = raw_input(\"Enter another Name: \")\n", + "if cName1 > cName2 :\n", + " print cName1 , cName2\n", + "else :\n", + " print cName2 , cName1" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter a Name: abcd\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter another Name: abcx\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "abcx abcd\n" + ] + } + ], + "prompt_number": 33 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 5.8, Page No. 110" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "print \"Enter 5 names: \"\n", + "names = []\n", + "for i in range(5):\n", + " names.append(raw_input(\"name \" + str(i+1) + \": \"))\n", + "names.sort()\n", + "for i in range(5):\n", + " print names[i]" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter 5 names: \n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "name 1: hardik\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "name 2: Parth\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "name 3: Nikunj\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "name 4: Vaibhav\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "name 5: Chirag\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Chirag\n", + "Nikunj\n", + "Parth\n", + "Vaibhav\n", + "hardik\n" + ] + } + ], + "prompt_number": 7 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 5.9, Page No.113" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "cName = raw_input(\"Enter Your Name: \")\n", + "for i in range(29):\n", + " if cName[i] == ' ':\n", + " break\n", + "cFirst=cName[0:i]\n", + "print cFirst\n", + "cSur=cName[i+1:]\n", + "print cSur\n", + "cSur=cSur+\" \"\n", + "cSur=cSur+cFirst\n", + "print cSur\n", + "cSur=cSur[::-1]\n", + "print cSur" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter Your Name: John Smith\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "John\n", + "Smith\n", + "Smith John\n", + "nhoJ htimS\n" + ] + } + ], + "prompt_number": 10 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 5.10, Page No.115" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "cEncrypt = []\n", + "cName = []\n", + "cName = raw_input(\"Enter Your Name: \")\n", + "iLen = len(cName)\n", + "for i in range(iLen):\n", + " asc=ord(cName[i])\n", + " asc=asc+1\n", + " cEncrypt.append(chr(asc))\n", + "print ''.join(cEncrypt)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter Your Name: JohnSmith\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "KpioTnjui\n" + ] + } + ], + "prompt_number": 24 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 5.11, Page No. 116" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import random\n", + "iLen = random.randint(0,100)%3+5\n", + "cPw=[]\n", + "for i in range(iLen):\n", + " val=random.randint(0,122)%26+65\n", + " cPw.append(chr(val))\n", + "print ''.join(cPw)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "ZXZUOY\n" + ] + } + ], + "prompt_number": 37 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 5.12, Page No. 119" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "cText=[]\n", + "cEncrypt=[]\n", + "cTemp1=[]\n", + "cText=raw_input(\"\\nWrite a text in upper case: \")\n", + "iLen= len(cText)\n", + "for i in range(iLen):\n", + " print cText[i]\n", + " car=ord(cText[i])\n", + " cEncrypt.append(car)\n", + "print ''.join(str(cEncrypt))" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Write a text in upper case: hellow\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "h\n", + "e\n", + "l\n", + "l\n", + "o\n", + "w\n", + "[104, 101, 108, 108, 111, 119]\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "import random\n", + "cKey=\"ABCDEFGHIJKLMNOPQRSTUVWXYZ\"\n", + "cKey=list(cKey)\n", + "cEncrypt=range(50)\n", + "for i in range(26):\n", + " j=random.randint(0,100)%26\n", + " cTemp=cKey[i]\n", + " cKey[i]=cKey[j]\n", + " cKey[j]=cTemp\n", + "cKey=\"\".join(map(str,cKey))\n", + "cText=raw_input(\"\\nWrite a text in upper case: \")\n", + "iLen= len(cText)\n", + "for i in range(iLen):\n", + " cEncrypt[i]=cKey[ord(cText[i])-65]\n", + "cEncrypt=cEncrypt[::iLen]\n", + "print \"\".join(map(str,cEncrypt))" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "Write a text in upper case: JOHNSMITH\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "R918273645\n" + ] + } + ], + "prompt_number": 15 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [], + "language": "python", + "metadata": {}, + "outputs": [] + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/Structured_Programing_with_C++/Chapter6.ipynb b/Structured_Programing_with_C++/Chapter6.ipynb new file mode 100755 index 00000000..6ee5ccef --- /dev/null +++ b/Structured_Programing_with_C++/Chapter6.ipynb @@ -0,0 +1,549 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:3541583e6368ad0fd94057f7e595031de565be72b75fadedd8abb1168ccd2728" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 6 : Functions" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 6.1, Page No 126" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "def dAverage(x1,x2):\n", + " av = (x1+x2)/2\n", + " return av\n", + "\n", + "print \"Enter two numbers:\"\n", + "dNo1= float(raw_input(\"\"))\n", + "dNo2= float(raw_input(\"\"))\n", + "dAvg= dAverage(dNo1,dNo2)\n", + "print \"The average is: \",dAvg" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter two numbers:\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "30\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "20\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "The average is: 25.0\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 6.2, Page No 127" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "def min(x,y):\n", + " if (x1000):\n", + " return 0.15\n", + " elif(dLinePrice>500 or iQty>10):\n", + " return 0.10\n", + " else:\n", + " return 0\n", + "\n", + "def dPrice(iNo,dUnitPrice):\n", + " dTax=0.25\n", + " dLinePr=iNo*dUnitPrice\n", + " dDiscPerc=dDiscount(iNo,dLinePr)\n", + " return dLinePr*(1-dDiscPerc)*(1+dTax)\n", + "\n", + "print \"Enter quantity and unit price: \"\n", + "iQuantity=int(raw_input(\"\"))\n", + "dUnitPrice=float(raw_input(\"\"))\n", + "\n", + "print \"To be paid\", dPrice(iQuantity,dUnitPrice)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter quantity and unit price: \n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "30\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "50\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "To be paid 1593.75\n" + ] + } + ], + "prompt_number": 8 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 6.6, Page No 137" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "def replace1(s,c,cnew):\n", + " n=0\n", + " s = list(s)\n", + " while(s[n]!='\\0'):\n", + " if(s[n]==c):\n", + " s[n]=cnew\n", + " n=n+1\n", + " print \"\".join(map(str,s))\n", + "a=\"C:/Mydocumnets/Sheets\\0\"\n", + "print a\n", + "replace1(a,'/','-')" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "C:/Mydocumnets/Sheets\u0000\n", + "C:-Mydocumnets-Sheets\u0000\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 6.7, Page No 139" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "def word(s):\n", + " i=0\n", + " j=len(s)\n", + " while(i='a' and s[i]<='z')or(s[i]>='A' and s[i]<='Z')):\n", + " i=i+1\n", + " else:\n", + " return 0;\n", + " return 1;\n", + "\n", + "str=range(100)\n", + "str=raw_input(\"Enter word: \")\n", + "while(str):\n", + " if(word(str)):\n", + " print \"A word\"\n", + " else:\n", + " print \"No word\"\n", + " str=raw_input(\"Enter word: \")" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter word: john\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "A word\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter word: smith\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "A word\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter word: john smith\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "No word\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter word: \n" + ] + } + ], + "prompt_number": 9 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 6.8, Page No 143" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#import myfunc we have created this header file and its going to work as header file user has to make it\n", + "print \"To be paid: \" + str(dPrice(10,700))\n", + "\n", + "# Code for myfunc Header file is here\n", + "\n", + "\"\"\"\n", + "def underline(n):\n", + " for i in range(n):\n", + " print \"=\",\n", + "def dDiscount(iQty,dLinePrice):\n", + " if(dLinePrice > 1000):\n", + " return 0.15\n", + " elif(dLinePrice>500 or iQty>10):\n", + " return 0.10\n", + " else:\n", + " return 0\n", + "def dPrice(iNo,dUnitPrice):\n", + " dTax = 0.25\n", + " dLinePr = iNo * dUnitPrice\n", + " dDiscPerc = dDiscount(iNo,dLinePr)\n", + " return dLinePr * (1-dDiscPerc) * (1+dTax)\n", + "\"\"\"" + ], + "language": "python", + "metadata": {}, + "outputs": [] + } + ], + "metadata": {} + } + ] +} \ No newline at end of file diff --git a/Structured_Programing_with_C++/Chapter7.ipynb b/Structured_Programing_with_C++/Chapter7.ipynb new file mode 100755 index 00000000..c4850700 --- /dev/null +++ b/Structured_Programing_with_C++/Chapter7.ipynb @@ -0,0 +1,478 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:81ebacbcf46be2a85cdba0d8109c34324595901036a67c9025bbb5cab58aa894" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 7 : Files" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 7.1, Page No 157" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "outfile = open(\"prodfile1.txt\",\"w\")\n", + "cProd = raw_input(\"Enter product, (only Enter to exit:\")\n", + "while (len(cProd) > 0):\n", + " outfile.writelines(cProd)\n", + " outfile.writelines(\"\\n\")\n", + " cProd = raw_input(\"Enter product, (only Enter to exit:\")\n", + "outfile.close()" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter product, (only Enter to exit:wheel\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter product, (only Enter to exit:handlebars\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter product, (only Enter to exit:saddle\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter product, (only Enter to exit:bike\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter product, (only Enter to exit:moped\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter product, (only Enter to exit:\n" + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Examle 7.2 Page No 159" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "infile = open(\"prodfile1.txt\",\"r\")\n", + "while (1):\n", + " cProd = infile.readline()\n", + " if(cProd):\n", + " print cProd\n", + " else:\n", + " break\n", + "infile.close()" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "wheel\n", + "\n", + "handlebars\n", + "\n", + "saddle\n", + "\n", + "bike\n", + "\n", + "moped\n", + "\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 7.3, Page No 160" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "cProd = raw_input(\"Enter new product \")\n", + "outfile = open(\"prodfile.txt1\",\"a\")\n", + "outfile.writelines(cProd)\n", + "outfile.close() " + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter new product Spoke\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 7.4, Page No 161" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "iProdId = 1\n", + "outfile = open(\"prodfile.txt\",\"w\")\n", + "while (iProdId != 0):\n", + " iProdId = int(raw_input(\"Enter product id: \"))\n", + " dPrice = float(raw_input(\"...and price: \"))\n", + " if(iProdId > 0):\n", + " outfile.writelines(str(iProdId) + '\\n' + str(dPrice) + '\\n')\n", + "outfile.close()" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter product id: 2345\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "...and price: 245.5\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter product id: 4512\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "...and price: 450.2\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter product id: 3902\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "...and price: 320.7\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter product id: 2478\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "...and price: 75.9\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter product id: 0\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "...and price: 0\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 7.5, Page No 163" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "iFound = 0\n", + "infile = open(\"prodfile.txt\",\"r\")\n", + "iSrch = int(raw_input(\"Enter product id: \"))\n", + "while(1):\n", + " iProdId = infile.readline()\n", + " if(iProdId == \"\"):\n", + " break\n", + " iProdId = int(iProdId)\n", + " dPrice = float(infile.readline())\n", + " if(iProdId == iSrch):\n", + " print \"The price is:\" , dPrice\n", + " iFound = 1\n", + " break\n", + "if(not iFound):\n", + " print \"Product missing\"\n", + "infile.close()" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter product id: 1234\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Product missing\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 7.6, Page No 166" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "def sort(cList,n):\n", + " for v in range(0,n-1):\n", + " for h in range(v+1,n):\n", + " if(cList[h]