summaryrefslogtreecommitdiff
path: root/C++_Demystified:_A_Self-Teaching_Guide/chapter10.ipynb
diff options
context:
space:
mode:
Diffstat (limited to 'C++_Demystified:_A_Self-Teaching_Guide/chapter10.ipynb')
-rw-r--r--C++_Demystified:_A_Self-Teaching_Guide/chapter10.ipynb99
1 files changed, 20 insertions, 79 deletions
diff --git a/C++_Demystified:_A_Self-Teaching_Guide/chapter10.ipynb b/C++_Demystified:_A_Self-Teaching_Guide/chapter10.ipynb
index dd6f3a0f..7fcd3612 100644
--- a/C++_Demystified:_A_Self-Teaching_Guide/chapter10.ipynb
+++ b/C++_Demystified:_A_Self-Teaching_Guide/chapter10.ipynb
@@ -1,6 +1,7 @@
{
"metadata": {
- "name": ""
+ "name": "",
+ "signature": "sha256:ffbb5815913062b1375d894b2fe1e26db393d3f99c982f5934f82d0355e05d2e"
},
"nbformat": 3,
"nbformat_minor": 0,
@@ -27,10 +28,7 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "\"\"\"\n",
- "defining an array\n",
- "note: no need to specify size of an array in python, it exapands automatically.\n",
- "\"\"\"\n",
+ "\n",
"\n",
"testScore = [] #array defined"
],
@@ -51,12 +49,7 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "\"\"\"\n",
- "variable as size of array\n",
- "note: this won't give an error as mentioned in book as it will take numTests as\n",
- "an element of array instead of size of array, as there is no need of size of \n",
- "array in python.\n",
- "\"\"\"\n",
+ "\n",
"\n",
"print \"Enter the number of test scores:\",\n",
"numTests = int(raw_input())\n",
@@ -102,11 +95,7 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "\"\"\"\n",
- "variable as size of array\n",
- "note: numTests will be taken as an element of array instead of size.\n",
- "Also, there in no constant in Python, this program will be same as previous one\n",
- "\"\"\"\n",
+ "\n",
"\n",
"numTests = 3\n",
"print \"Enter the number of test scores:\",\n",
@@ -153,11 +142,7 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "\"\"\"\n",
- "variable as size of array\n",
- "note: numTests will be taken as an element of array instead of size.\n",
- "Also, there in no constant in Python, this program will be same as previous one\n",
- "\"\"\"\n",
+ "\n",
"\n",
"numTests = 3\n",
"print \"Enter the number of test scores:\",\n",
@@ -205,10 +190,7 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "\"\"\"\n",
- "intializing character array\n",
- "note: '\\0' will have different result in python than in c++ \n",
- "\"\"\"\n",
+ "\n",
"\n",
"name = ['J', 'e', 'f', 'f', '\\0']\n",
"print name"
@@ -238,10 +220,7 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "\"\"\"\n",
- "intializing character array\n",
- "note: output will be different than that in book.\n",
- "\"\"\"\n",
+ "\n",
"\n",
"name = ['J', 'e', 'f', 'f']\n",
"print name"
@@ -271,9 +250,7 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "\"\"\"\n",
- "assigning & displaying array values\n",
- "\"\"\"\n",
+ "\n",
"\n",
"testScore = []\n",
"print \"Enter test score #1: \",\n",
@@ -358,9 +335,7 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "\"\"\"\n",
- "using 3 separate variables instead of array in previous example\n",
- "\"\"\"\n",
+ "\n",
"\n",
"\n",
"print \"Enter test score #1: \",\n",
@@ -445,9 +420,7 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "\"\"\"\n",
- "looping for array\n",
- "\"\"\"\n",
+ "\n",
"\n",
"testScore = []\n",
"for i in range(3):\n",
@@ -529,9 +502,7 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "\"\"\"\n",
- "using constant for range of array\n",
- "\"\"\"\n",
+ "\n",
"\n",
"MAX = 3\n",
"\n",
@@ -615,11 +586,7 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "\"\"\"\n",
- "Common programming mistake for array\n",
- "note: the problem mentioned in the textbook won't occur in python as we are not\n",
- "specifying size of an array.\n",
- "\"\"\"\n",
+ "\n",
"\n",
"MAX = 3\n",
"\n",
@@ -719,11 +686,7 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "\"\"\"\n",
- "input element by index in array\n",
- "note: if the array is not initialized then this method won't work. append() may\n",
- "be used instead.\n",
- "\"\"\"\n",
+ "\n",
"\n",
"MAX = 3\n",
"grades = [0,0,0]\n",
@@ -802,9 +765,7 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "\"\"\"\n",
- "character array\n",
- "\"\"\"\n",
+ "\n",
"\n",
"name = ['J','e','f','f']\n",
"print \"Enter your name: \",\n",
@@ -851,11 +812,6 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "\"\"\"\n",
- "cout Object with Numeric Arrays\n",
- "note: here the list itself will be printed instead of base address(as mentioned\n",
- "in textbook).\n",
- "\"\"\"\n",
"\n",
"MAX = 3\n",
"testScore = []\n",
@@ -935,11 +891,7 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "\"\"\"\n",
- "cin with numeric array\n",
- "note: there won't be any error in python as it is with the case of c++. It will\n",
- "just take testScore as a normal variable.\n",
- "\"\"\"\n",
+ "\n",
"\n",
"testScore = []\n",
"testScore = raw_input()"
@@ -970,11 +922,7 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "\"\"\"\n",
- "cin with character array\n",
- "note: it will simply override the array and assign whatever value you enter to\n",
- "the name variable unlike c++(as mentioned in c++)\n",
- "\"\"\"\n",
+ "\n",
"\n",
"name = ['J','e','f','f']\n",
"print \"Enter your name: \",\n",
@@ -1021,9 +969,7 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "\"\"\"\n",
- "name as string\n",
- "\"\"\"\n",
+ "\n",
"\n",
"print \"Enter your name: \",\n",
"name = raw_input()\n",
@@ -1069,10 +1015,7 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "\"\"\"\n",
- "getline()\n",
- "note: there is no getline() in python.\n",
- "\"\"\"\n",
+ "\n",
"\n",
"print \"Enter your name: \",\n",
"name = raw_input()\n",
@@ -1118,9 +1061,7 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "\"\"\"\n",
- "passing array as function argument\n",
- "\"\"\"\n",
+ "\n",
"\n",
"MAX = 3\n",
"\n",