From 83c1bfceb1b681b4bb7253b47491be2d8b2014a1 Mon Sep 17 00:00:00 2001 From: debashisdeb Date: Fri, 20 Jun 2014 15:42:42 +0530 Subject: removing problem statements --- Schaum's_Outlines_-_Programming_with_C++/ch9.ipynb | 220 ++++++++++++++++++--- 1 file changed, 189 insertions(+), 31 deletions(-) (limited to 'Schaum's_Outlines_-_Programming_with_C++/ch9.ipynb') diff --git a/Schaum's_Outlines_-_Programming_with_C++/ch9.ipynb b/Schaum's_Outlines_-_Programming_with_C++/ch9.ipynb index fabb9a56..d8825dca 100644 --- a/Schaum's_Outlines_-_Programming_with_C++/ch9.ipynb +++ b/Schaum's_Outlines_-_Programming_with_C++/ch9.ipynb @@ -1,6 +1,7 @@ { "metadata": { - "name": "ch9" + "name": "", + "signature": "sha256:3d283266e7082a716b1a943d213d074680f7742450c9d72e3e7e5a73a1856d5b" }, "nbformat": 3, "nbformat_minor": 0, @@ -10,7 +11,15 @@ { "cell_type": "code", "collapsed": false, - "input": "'''\nEXAMPLE 9.2 Using the Extraction Operation to Control a Loop\n'''\n\n\nwhile True:\n try:\n n = int(raw_input())\n print \"n = \" , n \n except:\n break", + "input": [ + "\n", + "while True:\n", + " try:\n", + " n = int(raw_input())\n", + " print \"n = \" , n \n", + " except:\n", + " break" + ], "language": "python", "metadata": {}, "outputs": [ @@ -18,62 +27,84 @@ "name": "stdout", "output_type": "stream", "stream": "stdout", - "text": "46\n" + "text": [ + "46\n" + ] }, { "output_type": "stream", "stream": "stdout", - "text": "n = 46\n" + "text": [ + "n = 46\n" + ] }, { "name": "stdout", "output_type": "stream", "stream": "stdout", - "text": "22\n" + "text": [ + "22\n" + ] }, { "output_type": "stream", "stream": "stdout", - "text": "n = 22\n" + "text": [ + "n = 22\n" + ] }, { "name": "stdout", "output_type": "stream", "stream": "stdout", - "text": "44\n" + "text": [ + "44\n" + ] }, { "output_type": "stream", "stream": "stdout", - "text": "n = 44\n" + "text": [ + "n = 44\n" + ] }, { "name": "stdout", "output_type": "stream", "stream": "stdout", - "text": "66\n" + "text": [ + "66\n" + ] }, { "output_type": "stream", "stream": "stdout", - "text": "n = 66\n" + "text": [ + "n = 66\n" + ] }, { "name": "stdout", "output_type": "stream", "stream": "stdout", - "text": "88\n" + "text": [ + "88\n" + ] }, { "output_type": "stream", "stream": "stdout", - "text": "n = 88\n" + "text": [ + "n = 88\n" + ] }, { "name": "stdout", "output_type": "stream", "stream": "stdout", - "text": "33,\n" + "text": [ + "33,\n" + ] } ], "prompt_number": 1 @@ -81,7 +112,20 @@ { "cell_type": "code", "collapsed": false, - "input": "'''\nEXAMPLE 9.4 Inputting Strings with the raw_input() Function\nThis program shows how to read text data line-by-line into an array \n'''\n\nking = [] # defines king to be an array \nn=0\nwhile True:\n name = raw_input()\n if len(name) < 1:\n break\n king.append(name)\n n += 1\n# now n == the number of names read\nfor i in range(n):\n print '\\t' , i+1 , \". \" , king[i] ", + "input": [ + "\n", + "king = [] # defines king to be an array \n", + "n=0\n", + "while True:\n", + " name = raw_input()\n", + " if len(name) < 1:\n", + " break\n", + " king.append(name)\n", + " n += 1\n", + "# now n == the number of names read\n", + "for i in range(n):\n", + " print '\\t' , i+1 , \". \" , king[i] " + ], "language": "python", "metadata": {}, "outputs": [ @@ -89,60 +133,87 @@ "name": "stdout", "output_type": "stream", "stream": "stdout", - "text": "Kenneth II (971-995)\n" + "text": [ + "Kenneth II (971-995)\n" + ] }, { "name": "stdout", "output_type": "stream", "stream": "stdout", - "text": "Constantine III (995-997)\n" + "text": [ + "Constantine III (995-997)\n" + ] }, { "name": "stdout", "output_type": "stream", "stream": "stdout", - "text": "Kenneth III (997-1005)\n" + "text": [ + "Kenneth III (997-1005)\n" + ] }, { "name": "stdout", "output_type": "stream", "stream": "stdout", - "text": "Malcolm II (1005-1034)\n" + "text": [ + "Malcolm II (1005-1034)\n" + ] }, { "name": "stdout", "output_type": "stream", "stream": "stdout", - "text": "Duncan I (1034-1040)\n" + "text": [ + "Duncan I (1034-1040)\n" + ] }, { "name": "stdout", "output_type": "stream", "stream": "stdout", - "text": "Macbeth (1040-1057)\n" + "text": [ + "Macbeth (1040-1057)\n" + ] }, { "name": "stdout", "output_type": "stream", "stream": "stdout", - "text": "Lulach (1057-1058)\n" + "text": [ + "Lulach (1057-1058)\n" + ] }, { "name": "stdout", "output_type": "stream", "stream": "stdout", - "text": "Malcolm III (1058-1093)\n" + "text": [ + "Malcolm III (1058-1093)\n" + ] }, { "name": "stdout", "output_type": "stream", "stream": "stdout", - "text": "\n" + "text": [ + "\n" + ] }, { "output_type": "stream", "stream": "stdout", - "text": "\t1 . Kenneth II (971-995)\n\t2 . Constantine III (995-997)\n\t3 . Kenneth III (997-1005)\n\t4 . Malcolm II (1005-1034)\n\t5 . Duncan I (1034-1040)\n\t6 . Macbeth (1040-1057)\n\t7 . Lulach (1057-1058)\n\t8 . Malcolm III (1058-1093)\n" + "text": [ + "\t1 . Kenneth II (971-995)\n", + "\t2 . Constantine III (995-997)\n", + "\t3 . Kenneth III (997-1005)\n", + "\t4 . Malcolm II (1005-1034)\n", + "\t5 . Duncan I (1034-1040)\n", + "\t6 . Macbeth (1040-1057)\n", + "\t7 . Lulach (1057-1058)\n", + "\t8 . Malcolm III (1058-1093)\n" + ] } ], "prompt_number": 2 @@ -150,7 +221,18 @@ { "cell_type": "code", "collapsed": false, - "input": "'''\nEXAMPLE 9.6 Capitalizing All the Words in a Text File\nHere is a complete program that reads words from the external file named input.txt, capitalizes\nthem, and then writes them to the external file named output.txt:\nNote : Working good , you need input.txt in same directory.\n'''\n\ninfile = open(\"input.txt\",\"r\")\noutfile = open(\"output.txt\",\"w\")\n\nfor i in infile:\n s = i.title()\n outfile.write(s)\n\ninfile.close()\noutfile.close()", + "input": [ + "\n", + "infile = open(\"input.txt\",\"r\")\n", + "outfile = open(\"output.txt\",\"w\")\n", + "\n", + "for i in infile:\n", + " s = i.title()\n", + " outfile.write(s)\n", + "\n", + "infile.close()\n", + "outfile.close()" + ], "language": "python", "metadata": {}, "outputs": [ @@ -170,7 +252,38 @@ { "cell_type": "code", "collapsed": false, - "input": "'''\nEXAMPLE 9.7 Merging Two Sorted Data Files\n'''\n\nfin1 = open(\"north.dat\",\"r\")\nfin2 = open(\"south.dat\",\"r\")\nfout = open(\"combined.dat\",\"w\")\n\nfile1 = []\nfile2 = []\nfor i in fin1:\n try:\n s = i.split(\" \")\n for j in s:\n file1.append(int(j))\n except:\n continue\n \nfor i in fin2:\n try:\n s = i.split(\" \")\n for j in s:\n file2.append(int(j))\n except:\n continue\n\n\nfor i in sorted(file1 + file2):\n fout.write(str(i) + \" \")\n\nfin1.close()\nfin2.close()\nfout.close()", + "input": [ + "\n", + "fin1 = open(\"north.dat\",\"r\")\n", + "fin2 = open(\"south.dat\",\"r\")\n", + "fout = open(\"combined.dat\",\"w\")\n", + "\n", + "file1 = []\n", + "file2 = []\n", + "for i in fin1:\n", + " try:\n", + " s = i.split(\" \")\n", + " for j in s:\n", + " file1.append(int(j))\n", + " except:\n", + " continue\n", + " \n", + "for i in fin2:\n", + " try:\n", + " s = i.split(\" \")\n", + " for j in s:\n", + " file2.append(int(j))\n", + " except:\n", + " continue\n", + "\n", + "\n", + "for i in sorted(file1 + file2):\n", + " fout.write(str(i) + \" \")\n", + "\n", + "fin1.close()\n", + "fin2.close()\n", + "fout.close()" + ], "language": "python", "metadata": {}, "outputs": [ @@ -190,14 +303,35 @@ { "cell_type": "code", "collapsed": false, - "input": "'''\nEXAMPLE 9.8 Using an Output String Stream\nThis program creates four objects: a character string s,\nan integer n, a floating-point number x, and an output string stream oss:\n'''\n\ndef print_(oss):\n print 'oss.str() = \"' , str(oss) , '\"'\n\ns=\"ABCDEFG\"\nn=33\nx=2.718\nl = ''\nprint_(l)\nl += s\nprint_(l)\nl += ( \" \" + str(n) )\nprint_(l)\nl += ( \" \" + str(x) )\nprint_(l)", + "input": [ + "\n", + "def print_(oss):\n", + " print 'oss.str() = \"' , str(oss) , '\"'\n", + "\n", + "s=\"ABCDEFG\"\n", + "n=33\n", + "x=2.718\n", + "l = ''\n", + "print_(l)\n", + "l += s\n", + "print_(l)\n", + "l += ( \" \" + str(n) )\n", + "print_(l)\n", + "l += ( \" \" + str(x) )\n", + "print_(l)" + ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", - "text": "oss.str() = \" \"\noss.str() = \" ABCDEFG \"\noss.str() = \" ABCDEFG 33 \"\noss.str() = \" ABCDEFG 33 2.718 \"\n" + "text": [ + "oss.str() = \" \"\n", + "oss.str() = \" ABCDEFG \"\n", + "oss.str() = \" ABCDEFG 33 \"\n", + "oss.str() = \" ABCDEFG 33 2.718 \"\n" + ] } ], "prompt_number": 5 @@ -205,14 +339,38 @@ { "cell_type": "code", "collapsed": false, - "input": "'''\nEXAMPLE 9.9 Using an Input String Stream iss ABCDEFG 44 3.14 istringstream\nThis program is similar to the one in Example 9.8 \nexcept that it reads from an input string stream iss\ninstead of writing to an output string stream.:\n'''\n'''\nEXAMPLE 9.8 Using an Output String Stream\nThis program creates four objects: a character string s,\nan integer n, a floating-point number x, and an output string stream oss:\n'''\n\ndef print_(iss,s='',n=0,x=0.0):\n print 's = \"' , s , '\", n = ' , n , \", x = \" , x, ', iss.str() = \"' \\\n , iss , '\"' \n\ns=\"\"\nn=0\nx=0.0\nl = ''\niss = \"ABCDEFG 44 3.14\"\nprint_(iss)\ns = \"ABCDEFG\"\nprint_(iss,s)\nn = 44\nprint_(iss,s,n)\nx = 3.14\nprint_(iss,s,n,x)", + "input": [ + "\n", + "\n", + "def print_(iss,s='',n=0,x=0.0):\n", + " print 's = \"' , s , '\", n = ' , n , \", x = \" , x, ', iss.str() = \"' \\\n", + " , iss , '\"' \n", + "\n", + "s=\"\"\n", + "n=0\n", + "x=0.0\n", + "l = ''\n", + "iss = \"ABCDEFG 44 3.14\"\n", + "print_(iss)\n", + "s = \"ABCDEFG\"\n", + "print_(iss,s)\n", + "n = 44\n", + "print_(iss,s,n)\n", + "x = 3.14\n", + "print_(iss,s,n,x)" + ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", - "text": "s = \" \", n = 0 , x = 0.0 , iss.str() = \" ABCDEFG 44 3.14 \"\ns = \" ABCDEFG \", n = 0 , x = 0.0 , iss.str() = \" ABCDEFG 44 3.14 \"\ns = \" ABCDEFG \", n = 44 , x = 0.0 , iss.str() = \" ABCDEFG 44 3.14 \"\ns = \" ABCDEFG \", n = 44 , x = 3.14 , iss.str() = \" ABCDEFG 44 3.14 \"\n" + "text": [ + "s = \" \", n = 0 , x = 0.0 , iss.str() = \" ABCDEFG 44 3.14 \"\n", + "s = \" ABCDEFG \", n = 0 , x = 0.0 , iss.str() = \" ABCDEFG 44 3.14 \"\n", + "s = \" ABCDEFG \", n = 44 , x = 0.0 , iss.str() = \" ABCDEFG 44 3.14 \"\n", + "s = \" ABCDEFG \", n = 44 , x = 3.14 , iss.str() = \" ABCDEFG 44 3.14 \"\n" + ] } ], "prompt_number": 6 @@ -220,7 +378,7 @@ { "cell_type": "code", "collapsed": false, - "input": "", + "input": [], "language": "python", "metadata": {}, "outputs": [] -- cgit