{
 "metadata": {
  "name": "",
  "signature": "sha256:2b15773f7ac32790cdae17d01e20d25a0e5b7210bb725c38fabf3dd28109e9da"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 1:Introduction to C++"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "C3FIRST, Page number:52"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Variable Declaration\n",
      "i=4\n",
      "j=i+7\n",
      "c='A'\n",
      "x=9.087\n",
      "x=x*4.5\n",
      "\n",
      "#Result\n",
      "print i,c,j,x"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "4 A 11 40.8915\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "C4ST1, Page number:85"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Result\n",
      "print \"C++ programming is fun!\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "C++ programming is fun!\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "C4ST2, Page number:86"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Declaration\n",
      "tax_rate=0.08\n",
      "sale=22.54\n",
      "\n",
      "#Calculation\n",
      "tax=sale*tax_rate\n",
      "\n",
      "#Result\n",
      "print \"The sales tax is :\" ,tax"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The sales tax is : 1.8032\n"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "C4AREAC,Page number:95"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Declaration\n",
      "PI=3.14159\n",
      "radius=5\n",
      "\n",
      "#Calculation\n",
      "area=radius*radius*PI\n",
      "#Result\n",
      "print \"The area is \",area\n",
      "\n",
      "radius=20\n",
      "#Calculation\n",
      "area=radius*radius*PI\n",
      "\n",
      "#Result\n",
      "print \"The area is \",area"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The area is  78.53975\n",
        "The area is  1256.636\n"
       ]
      }
     ],
     "prompt_number": 10
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "C5INIT,Page number:108"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Get input\n",
      "#first=raw_input(\"Enter your first name:\")\n",
      "#last=raw_input(\"Enter your last name\")\n",
      "\n",
      "first=\"perry\"\n",
      "last=\"greg\"\n",
      "#Print the Initials\n",
      "print \"Your initials are \",first[0],last[0] \n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Your initials are  p g\n"
       ]
      }
     ],
     "prompt_number": 11
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "C6PRE,Page number:114"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Declaration\n",
      "AGE=28\n",
      "MESSAGE=\"Hello, world\"\n",
      "\n",
      "i=10\n",
      "age=5\n",
      "\n",
      "# 'AGE' is different from 'age'\n",
      "i=i*AGE                                   \n",
      "\n",
      "#Result\n",
      "print i,\" \",age,\" \",AGE,\"\\n\"\n",
      "print MESSAGE                       "
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "280   5   28 \n",
        "\n",
        "Hello, world\n"
       ]
      }
     ],
     "prompt_number": 12
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "C6INCL1,Page number:119"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Result\n",
      "print \"Kelly Jane Peterson\\n\"\n",
      "print \"Apartment #217\\n\"\n",
      "print \"4323 East Skelly Drive\\n\"\n",
      "print \"New York, New York\\n\"\n",
      "print \"             10012\\n\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Kelly Jane Peterson\n",
        "\n",
        "Apartment #217\n",
        "\n",
        "4323 East Skelly Drive\n",
        "\n",
        "New York, New York\n",
        "\n",
        "             10012\n",
        "\n"
       ]
      }
     ],
     "prompt_number": 13
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "C6INCL3,Page number:120"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "source = \"This is fun!\"\n",
      "\n",
      "#source is copied to message\n",
      "import copy\n",
      "message=copy.copy(source)\n",
      "\n",
      "#Result\n",
      "print message\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "This is fun!\n"
       ]
      }
     ],
     "prompt_number": 14
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "C6DEF1,Page number:121"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "MYNAME=\"Phil Ward\"\n",
      "name=MYNAME\n",
      "\n",
      "#Result\n",
      "print \"My name is \",name,\"\\n\"\n",
      "print \"My name is \",MYNAME,\"\\n\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "My name is  Phil Ward \n",
        "\n",
        "My name is  Phil Ward \n",
        "\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "C6DEF2,Page number:122"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#function definition\n",
      "def X4(b,c,d):\n",
      "    return 2*b+c+3*b+c+b+c+4*b+c+b+c*c+b+c-d\n",
      "    \n",
      "b=2\n",
      "c=3\n",
      "d=4\n",
      "e= X4 (b,c,d)\n",
      "\n",
      "#Result\n",
      "print e,\",\",b+c,\",\",b+c+b+c,\",\",b+c+b+c*c+b+c-d,\",\",X4(b,c,d)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "44 , 5 , 10 , 17 , 44\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "C7PRNT1,Page number:136"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Declaration\n",
      "first='E'\n",
      "middle='W'\n",
      "last='C'\n",
      "age=32\n",
      "dependents=2\n",
      "salary=25000.00\n",
      "bonus=575.25\n",
      "\n",
      "#Result\n",
      "print \"Here are the initials: \"\n",
      "print first,middle,last\n",
      "print \"The age and number of dependents are \"\n",
      "print age,\" \",dependents\n",
      "print \"The salary and bonus are \"\n",
      "print salary,\" \",bonus\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Here are the initials: \n",
        "E W C\n",
        "The age and number of dependents are \n",
        "32   2\n",
        "The salary and bonus are \n",
        "25000.0   575.25\n"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "C7TEAM, Page number:138"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#table of team names and hits for three weeks\n",
      "\n",
      "print \"Parrots\\tRams\\tKings\\tTitans\\tChargers\"\n",
      "print \"3\\t5\\t3\\t1\\t0\"\n",
      "print \"2\\t5\\t1\\t0\\t1\"\n",
      "print \"2\\t6\\t4\\t3\\t0\"\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Parrots\tRams\tKings\tTitans\tChargers\n",
        "3\t5\t3\t1\t0\n",
        "2\t5\t1\t0\t1\n",
        "2\t6\t4\t3\t0\n"
       ]
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "C7PAY1,Page number:141"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# Computes and prints payroll data properly in dollars and cents.\n",
      "\n",
      "emp_name=\"Larry Payton\"\n",
      "pay_date=\"03/09/92\"\n",
      "hours_worked=43\n",
      "rate=7.75                       #pay per hour\n",
      "tax_rate=.32                    #Tax percentage rate\n",
      "\n",
      "\n",
      "#Compute the pay amount\n",
      "gross_pay=hours_worked*rate\n",
      "taxes=tax_rate*gross_pay\n",
      "net_pay=gross_pay-taxes\n",
      "\n",
      "#Results\n",
      "print \"As of: \",pay_date\n",
      "print emp_name,\" worked \",hours_worked,\"hours\"\n",
      "print \"and got paid\",round(gross_pay,2)\n",
      "print \"After taxes of: \",round(taxes,2)\n",
      "print \"his take-home pay was $\",round(net_pay,2)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "As of:  03/09/92\n",
        "Larry Payton  worked  43 hours\n",
        "and got paid 333.25\n",
        "After taxes of:  106.64\n",
        "his take-home pay was $ 226.61\n"
       ]
      }
     ],
     "prompt_number": 7
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "C7SLTX1, Page number:146"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#prompt for a sales amount and print sales tax\n",
      "\n",
      "#getting total sale as float number.\n",
      "#print \"What is the total amount of the sale?\"\n",
      "#total_sale=float(raw_input())   \n",
      "\n",
      "total_sale=50\n",
      "\n",
      "#Compute sales tax\n",
      "stax=total_sale*0.07    \n",
      "\n",
      "#Results\n",
      "print \"The sales tax for\",float(round(total_sale,2)),\"is\",round(stax,2)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The sales tax for 50.0 is 3.5\n"
       ]
      }
     ],
     "prompt_number": 10
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "C7PHON1, Page number:147"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#request user's name and print it as it would appeat in a phone book\n",
      "\n",
      "#get name\n",
      "#first=raw_input(\"What is your first name?\\n\")\n",
      "#last=raw_input(\"What is your last name?\\n\")\n",
      "\n",
      "first=\"perry\"\n",
      "last=\"greg\"\n",
      "print \"\\n\\n\"\n",
      "print \"In a phone book,your name would look like this :\\n\"\n",
      "print last,\",\",first "
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "\n",
        "\n",
        "\n",
        "In a phone book,your name would look like this :\n",
        "\n",
        "greg , perry\n"
       ]
      }
     ],
     "prompt_number": 11
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "C7MATH, Page number:148"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Simple Addition\n",
      "\n",
      "print \"*** Math Practice ***\\n\\n\\n\"\n",
      "#num1=input(\"What is the first number:\")\n",
      "#num2=input(\"What is the second number:\")\n",
      "\n",
      "num1=10\n",
      "num2=20\n",
      "\n",
      "ans=num1+num2\n",
      "\n",
      "#get user answer\n",
      "#her_ans=input(\"\\nWhat do you think is the answer?\")\n",
      "her_ans=30\n",
      "\n",
      "#Result\n",
      "print \"\\n\",num1,\"plus\",num2,\"is\",ans,\"\\n\\nHope you got it right!\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "*** Math Practice ***\n",
        "\n",
        "\n",
        "\n",
        "\n",
        "10 plus 20 is 30 \n",
        "\n",
        "Hope you got it right!\n"
       ]
      }
     ],
     "prompt_number": 12
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "C7PS2, Page number:150"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "message=\"Please turn on your printer.\"\n",
      "\n",
      "#Result\n",
      "print message"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Please turn on your printer.\n"
       ]
      }
     ],
     "prompt_number": 13
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "C7PRNTF, Page number:153"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Declaration\n",
      "first='E'\n",
      "middle='W'\n",
      "last='C'\n",
      "age=32\n",
      "dependents=2\n",
      "salary=25000.00\n",
      "bonus=575.25\n",
      "\n",
      "#Result\n",
      "print \"Here are the initials: \"\n",
      "print first,\" \",middle,\" \",last,\"\\n\"\n",
      "print \"The age and number of dependents are: \"\n",
      "print age,\" \",dependents,\"\\n\"\n",
      "print \"The salary and bonus are: \"\n",
      "print \"%.6f\" %salary,\" \",\"%.6f\" %bonus"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Here are the initials: \n",
        "E   W   C \n",
        "\n",
        "The age and number of dependents are: \n",
        "32   2 \n",
        "\n",
        "The salary and bonus are: \n",
        "25000.000000   575.250000\n"
       ]
      }
     ],
     "prompt_number": 15
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "C7SLTXS, Page number:156"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#prompt for a sales amount and print sales tax\n",
      "\n",
      "#getting total sale as float number\n",
      "#print \"What is the total amount of the sale?\"\n",
      "#total_sale=float(raw_input())   \n",
      "total_sale=10\n",
      "\n",
      "#compute sales tax\n",
      "stax=total_sale*0.07    \n",
      "\n",
      "#Result\n",
      "print \"The sales tax for\",float(round(total_sale,3)),\"is\",round(stax,3)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The sales tax for 10.0 is 0.7\n"
       ]
      }
     ],
     "prompt_number": 18
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [],
     "language": "python",
     "metadata": {},
     "outputs": []
    }
   ],
   "metadata": {}
  }
 ]
}