summaryrefslogtreecommitdiff
path: root/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter16.ipynb
diff options
context:
space:
mode:
authorhardythe12015-07-03 12:23:43 +0530
committerhardythe12015-07-03 12:23:43 +0530
commit9d260e6fae7328d816a514130b691fbd0e9ef81d (patch)
tree9e6035702fca0f6f8c5d161de477985cacad7672 /C_Programming:_A_Modern_Approach_by_K.N._King/Chapter16.ipynb
parentafcd9e5397e3e1bde0392811d0482d76aac391dc (diff)
downloadPython-Textbook-Companions-9d260e6fae7328d816a514130b691fbd0e9ef81d.tar.gz
Python-Textbook-Companions-9d260e6fae7328d816a514130b691fbd0e9ef81d.tar.bz2
Python-Textbook-Companions-9d260e6fae7328d816a514130b691fbd0e9ef81d.zip
add/remove books
Diffstat (limited to 'C_Programming:_A_Modern_Approach_by_K.N._King/Chapter16.ipynb')
-rwxr-xr-xC_Programming:_A_Modern_Approach_by_K.N._King/Chapter16.ipynb180
1 files changed, 180 insertions, 0 deletions
diff --git a/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter16.ipynb b/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter16.ipynb
new file mode 100755
index 00000000..20e3b1e5
--- /dev/null
+++ b/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter16.ipynb
@@ -0,0 +1,180 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:9fe9374bd25aac8dfc98eab84988bb008dcfb464faf94260bebab61ae764fb98"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 16: Structures, Unions and Enumerations"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example inventory.c, Page 391"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "NAME_LEN=25\n",
+ "MAX_PARTS=100\n",
+ "num_parts=0\n",
+ "number1=[0]*100\n",
+ "on_hand1=[0]*100\n",
+ "name1=[0]*100\n",
+ "def find_part(number):\n",
+ " i=0\n",
+ " for i in range (i,num_parts):\n",
+ " if(number1[i]==number):\n",
+ " return i\n",
+ " return -1\n",
+ "def insert():\n",
+ " num_parts=0\n",
+ " if(num_parts==MAX_PARTS):\n",
+ " print \"Database is full, cant add more parts\"\n",
+ " return\n",
+ " part_number=int(raw_input(\"Enter part number: \"))\n",
+ " if(find_part(part_number)>=0):\n",
+ " print \"Part already exists\"\n",
+ " return\n",
+ " number1[num_parts]=part_number\n",
+ " name1[num_parts]=raw_input(\"Enter part name: \")\n",
+ " on_hand1[num_parts]=raw_input(\"Enter quality on hand: \")\n",
+ " num_parts=num_parts+1\n",
+ " \n",
+ "def search():\n",
+ " number=int(raw_input(\"Enter part number: \"))\n",
+ " i=find_part(number)\n",
+ " if(i>=0):\n",
+ " print \"Part name: %s\" %name1[i]\n",
+ " print \"Quantity on hand: %d\"%on_hand1[i]\n",
+ " else:\n",
+ " print \"Part not found\"\n",
+ " \n",
+ "def update():\n",
+ " number=int(raw_input(\"Enter part number: \"))\n",
+ " i=find_part(number)\n",
+ " if(i>=0):\n",
+ " change=int(raw_input(\"Enter change in quantity on hand: \")) \n",
+ " on_hand1[i]=on_hand1[i]+change\n",
+ " else:\n",
+ " print \"Part not found\"\n",
+ "\n",
+ "while(1):\n",
+ " code=raw_input(\"Enter operation code: \")\n",
+ " if code=='i':\n",
+ " insert()\n",
+ " break\n",
+ " elif code=='s':\n",
+ " search()\n",
+ " break\n",
+ " elif code=='u':\n",
+ " update()\n",
+ " break\n",
+ " elif(code=='p'):\n",
+ " print()\n",
+ " break\n",
+ "\n",
+ "print \"\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter operation code: i\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter part number: 528\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter part name: Disk Drive\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Enter quality on hand: 10\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example readline.c, Page 395"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def read_line(str,n):\n",
+ " ch=0\n",
+ " i=0\n",
+ " EOF='\\n'\n",
+ " ch=raw_input()\n",
+ " while(isspace(ch)):\n",
+ " donothing=0\n",
+ " while(ch!='\\n' and ch!=EOF):\n",
+ " if(i<n):\n",
+ " str[i+1]=ch\n",
+ " ch=raw_input()\n",
+ " str[i]='\\0'\n",
+ " return i"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file