1 / 1299

Computer Programming: Introductory Lecture

Computer Programming: Introductory Lecture. Computer Systems Simple Boolean Algebra Algorithms Control Structures Data Structures Structured Programming: C Software Engineering Principles Numerical Computing. Overview. Textbooks. Prescribed :

vschaefer
Download Presentation

Computer Programming: Introductory Lecture

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Computer Programming:Introductory Lecture

  2. Computer Systems Simple Boolean Algebra Algorithms Control Structures Data Structures Structured Programming: C Software Engineering Principles Numerical Computing Overview

  3. Textbooks • Prescribed: • King K.N., C Programming: A Modern Approach, Norton 1996 • Recommended: • Deitel & Deitel, C How to Program, Prentice Hall 1994 (2nd edition) • Brookshear, J.G., Computer Science: An Overview, Benjamin-Cummings 2000 (6th edition) • Kernighan & Ritchie, The C Programming Language, Prentice Hall • References listed in the Introductory Notes

  4. CSE1301 Computer Programming: Lecture 1Computer Systems Overview

  5. eureka! Algorithm: A set of instructions describing how to do a task (or process) Program: C

  6. Topics • Hardware components • Computer networks

  7. Collector Base Emitter Transistor “semi-conductor” • Binary digit or “bit”: • 0 off • 1  on

  8. Transistor (cont) Collector Base Emitter off : 0

  9. Transistor Collector Base Emitter on : 1

  10. Collector Base Emitter Transistor Modern-day “chips” (about 3 x 3 mm in size) can contain millions of transistors

  11. AND Gate NOT Gate OR Gate Gates • Gate: a group of transistors • Gates are switches that distinguish between two electrical voltages: • Current is low => 0 • Current is high => 1 • Types:

  12. A A AND B B A A B A AND B 0 0 B 0 1 1 0 1 1 A AND B Example: AND Gate

  13. OR Gate A OR B Gates and Boolean Algebra AND Gate A B A AND B 0 0 0 1 1 0 1 1

  14. Gates and Boolean Algebra(cont) NOT Gate A NOT A 0 1

  15. Gates and Boolean Algebra (cont) A sequence of bits at a time: A = 1 1 0 0 1 1 0 1 B = 0 1 1 0 0 1 1 0 A AND B = • Most PCs do 32 bits at a time (“32-bit machines”), others as many as 128 bits at a time

  16. 0or1 • Gates are the basic building blocks of computers

  17. Hardware Components of a Typical Computer Peripheral Devices Central Processing Unit (CPU) Memory • "Buses" allow components to pass data to each other

  18. Peripheral Devices Central Processing Unit (CPU) Memory Hardware Components of a Typical Computer -- CPU Central Processing Unit(CPU) • performs the basic operations • consists of two parts: • Arithmetic / Logic Unit (ALU) - data manipulation • Control Unit - coordinate machine’s activities

  19. Peripheral Devices Central Processing Unit (CPU) Memory Hardware Components of a Typical Computer -- Memory Main Memory • holds programs and data • stores bits in fixed-sized chunks: “word” (8, 16, 32, or 64 bits) • each word is stored in a cell, which has a unique address • the cells can be accessed in any order =>random-access memory or “RAM”

  20. Bits, Bytes, Kilo-, Mega-, Giga-, … • A bit: 0 or 1 • A word: chunk of bits (8, 16, 32 or 64 bits) • a byte = 8 bits • a kilobyte = 210 bytes = 1024 bytes • a megabyte = 1024 KB = 220 bytes = 1,048,576 bytes • a gigabyte = 1024 MB = 230 bytes • a terabyte = 1024 GB = 240 bytes

  21. Peripheral Devices Central Processing Unit (CPU) Memory Hardware Components of a Typical Computer -- Peripherals Peripheral devices– • communicate with the outside world • store data long term

  22. Peripheral Devices Central Processing Unit (CPU) Memory Hardware Components of a Typical Computer – Peripheral Devices that Communicate with the Outside World • Input/Output (I/O) • Input: keyboard, mouse, microphone, scanner, sensors (camera, infra-red), punch-cards • Output: video, printer, audio speakers, etc • Communication • modem, ethernet card

  23. Hardware Components of a Typical Computer – Peripheral Devices that Store Data Long Term Secondary (mass) storage Stores information for long periods of time as files • Examples:hard drive, floppy disk, tape, CD-ROM (Compact Disk Read-Only Memory)

  24. Features of Computers – SpeedCPU Speed • CPU clock speed: in cycles per second ("hertz") • Example: 700MHz Pentium III • but different CPU designs do different amounts of work in one clock cycle • “flops” (floating-point operations per second) • “mips” (million instructions per second)

  25. Features of Computers – SpeedSystem-Clock/Bus Speed • communication between CPU, memory and peripheral devices • depends on main board (a.k.a. "motherboard") design • Examples: • Intel 1.50GHz Pentium-4 works on a 400MHz bus speed • 50MHz, 60MHz, 66MHz, 100Mhz, 133MHz, and rising

  26. Features of Computers – SpeedMemory-Access Speed • RAM • about 60ns (1 nanosecond = a billionth of a second), and getting faster • may be rated with respect to “bus speed’’ (e.g., PC-100) • Cache memory • faster than main memory (about 20ns access speed), but more expensive • contains data which the CPU is likely to use next

  27. Features of Computers – Speed Peripheral-Device Speed • Mass storage • Examples: • 3.5in 1.4MB floppy disk: about 500kb/sec at 300 rpm (revolutions per minute) • 3.5in hard disk: average seek time about 8.5 microseconds, and 7,200 rpm • Communications • Examples: modems at 56 kilobits per second, and network cards at 10 or 100 megabits per second • I/O • Examples: ISA, PCI, IDE, SCSI, ATA, USB, etc....

  28. Features of Computers -- Reliability Factors that affect reliability: • heat, ventilation, “over-clocking”, power surges • Most system failures are due to software flaws rather than hardware

  29. 1 0 1 1 0 0 0 1 • Serial communication: • one bit at a time 1 0 Modes of communication • Parallel communication: • all the bits are transferred at the same time • each bit on a separate line

  30. Modems (MOdulator-DEModulator) Modem Remote Computer Digital Data Audio signal phone lines Home Computer Digital Data Modem

  31. Computer Networks • Types • Local Area Networks (LAN) • Computers in an organization • Example: the PCs in the lab • Long Haul Networks • Separated by hundreds or thousands of miles • Physical wires, telephone lines, satellites, etc • Example: Internet “backbone”

  32. Computer Networks– Method of Communication • Each computer has an address • Example: IP address of www.monash.edu.au is 130.194.11.4 • A sender computer transmits data through the network in packets; each packet is tagged with the destination and return address • When data is too big to fit in one packet, the sender computer can split the data into several packets, labeled in sequence

  33. Computer Networks– Method of Communication (cont) • The packets are sent via links from computer to computer (“routing”) • Each intermediate computer receives and retransmits the message (“hops”) • The packets do not necessarily arrive in the order in which they were sent • The recipient computer puts the packets in correct sequence and retrieves the data

  34. Summary • Transistors, gates, chips, hardware • Computer = CPU + Memory + I/O Devices • Networks, modems • Jargon and acronyms

  35. CSE1301Computer ProgrammingLecture 2:Introduction to Algorithms

  36. Topics • Solving problems • Algorithms • Values and variables

  37. How do we solve problems? • We "just do" • Guesswork-and-luck • Trial-and-error • Experience (possibly someone else's) • "Scientifically"

  38. Analysis Problemspecification Design Algorithm Implementation Program Compilation Executable (solution) The Problem-solving Process "Doctor, my head hurts" Patient has elevated pressure in anterior parietal lobe 1. Sterilize cranial saw 2. Anaesthetize patient 3. Remove top of skull 4. Get the big spoon... 5. etc., etc. sterilize(saw,alcohol); raise_hammer(); lower hammer(fast); start(saw); /* etc. etc. */ 0100111010110010101010101001010101010100110010101010101001011010011101010101010010010111010011110101010111110101010001101…

  39. The Problem-solving Process "Doctor, my head hurts" Patient has elevated pressure in anterior parietal lobe. Analysis Problem specification 1. Sterilize cranial saw 2. Anaesthetize patient 3. Remove top of skull 4. Get the big spoon... 5. etc., etc. Design Algorithm Implementation sterilize(saw,alcohol); raise_hammer(); lower hammer(fast); start(saw); /* etc. etc. */ Program Compilation 010011101011001010101010100101010101010011001010101010100101101001110101010101001001011101001111010101011111010101000110100001101... Executable (solution)

  40. The Problem-solving Process Analysis Problem specification Design Algorithm Implementation Program Compilation Executable (solution)

  41. Algorithm • A sequence of instructions specifying the steps required to accomplish some task

  42. Algorithm –History Muhammad ibn Musa Al-Khwarizmi http://www-groups.dcs.st-andrews.ac.uk/~history/Mathematicians/Al-Khwarizmi.html • Book on arithmetic: • Hindu numeration, decimal numbers, use of zero, method for finding square root • Latin translation (c.1120 CE): “Algoritmi de numero Indorum” • Book on algebra • Hisab al-jabr w’al-muqabala

  43. Algorithm – Working Definition • A sequence of instructions describing how to do a task [As opposed to actually executing the instructions]

  44. Algorithm -- Examples • A cooking recipe • Assembly instructionsfor a model • The rules of how to play a game • VCR instructions • Descriptionof a martial arts technique • Directions for driving from A to B • A knitting pattern • A car repair manual

  45. Algorithm – Examples (cont) • Recipe for Almond and honey slice • Recipe for Arroz con pollo

  46. 1/2 quantity Shortcrust Pastry 185 g unsalted butter 100 g castor sugar 5 tablespoons honey 50 ml cream 50 ml brandy or any other liqueur or spirit 300 g flaked almonds Preheat oven for 200° C Line a 30 cm  20 cm baking tray with baking paper, and then with pastry Bake blind for 20 minutes, then remove weights and foil Turn oven up to 220° C. Bring remaining ingredients to a boil, stirring. Spread evenly over pastry. Bake until topping is bubbling and has caramelised evenly, about 15 minutes. Cool before cutting into fingers or squares. Almond and Honey Slice From: Stephanie Alexander, The Cook’s Companion, Viking/Penguin, Ringwood, Victoria, 1996, p. 349.

  47. 1/2 quantity Shortcrust Pastry 185 g unsalted butter 100 g castor sugar 5 tablespoons honey 50 ml cream 50 ml brandy or any other liqueur or spirit 300 g flaked almonds Preheat oven for 200° C Line a 30 cm  20 cm baking tray with baking paper, and then with pastry Bake blind for 20 minutes, then remove weights and foil Turn oven up to 220° C. Bring remaining ingredients to a boil, stirring. Spread evenly over pastry. Bake until topping is bubbling and has caramelised evenly, about 15 minutes. Cool before cutting into fingers or squares. Almond and Honey Slice Instructions are given in the order in which they are performed (“executed”) From: Stephanie Alexander, The Cook’s Companion, Viking/Penguin, Ringwood, Victoria, 1996, p. 349.

  48. Cut chicken into pieces and brown the pieces on all sides in a casserole dish in hot olive oil. Remove the chicken and to the juices in the casserole add garlic, onions and green peppers, and sauté until onion is golden. Add bay leaf, whole tomatoes, and chicken broth. When the broth boils add salt, saffron and rice. Arrange chicken on rice, cover casserole and bake in a moderate oven (350°F) for 20 minutes or until the rice is tender. Add beans and artichokes during last 10 minutes of cooking. Correct Algorithm? From: “Arroz Con Pollo” in The Margaret Fulton Cookbook, Hamlyn, Sydney, 1968.

  49. Cut chicken into pieces and brown the pieces on all sides in a casserole dish in hot olive oil. Remove the chicken and to the juices in the casserole add garlic, onions and green peppers, and sauté until onion is golden. Add bay leaf, whole tomatoes, and chicken broth. When the broth boils add salt, saffron and rice. Arrange chicken on rice, cover casserole andbake in a moderate oven (350°F) for 20 minutes or until the rice is tender. Add beans and artichokes during last 10 minutes of cooking. Correct Algorithm? From: “Arroz Con Pollo” in The Margaret Fulton Cookbook, Hamlyn, Sydney, 1968.

  50. Cut chicken into pieces and brown the pieces on all sides in a casserole dish in hot olive oil. Remove the chicken and to the juices in the casserole add garlic, onions and green peppers, and sauté until onion is golden. Add bay leaf, whole tomatoes, and chicken broth. When the broth boils add salt, saffron and rice. Arrange chicken on rice, cover casserole andbake in a moderate oven (350°F) for 10 minutes. Add beans and artichokes. Cover, and bake for another 10 minutes or until rice is tender. Correct Algorithm?

More Related