summaryrefslogtreecommitdiff
path: root/C++_from_the_Ground/Chapter_2.ipynb
diff options
context:
space:
mode:
Diffstat (limited to 'C++_from_the_Ground/Chapter_2.ipynb')
-rw-r--r--C++_from_the_Ground/Chapter_2.ipynb416
1 files changed, 416 insertions, 0 deletions
diff --git a/C++_from_the_Ground/Chapter_2.ipynb b/C++_from_the_Ground/Chapter_2.ipynb
new file mode 100644
index 00000000..b3976867
--- /dev/null
+++ b/C++_from_the_Ground/Chapter_2.ipynb
@@ -0,0 +1,416 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:05876b24f412fcea817693bad944dc90f3dae4fb5142aeb7d9c2c98569067083"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h1>Chapter 2: An Overview of C++<h1>"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 2.1, Page Number: 12<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "print \"This is my first C++ program.\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "This is my first C++ program.\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 2.2, Page Number: 17<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ " \n",
+ "x=None \n",
+ "\n",
+ "x=1023 #this assigns 1023 to x\n",
+ "\n",
+ "#Result\n",
+ "print \"This program prints the value of x: \",x #prints x,i.e, 1023\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "This program prints the value of x: 1023\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 2.3, Page Number: 18<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "\n",
+ "#Variable declaration\n",
+ "gallons=10 #User input\n",
+ "liters=None\n",
+ "\n",
+ "liters=gallons*4 #convert to liters\n",
+ "\n",
+ "#Result\n",
+ "print \"Liters: \",liters"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Liters: 40\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 2.4, Page Number: 20<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "\n",
+ "\n",
+ "#Variable declaration\n",
+ "gallons=10.20 #User input\n",
+ "liters=None\n",
+ "\n",
+ "liters=gallons*3.7854 #convert to liters\n",
+ "\n",
+ "#Result\n",
+ "print \"Liters: \",liters"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Liters: 38.61108\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 2.5, Page Number: 21<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ " \n",
+ "def myfunc():\n",
+ " print \"Inside myfunc() \"\n",
+ " \n",
+ "print \"In main()\"\n",
+ "myfunc() #call myfunc()\n",
+ "print \"Back in main()\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "In main()\n",
+ "Inside myfunc() \n",
+ "Back in main()\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 2.6, Page Number: 22<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ " \n",
+ "print abs(-10)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "10\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 2.7, Page Number: 23<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ " \n",
+ "def mul(x,y):\n",
+ " print x*y,\n",
+ "\n",
+ "#calling mul\n",
+ "mul(10,20)\n",
+ "mul(5,6)\n",
+ "mul(8,9)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "200 30 72\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 2.8, Page Number: 24<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ " \n",
+ "def mul(x,y):\n",
+ " return x*y #return product of x and y\n",
+ "\n",
+ "#Variable declaration\n",
+ "answer=mul(10,11) #assign return values\n",
+ "\n",
+ "#Result\n",
+ "print \"The answer is: \",answer\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The answer is: 110\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 2.9, Page Number: 26<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "\n",
+ "print \"one\"\n",
+ "print \"two\" #prints in different line\n",
+ "print \"three\",\"four\" #prints all in same line"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "one\n",
+ "two\n",
+ "three four\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 2.10, Page Number: 27<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ " \n",
+ "#Variable declaration\n",
+ "a=10 #user input for two numbers\n",
+ "b=20\n",
+ "\n",
+ "#Result\n",
+ "if a<b:\n",
+ " print \"First number is less than second. \""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "First number is less than second. \n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 2.11, Page Number: 28<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "\n",
+ "for count in range(1,100+1):\n",
+ " print count,"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Example 2.12, Page Number: 30<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ " \n",
+ "a=10 #User input for two numbers\n",
+ "b=20\n",
+ "\n",
+ "#Result\n",
+ "if a<b:\n",
+ " print \"First number is less than second\"\n",
+ " print \"Their difference is: \",b-a\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "First number is less than second\n",
+ "Their difference is: 10\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file