summaryrefslogtreecommitdiff
path: root/Schaum's_Outlines_-_Programming_with_C++/ch14.ipynb
diff options
context:
space:
mode:
authorJovina Dsouza2014-06-18 13:08:52 +0530
committerJovina Dsouza2014-06-18 13:08:52 +0530
commita78126bbe4443e9526a64df9d8245c4af8843044 (patch)
treeec84778a693a93a076d64803afbe814b8f5c99be /Schaum's_Outlines_-_Programming_with_C++/ch14.ipynb
parent206d0358703aa05d5d7315900fe1d054c2817ddc (diff)
downloadPython-Textbook-Companions-a78126bbe4443e9526a64df9d8245c4af8843044.tar.gz
Python-Textbook-Companions-a78126bbe4443e9526a64df9d8245c4af8843044.tar.bz2
Python-Textbook-Companions-a78126bbe4443e9526a64df9d8245c4af8843044.zip
adding book
Diffstat (limited to 'Schaum's_Outlines_-_Programming_with_C++/ch14.ipynb')
-rw-r--r--Schaum's_Outlines_-_Programming_with_C++/ch14.ipynb172
1 files changed, 172 insertions, 0 deletions
diff --git a/Schaum's_Outlines_-_Programming_with_C++/ch14.ipynb b/Schaum's_Outlines_-_Programming_with_C++/ch14.ipynb
new file mode 100644
index 00000000..1618010d
--- /dev/null
+++ b/Schaum's_Outlines_-_Programming_with_C++/ch14.ipynb
@@ -0,0 +1,172 @@
+{
+ "metadata": {
+ "name": "ch14"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "'''\nEXAMPLE 14.1 Using a vector of strings\n'''\n\ndef load(v):\n v.append(\"Japan\")\n v.append(\"Italy\")\n v.append(\"Spain\")\n v.append(\"Egypt\")\n v.append(\"Chile\")\n v.append(\"Zaire\")\n v.append(\"Nepal\")\n v.append(\"Kenya\")\n\ndef print_(v):\n for i in v:\n print i\n\nv = []\nload(v)\nprint_(v)",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "Japan\nItaly\nSpain\nEgypt\nChile\nZaire\nNepal\nKenya\n"
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "'''\nEXAMPLE 14.2 \n'''\n\ndef load(v):\n v.append(\"Japan\")\n v.append(\"Italy\")\n v.append(\"Spain\")\n v.append(\"Egypt\")\n v.append(\"Chile\")\n v.append(\"Zaire\")\n v.append(\"Nepal\")\n v.append(\"Kenya\")\n\ndef print_(v):\n for i in v:\n print i\n\nv = []\nload(v)\nprint_(v)",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "Japan\nItaly\nSpain\nEgypt\nChile\nZaire\nNepal\nKenya\n"
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "'''\nEXAMPLE 14.3 \n'''\n\ndef load(v):\n v.append(\"Japan\")\n v.append(\"Italy\")\n v.append(\"Spain\")\n v.append(\"Egypt\")\n v.append(\"Chile\")\n v.append(\"Zaire\")\n v.append(\"Nepal\")\n v.append(\"Kenya\")\n\ndef print_(v):\n for i in range(len(v)):\n print v[i]\n\nv = []\nload(v)\nprint_(v)",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "Japan\nItaly\nSpain\nEgypt\nChile\nZaire\nNepal\nKenya\n"
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "'''\nEXAMPLE 14.4 Using the Generic sort() Algorithm\n'''\n\n\ndef load(v):\n v.append(\"Japan\")\n v.append(\"Italy\")\n v.append(\"Spain\")\n v.append(\"Egypt\")\n v.append(\"Chile\")\n v.append(\"Zaire\")\n v.append(\"Nepal\")\n v.append(\"Kenya\")\n\ndef print_(v):\n for i in v:\n print i\n\nv = []\nload(v)\nv.sort()\nprint_(v)\n",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "Chile\nEgypt\nItaly\nJapan\nKenya\nNepal\nSpain\nZaire\n"
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "'''\nEXAMPLE 14.5 Using the Assignment Operator to Duplicate a vector\n'''\n#This program demonstrates that one vector can be assigned to another.\n\n\n\ndef load(v):\n v.append(\"Japan\")\n v.append(\"Italy\")\n v.append(\"Spain\")\n v.append(\"Egypt\")\n v.append(\"Chile\")\n v.append(\"Zaire\")\n v.append(\"Nepal\")\n v.append(\"Kenya\")\n\ndef print_(v):\n for i in v:\n print i\n\nv = []\nload(v)\nw = v\nprint_(v)\nprint_(w)",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "Japan\nItaly\nSpain\nEgypt\nChile\nZaire\nNepal\nKenya\nJapan\nItaly\nSpain\nEgypt\nChile\nZaire\nNepal\nKenya\n"
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "'''\nEXAMPLE 14.6 \n'''\n\ndef load(v):\n v.append(\"Japan\")\n v.append(\"Italy\")\n v.append(\"Spain\")\n v.append(\"Egypt\")\n v.append(\"Chile\")\n v.append(\"Zaire\")\n v.append(\"Nepal\")\n v.append(\"Kenya\")\n\ndef print_(v):\n for i in v:\n print i\n\nv = []\nload(v)\nv.sort()\nprint_(v)\nprint \"v.front() = \" + v[0]\nprint \"v.back() = \" + v.pop(-1) \nprint \"v.back() = \" + v.pop(-1) \nprint \"v.back() = \" + v[-1] \nprint_(v)",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "Chile\nEgypt\nItaly\nJapan\nKenya\nNepal\nSpain\nZaire\nv.front() = Chile\nv.back() = Zaire\nv.back() = Spain\nv.back() = Nepal\nChile\nEgypt\nItaly\nJapan\nKenya\nNepal\n"
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "'''\nEXAMPLE 14.7 Using the erase() Function\n'''\n\ndef load(v):\n v.append(\"Japan\")\n v.append(\"Italy\")\n v.append(\"Spain\")\n v.append(\"Egypt\")\n v.append(\"Chile\")\n v.append(\"Zaire\")\n v.append(\"Nepal\")\n v.append(\"Kenya\")\n\ndef print_(v):\n for i in v:\n print i\n\nv = []\nload(v)\nv.sort()\nprint_(v)\nv.pop(2) # removes Italy\nv.pop(-2) # removes Spain\nprint_(v)",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "Chile\nEgypt\nItaly\nJapan\nKenya\nNepal\nSpain\nZaire\nChile\nEgypt\nJapan\nKenya\nNepal\nZaire\n"
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "'''\nEXAMPLE 14.8 Using the insert() Function\n'''\ndef load(v):\n v.append(\"Japan\")\n v.append(\"Italy\")\n v.append(\"Spain\")\n v.append(\"Egypt\")\n v.append(\"Chile\")\n v.append(\"Zaire\")\n v.append(\"Nepal\")\n v.append(\"Kenya\")\n\ndef print_(v):\n for i in v:\n print i\nv = []\nload(v)\nv.sort()\nprint_(v)\nr = []\nfor i in range(2,len(v)-2):\n r.append(v[i]) #removes the segment Italy..Nepal\n \nfor i in r:\n v.remove(i)\nprint_(v)\nv.insert(2,\"India\")\nprint_(v)",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "Chile\nEgypt\nItaly\nJapan\nKenya\nNepal\nSpain\nZaire\nChile\nEgypt\nSpain\nZaire\nChile\nEgypt\nIndia\nSpain\nZaire\n"
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "'''\nEXAMPLE 14.9 Using the find() Function\n'''\n\ndef load(v):\n v.append(\"Japan\")\n v.append(\"Italy\")\n v.append(\"Spain\")\n v.append(\"Egypt\")\n v.append(\"Chile\")\n v.append(\"Zaire\")\n v.append(\"Nepal\")\n v.append(\"Kenya\")\n v.append(\"India\")\n v.append(\"China\")\n v.append(\"Malta\")\n v.append(\"Syria\")\n\ndef print_(v):\n for i in v:\n print i\n\nv = []\nload(v)\nprint_(v)\negypt = v.index('Egypt')\nmalta = v.index('Malta')\nw = v[egypt:malta+1]\nw.sort()\nprint_(w)",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "Japan\nItaly\nSpain\nEgypt\nChile\nZaire\nNepal\nKenya\nIndia\nChina\nMalta\nSyria\nChile\nChina\nEgypt\nIndia\nKenya\nMalta\nNepal\nZaire\n"
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "'''\nEXAMPLE 14.10\n'''\ndef copy(v,x,n):\n for i in x:\n v.append(i)\n\ndef projection(v,b):\n v_size = len(v)\n w = []\n for i in range(0,v_size):\n if b[i]:\n w.append(v[i])\n return w\n\ndef print_(v):\n for i in v:\n print i,\n print ''\n\nx = [ 22.2, 33.3, 44.4, 55.5, 66.6, 77.7, 88.8, 99.9 ]\nv = []\ncopy(v, x, 8)\ny = [ False, True, False, True, True, True, False, True ]\nb = []\ncopy(b, y, 8)\nw = projection(v, b)\nprint_(v)\nprint_(w)",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "22.2 33.3 44.4 55.5 66.6 77.7 88.8 99.9 \n33.3 55.5 66.6 77.7 99.9 \n"
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "",
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file