1 / 32

Lecture II Basic computer and programming concepts

Lecture II Basic computer and programming concepts. Yi Lin Sept 7, 2006. What is computer?. Computers are clever idiots Idiot: Do whatever it is ordered; Clever: But fast and never wrong. Who gives the orders? Programmers In what forms?

cdeschamp
Télécharger la présentation

Lecture II Basic computer and programming concepts

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. Lecture II Basic computer and programming concepts Yi Lin Sept 7, 2006

  2. What is computer? • Computers are clever idiots • Idiot: Do whatever it is ordered; • Clever: But fast and never wrong. • Who gives the orders? • Programmers • In what forms? • Programs in certain syntaxes (i.e., in certain programming languages) 34253 * 98573 * 15462 = ? 52206221022678 COMP208 Computers in Engr

  3. Computer Windows XP, Linux, Microsoft Office, Internet Browser … Software Pentium 4 CPU, AMD, 512 MB DDR memory, 19 inch LCD, Keyboard, … Hardward COMP208 Computers in Engr

  4. Command n Command n …… …… Command 2 Command n …… storage storage storage Command 2 Command n Command 2 results Monitor Computer Hardware • Von Neumann model • FETCH and EXECUTE Command 1 processor COMP208 Computers in Engr

  5. Computer Hardware Keyboard Hard Disk Memory BUS Cache Monitor Printer Register CPU COMP208 Computers in Engr

  6. The 5 Classic Components Computer CPU Memory Control Input Devices Registers Output Devices COMP208 Computers in Engr

  7. Input / Ouput Output Input Those are only the ones I came up with when I wrote this slide… COMP208 Computers in Engr

  8. Computer Software (program) • A programis a set of step-by-step instructions that directs the computer to do the tasks you want it to do and produce the results you want. In what form? • E.g., Windows XP, Red hat, Microsoft Office (Word, PowerPoint, Excel), Computer Virus … • Showing a few example programs, BallGame, TypingGame, … COMP208 Computers in Engr

  9. Different natural languages Wie geht es Ihnen? How are you? And more …… Comment allez-vous? 你好吗? COMP208 Computers in Engr

  10. Different programming languages C++ C# C Assembly (Intel8086, Motorola68000) Machine language And more …… Fortran Java COMP208 Computers in Engr

  11. Levels of language Natural language Easiness for human, i.e., more flexibility, easier to be implemented, maintained Very high level language (e.g., Java, C++, SQL) High level language (e.g., Fortran, C, Cobol) Assembly language (Intel: 8086, Motorola: 68000, Sun: Sparc) Machine Language (e.g., 01001110000) Speed COMP208 Computers in Engr

  12. Choosing a language • Manager choices a language for everyone in the group • Suitable for your tasks • Satellite communication (speed) Assembly • Education Basic, Pascal • Business  Cobol • Web development Javascript, Java • Scientific calculation Fortran • Real programmer in general purpose C COMP208 Computers in Engr

  13. Major programming language: Fortran • The First High-Level Language • Developed by IBM and introduced in 1957 • Primarily associated with engineering, mathematical, and scientific research tasks. • Rich in math library COMP208 Computers in Engr

  14. Major programming language: COBOL • The Language of Business • Although Fortran in 1950s, no high level language for business.. • The U.S. Department of Defense: CODASYL-COnference of DAta SYstem Languages. • 1959 COBOL-COmmon Business Oriented Language. • 1974, American National Standards Institute: ANSI-COBOL • 1985, COBOL 85 • COBOL is very good for processing large files and performing relatively simple business calculations, such as payroll or interest. • English-like-far more than FORTRAN or BASIC COMP208 Computers in Engr

  15. Major programming language: Basic • For Beginners and Others • BASIC-Beginners' All-purpose Symbolic Instruction Code • Developed at Dartmouth College by John Kemeny and Thomas Kurtz in 1965 and originally intended for use by students. • For many years, BASIC was looked down on by "real programmers," who complained that it had too many limitations and was not suitable for complex tasks. Newer versions, such as Microsofts QuickBASIC, include substantial improvements. COMP208 Computers in Engr

  16. Major programming language: C • A language invented by Dennis Ritchie at Bell Labs in 1972 • Advantage: • C very fast ≈ assembly language while still offering high-level language features. • Disadvantage: • Although C is simple and elegant, it is not simple to learn. • C was originally designed to write systems software but is now considered a general-purpose language. • The availability of C on personal computers has greatly enhanced the value of personal computers for budding software entrepreneurs. COMP208 Computers in Engr

  17. The Programming Process • Developing a program involves steps similar to any problem-solving task: • Defining the problem • Planning the solution • Coding the program • Testing the program • Documenting the program COMP208 Computers in Engr

  18. 1. Defining the problem • identifying • what it is you know (input-given data), • and what it is you want to obtain (output-the result). • Need to meet with • users from the client organization to analyze the problem, • a systems analyst who outlines the project. • Finally a written agreement is produced. COMP208 Computers in Engr

  19. 2. Planning the solution • draw a flowchart • a pictorial representation of a step-by-step solution to a problem • arrows • the direction the program takes • boxes • representing actions. • write pseudocode, • an English-like nonstandard language • Focus on programming logic, no syntax • No executable • possibly both. COMP208 Computers in Engr

  20. N=1, sum=0 conditions action No N < 100 Yes sum = sum + N N = N +1 end actions 2.1. Flow chart start • Example: • Calculate the sum of positive integers less than 100 loop COMP208 Computers in Engr

  21. 2.2. Pseudocodes • Initiate N as smallest positive integer, sum=0 • Loop until N equals to 100 • Sum = sum + N • Increase N by 1 COMP208 Computers in Engr

  22. Essential things in a program • Variables, e.g., N, sum • Type: e.g., integer • Operator: e.g., +, =, < • Conditions: e.g., if N < 100 • Loop: e.g., loop until N < 100 • For reusing the codes • Exit conditions: e.g., N < 100 COMP208 Computers in Engr

  23. 3. Coding the program • Translate the logic from the flowchart or pseudocode-or some other tool-to a programming language. • Programming language is more precise than natural languages • Have to follow exactly the rules (i.e., the syntax) of the language you are using. • Note: No syntax error does not guarantee the program will work correctly as you expect. COMP208 Computers in Engr

  24. 4. Testing the program • Desk-checking: similar to proofreading. • Compiling: • use compilor, a program, to check if syntax error. • N=2 *(I+J)) // compilor will report an error. • Then translates your program into a form the computer can understand, i.e., machine language • Debugging: • Run the translated program in machine language • detecting, locating, and correcting bugs (mistakes) • These bugs are logic errors (e.g., n < 100 not n <=100) COMP208 Computers in Engr

  25. 5. Documenting the program • Documentation is a written detailed description of the programming cycle and specific facts about the program. • Separated documents • Comments in the program itself • Many programmers omit these or put little comments on the codes. • Comments should not just rephrase the codes in plain English • Bad: n=n+1 // increase n by 1 • Good: n=n+1 // n needed to increased for terminating the loop COMP208 Computers in Engr

  26. Let’s startA simplest Fortran program COMP208 Computers in Engr

  27. Hello World! PROGRaM hello IMPLIcIT NONE WRITE(*,*) "Hello World!" END PROGRaM • Edit: • any text editor, e.g., SciTE, Notepad, • Or IDE (Integrated Development Environment), e.g., Visual Fortran HelloWorld.f90 COMP208 Computers in Engr

  28. Hello World (cont.) • Edit • compile • Fortran  Machine Language • GFortran: • ~%>gfortran HelloWorld.f90  a.exe • ~%>gfortran HelloWorld.f90 –o HelloWorld -> HelloWorld.exe • Link (not necessary for simple programs) • Linking libraries used in the program • Run • ~%>HelloWorld • Output: “Hello World!” Repeat Until succeed COMP208 Computers in Engr

  29. Program name Later “!” comment the whole line block WRITE(*,*): Write something on the screen Hello World (cont.) PROGRaM hello IMPLIcIT NONE WRITE(*,*) "Hello World!" END PROGRaM COMP208 Computers in Engr

  30. The Program Block PROGRAM hello IMPLICIT NONE !This is my first program WRITE (*,*) “Hello World!“ END PROGRAM hello The bold keywords tell the compiler where the program begins and ends. They bracket a section of code called a block Using uppercase is a convention to distinguish keywords. FORTRAN is case insensitive. PROGRAM, program, proGRAM, pRoGrAm are all the same. COMP208 Computers in Engr

  31. The Program Block in General Syntax for the program block PROGRAM program-name IMPLICIT NONE {declarations} {statements} {subprograms} END PROGRAM program-name COMP208 Computers in Engr

  32. Some specific facts about codes • White space insensitive • WRITE(*,*) “Hello world!” • WRITE (*, *) “Hello world!” • W RITE(*,*) “Hello world!”  compile error • case insensitive • WRITE(*,*) “Hello world!” • write(*,*) “Hello world!” • Note: These two facts only for codes, not for data • WRITE(*,*) “Hello world!” • WRITE(*,*) “HELLO W O RLD !” same same Different COMP208 Computers in Engr

More Related