summaryrefslogtreecommitdiff
path: root/C++_from_the_Ground/Chapter_22(1).ipynb
diff options
context:
space:
mode:
authordebashisdeb2014-06-20 15:42:42 +0530
committerdebashisdeb2014-06-20 15:42:42 +0530
commit83c1bfceb1b681b4bb7253b47491be2d8b2014a1 (patch)
treef54eab21dd3d725d64a495fcd47c00d37abed004 /C++_from_the_Ground/Chapter_22(1).ipynb
parenta78126bbe4443e9526a64df9d8245c4af8843044 (diff)
downloadPython-Textbook-Companions-83c1bfceb1b681b4bb7253b47491be2d8b2014a1.tar.gz
Python-Textbook-Companions-83c1bfceb1b681b4bb7253b47491be2d8b2014a1.tar.bz2
Python-Textbook-Companions-83c1bfceb1b681b4bb7253b47491be2d8b2014a1.zip
removing problem statements
Diffstat (limited to 'C++_from_the_Ground/Chapter_22(1).ipynb')
-rw-r--r--C++_from_the_Ground/Chapter_22(1).ipynb201
1 files changed, 171 insertions, 30 deletions
diff --git a/C++_from_the_Ground/Chapter_22(1).ipynb b/C++_from_the_Ground/Chapter_22(1).ipynb
index 83be7161..8c26974a 100644
--- a/C++_from_the_Ground/Chapter_22(1).ipynb
+++ b/C++_from_the_Ground/Chapter_22(1).ipynb
@@ -1,6 +1,7 @@
{
"metadata": {
- "name": "Chapter 22"
+ "name": "",
+ "signature": "sha256:53f00d75f5adfa37af0d8067426691c881e1b4ea1e38045c3a67a88230ca00f5"
},
"nbformat": 3,
"nbformat_minor": 0,
@@ -10,24 +11,44 @@
{
"cell_type": "markdown",
"metadata": {},
- "source": "<h1>Chapter 22: The C++ Preprocessor<h1>"
+ "source": [
+ "<h1>Chapter 22: The C++ Preprocessor<h1>"
+ ]
},
{
"cell_type": "markdown",
"metadata": {},
- "source": "<h3>Example 22.1, Page Number: 550<h3>"
+ "source": [
+ "<h3>Example 22.1, Page Number: 550<h3>"
+ ]
},
{
"cell_type": "code",
"collapsed": false,
- "input": "'''Implement a function-like macro'''\n\ndef MIN(a,b):\n if a<b:\n return a\n else:\n return b\n\n#Variable declaration\nx=10\ny=20\n\n#Result\nprint \"The minimum is\",MIN(x,y)",
+ "input": [
+ "\n",
+ "def MIN(a,b):\n",
+ " if a<b:\n",
+ " return a\n",
+ " else:\n",
+ " return b\n",
+ "\n",
+ "#Variable declaration\n",
+ "x=10\n",
+ "y=20\n",
+ "\n",
+ "#Result\n",
+ "print \"The minimum is\",MIN(x,y)"
+ ],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
- "text": "The minimum is 10\n"
+ "text": [
+ "The minimum is 10\n"
+ ]
}
],
"prompt_number": 2
@@ -35,19 +56,36 @@
{
"cell_type": "markdown",
"metadata": {},
- "source": "<h3>Example 22.2, Page Number: 551<h3>"
+ "source": [
+ "<h3>Example 22.2, Page Number: 551<h3>"
+ ]
},
{
"cell_type": "code",
"collapsed": false,
- "input": "'''Implement a function-like macro'''\n#Since macros is implemented here using functions,\n#it wont give a wrong answer.\n\ndef EVEN(a):\n if a%2==0:\n return 1\n else:\n return 0\n\nif EVEN(9+1):\n print \"is even\"\nelse:\n print \"is odd\"",
+ "input": [
+ "\n",
+ "\n",
+ "def EVEN(a):\n",
+ " if a%2==0:\n",
+ " return 1\n",
+ " else:\n",
+ " return 0\n",
+ "\n",
+ "if EVEN(9+1):\n",
+ " print \"is even\"\n",
+ "else:\n",
+ " print \"is odd\""
+ ],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
- "text": "is even\n"
+ "text": [
+ "is even\n"
+ ]
}
],
"prompt_number": 3
@@ -55,19 +93,35 @@
{
"cell_type": "markdown",
"metadata": {},
- "source": "<h3>Example 22.3, Page Number: 551<h3>"
+ "source": [
+ "<h3>Example 22.3, Page Number: 551<h3>"
+ ]
},
{
"cell_type": "code",
"collapsed": false,
- "input": "'''Implement a function-like macro'''\n\ndef EVEN(a):\n if a%2==0:\n return 1\n else:\n return 0\n\nif EVEN(9+1):\n print \"is even\"\nelse:\n print \"is odd\"",
+ "input": [
+ "\n",
+ "def EVEN(a):\n",
+ " if a%2==0:\n",
+ " return 1\n",
+ " else:\n",
+ " return 0\n",
+ "\n",
+ "if EVEN(9+1):\n",
+ " print \"is even\"\n",
+ "else:\n",
+ " print \"is odd\""
+ ],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
- "text": "is even\n"
+ "text": [
+ "is even\n"
+ ]
}
],
"prompt_number": 4
@@ -75,19 +129,31 @@
{
"cell_type": "markdown",
"metadata": {},
- "source": "<h3>Example 22.4, Page Number: 553<h3>"
+ "source": [
+ "<h3>Example 22.4, Page Number: 553<h3>"
+ ]
},
{
"cell_type": "code",
"collapsed": false,
- "input": "'''Impementing #if'''\n\ndef MAX():\n return 100\n\nif MAX()>10:\n print \"Extra memory required.\"\n ",
+ "input": [
+ "\n",
+ "def MAX():\n",
+ " return 100\n",
+ "\n",
+ "if MAX()>10:\n",
+ " print \"Extra memory required.\"\n",
+ " "
+ ],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
- "text": "Extra memory required.\n"
+ "text": [
+ "Extra memory required.\n"
+ ]
}
],
"prompt_number": 5
@@ -95,19 +161,33 @@
{
"cell_type": "markdown",
"metadata": {},
- "source": "<h3>Example 22.5, Page Number: 554<h3>"
+ "source": [
+ "<h3>Example 22.5, Page Number: 554<h3>"
+ ]
},
{
"cell_type": "code",
"collapsed": false,
- "input": "'''Impementing #if/#else'''\n\ndef MAX():\n return 6\n\nif MAX()>10:\n print \"Extra memory required.\"\nelse:\n print \"Current memory OK.\"\n ",
+ "input": [
+ "\n",
+ "def MAX():\n",
+ " return 6\n",
+ "\n",
+ "if MAX()>10:\n",
+ " print \"Extra memory required.\"\n",
+ "else:\n",
+ " print \"Current memory OK.\"\n",
+ " "
+ ],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
- "text": "Current memory OK.\n"
+ "text": [
+ "Current memory OK.\n"
+ ]
}
],
"prompt_number": 7
@@ -115,19 +195,42 @@
{
"cell_type": "markdown",
"metadata": {},
- "source": "<h3>Example 22.6, Page Number: 556<h3>"
+ "source": [
+ "<h3>Example 22.6, Page Number: 556<h3>"
+ ]
},
{
"cell_type": "code",
"collapsed": false,
- "input": "'''Implementation of #ifdef and #ifndef'''\n\ndef TOM():\n pass\n\n\ntry:\n TOM()\nexcept NameError:\n print \"Programmer is unknown.\"\nelse:\n print \"Programmer is Tom.\"\n \ntry:\n RALPH()\nexcept NameError:\n print \"RALPH not defined.\"\n ",
+ "input": [
+ "\n",
+ "def TOM():\n",
+ " pass\n",
+ "\n",
+ "\n",
+ "try:\n",
+ " TOM()\n",
+ "except NameError:\n",
+ " print \"Programmer is unknown.\"\n",
+ "else:\n",
+ " print \"Programmer is Tom.\"\n",
+ " \n",
+ "try:\n",
+ " RALPH()\n",
+ "except NameError:\n",
+ " print \"RALPH not defined.\"\n",
+ " "
+ ],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
- "text": "Programmer is Tom.\nRALPH not defined.\n"
+ "text": [
+ "Programmer is Tom.\n",
+ "RALPH not defined.\n"
+ ]
}
],
"prompt_number": 8
@@ -135,19 +238,32 @@
{
"cell_type": "markdown",
"metadata": {},
- "source": "<h3>Example 22.7, Page Number: 558<h3>"
+ "source": [
+ "<h3>Example 22.7, Page Number: 558<h3>"
+ ]
},
{
"cell_type": "code",
"collapsed": false,
- "input": "'''Implement __LINE__ '''\n\nimport inspect\n\n#Returns the current line number in our program.\ndef lineno():\n return inspect.currentframe().f_back.f_lineno\n \nprint lineno()+200\n",
+ "input": [
+ "\n",
+ "import inspect\n",
+ "\n",
+ "#Returns the current line number in our program.\n",
+ "def lineno():\n",
+ " return inspect.currentframe().f_back.f_lineno\n",
+ " \n",
+ "print lineno()+200\n"
+ ],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
- "text": "209\n"
+ "text": [
+ "209\n"
+ ]
}
],
"prompt_number": 9
@@ -155,19 +271,31 @@
{
"cell_type": "markdown",
"metadata": {},
- "source": "<h3>Example 22.8, Page Number: 559<h3>"
+ "source": [
+ "<h3>Example 22.8, Page Number: 559<h3>"
+ ]
},
{
"cell_type": "code",
"collapsed": false,
- "input": "'''Implemention # operator'''\n\ndef mkstr(s):\n return str(s)\n\n#Result\nprint mkstr('I like C++')\n",
+ "input": [
+ "\n",
+ "\n",
+ "def mkstr(s):\n",
+ " return str(s)\n",
+ "\n",
+ "#Result\n",
+ "print mkstr('I like C++')\n"
+ ],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
- "text": "I like C++\n"
+ "text": [
+ "I like C++\n"
+ ]
}
],
"prompt_number": 10
@@ -175,19 +303,32 @@
{
"cell_type": "markdown",
"metadata": {},
- "source": "<h3>Example 22.9, Page Number: 560<h3>"
+ "source": [
+ "<h3>Example 22.9, Page Number: 560<h3>"
+ ]
},
{
"cell_type": "code",
"collapsed": false,
- "input": "'''Implemention # operator'''\n\ndef concat(a,b):\n return a+b\n#Variable declaration\nxy=10\n\n#Result\nexec(\"print %s\")%concat('x','y')",
+ "input": [
+ "\n",
+ "def concat(a,b):\n",
+ " return a+b\n",
+ "#Variable declaration\n",
+ "xy=10\n",
+ "\n",
+ "#Result\n",
+ "exec(\"print %s\")%concat('x','y')"
+ ],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
- "text": "10\n"
+ "text": [
+ "10\n"
+ ]
}
],
"prompt_number": 11
@@ -195,7 +336,7 @@
{
"cell_type": "code",
"collapsed": false,
- "input": "",
+ "input": [],
"language": "python",
"metadata": {},
"outputs": []