diff options
author | nice | 2014-10-09 18:07:00 +0530 |
---|---|---|
committer | nice | 2014-10-09 18:07:00 +0530 |
commit | 36a03d6d76bac315dba73b2ba9555c7e3fe0234f (patch) | |
tree | 7e46e8873a7c92be2eef962a36e664c775aa6bf2 /Structured_Programing_with_C++/Chapter8.ipynb | |
parent | b8bb8bbfa81499ad7fc3f3508be257da65f543af (diff) | |
download | Python-Textbook-Companions-36a03d6d76bac315dba73b2ba9555c7e3fe0234f.tar.gz Python-Textbook-Companions-36a03d6d76bac315dba73b2ba9555c7e3fe0234f.tar.bz2 Python-Textbook-Companions-36a03d6d76bac315dba73b2ba9555c7e3fe0234f.zip |
updated books
Diffstat (limited to 'Structured_Programing_with_C++/Chapter8.ipynb')
-rwxr-xr-x | Structured_Programing_with_C++/Chapter8.ipynb | 352 |
1 files changed, 352 insertions, 0 deletions
diff --git a/Structured_Programing_with_C++/Chapter8.ipynb b/Structured_Programing_with_C++/Chapter8.ipynb new file mode 100755 index 00000000..0d779089 --- /dev/null +++ b/Structured_Programing_with_C++/Chapter8.ipynb @@ -0,0 +1,352 @@ +{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:95ddab2248de9e7055a4dff19cd18b277d7ba7ab8ace5be6bff568b621024b03"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "\n",
+ "Chapter 8 : Pointers"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.1, Page No 179"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "from ctypes import *\n",
+ "\n",
+ "iNo=c_int\n",
+ "pNo = id(iNo)\n",
+ "dPrice=dTotal=float\n",
+ "pPrice=id(dPrice)\n",
+ "pTotal=id(dTotal)\n",
+ "cName=range(20)\n",
+ "pName=id(cName)\n",
+ "pName = raw_input(\"Enter your name: \")\n",
+ "pNo = int(raw_input(\"Enter quantity: \"))\n",
+ "pPrice = float(raw_input(\"and price: \"))\n",
+ "pTotal = pNo * pPrice\n",
+ "print \"Dear \" + pName + \", your price is \" + str(pTotal) + \" kr.\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter your name: chirag\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter quantity: 10\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "and price: 100\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Dear chirag, your price is 1000.0 kr.\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.2, Page No 182"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "iSal=[14000,15000,16000,17000,18000,19000]\n",
+ "pSal = id(iSal)\n",
+ "dTax=[0.32,0.34,0.35,0.36,0.365,0.37]\n",
+ "pTax=id(dTax)\n",
+ "print \"Salary Tax\"\n",
+ "for i in range(6):\n",
+ " print str(iSal[i])+\" \",str(iSal[i]*dTax[i])\n",
+ " i=i+1"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Salary Tax\n",
+ "14000 4480.0\n",
+ "15000 5100.0\n",
+ "16000 5600.0\n",
+ "17000 6120.0\n",
+ "18000 6570.0\n",
+ "19000 7030.0\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.3, Page No 185"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def find(s):\n",
+ " for p in range(len(s)):\n",
+ " if(s[p]=='@'):\n",
+ " print \"It is an email address\"\n",
+ " p=p+1\n",
+ "\n",
+ "#cString=range(9)\n",
+ "pString=id(cString)\n",
+ "cString=raw_input(\"Enter A text: \")\n",
+ "find(cString)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter A text: hello@gmail.com\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "It is an email address\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.4, Page No 188"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "iNumber=int(raw_input(\"How many product will be entered? \"))\n",
+ "\n",
+ "for i in range(iNumber):\n",
+ " pNo = id(iNumber)\n",
+ " print pNo\n",
+ " pNO = pNo + 1\n",
+ "pNo = pNo - iNumber\n",
+ "for i in range(iNumber):\n",
+ " print id(pNO)\n",
+ " pNo = pNO + 1\n",
+ "pNo = pNo - iNumber\n",
+ "del pNo "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "How many product will be entered? 5\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "3848360\n",
+ "3848360\n",
+ "3848360\n",
+ "3848360\n",
+ "3848360\n",
+ "51980880\n",
+ "51980880\n",
+ "51980880\n",
+ "51980880\n",
+ "51980880\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 8.5, Page No 189"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "iNo = 5\n",
+ "cName = range(iNo)\n",
+ "print \"Enter the name of 5 course mates: \"\n",
+ "for i in range(iNo):\n",
+ " print \"Mate no. \" ,i+1\n",
+ " temp = raw_input(\"Mate name: \")\n",
+ " cName.append(temp)\n",
+ "for j in range(iNo):\n",
+ " print cName[j]\n",
+ "for k in range(iNo):\n",
+ " del cName[k] "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter the name of 5 course mates: \n",
+ "Mate no. 1\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Mate name: a\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Mate no. 2\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Mate name: b\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Mate no. 3\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Mate name: c\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Mate no. 4\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Mate name: d\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Mate no. 5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Mate name: e\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "0\n",
+ "1\n",
+ "2\n",
+ "3\n",
+ "4\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+}
\ No newline at end of file |