Lecture II Basic computer and programming concepts - PowerPoint PPT Presentation

About This Presentation
Title:

Lecture II Basic computer and programming concepts

Description:

Windows XP, Linux, Microsoft Office, Internet Browser ... Hardward ... Sun: Sparc) High level language (e.g., Fortran, C, Cobol) Very high level language ... – PowerPoint PPT presentation

Number of Views:122
Avg rating:3.0/5.0
Slides: 34
Provided by: stude805
Category:

less

Transcript and Presenter's Notes

Title: Lecture II Basic computer and programming concepts


1
Lecture II Basic computer and programming concepts
  • Yi Lin
  • Jan 09, 2007

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
3
Computer
Windows XP, Linux, Microsoft Office, Internet
Browser
Software
Pentium 4 CPU, AMD, 512 MB DDR memory, 19 inch
LCD, Keyboard,
Hardward
4
Computer Hardware
  • Von Neumann model
  • FETCH and EXECUTE

Command 1
processor
5
Computer Hardware
Keyboard
Hard Disk
Memory
BUS
Monitor Printer
Cache
Register
CPU
6
The 5 Classic Components
Computer
CPU
Memory
Control
Input Devices
Registers
Output Devices
7
Input / Ouput
Output
Input
Those are only the ones I came up with when I
wrote this slide
8
Computer Software (program)
  • A program is 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,

9
Different natural languages
Wie geht es Ihnen?
How are you?
And more
Comment allez-vous?
????
10
Different programming languages
C
C
C
Assembly (Intel8086, Motorola68000)
Machine language
And more
Fortran
Java
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
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

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

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

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.

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.

17
Lets startA simplest Fortran program
18
Hello World!
PROGRaM hello IMPLIcIT NONE WRITE(,) "Hello
World!" END PROGRaM
HelloWorld.f90
  • Edit
  • any text editor, e.g., SciTE, Notepad,
  • Or IDE (Integrated Development Environment),
    e.g., Visual Fortran

19
Hello World (cont.)
  • Edit (open a scite editor)
  • compile
  • Fortran ? Machine Language
  • Scite menu Tools-gtcompile (CtrlF7)
  • Link (not necessary for simple programs)
  • Linking libraries used in the program
  • Run
  • Scite menu Tools -gtgo (F5)
  • Output Hello World!

Repeat Until succeed
20
Hello World (cont.)
  • PROGRaM hello
  • IMPLIcIT NONE
  • WRITE(,) "Hello World!"
  • END PROGRaM

21
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.

22
The Program Block in General
  • Syntax for the program block
  • PROGRAM program-name
  • IMPLICIT NONE
  • declarations
  • statements
  • subprograms
  • END PROGRAM program-name

23
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
24
A simple example Roots finding
  • Finding roots for quadratic
  • aX2bXc0
  • Input a, b, c
  • Output root(s)
  • (-b SQRT(bb - 4ac))/(2a)
  • (-b - SQRT(bb - 4ac))/(2a)

25
Roots finding (cont.)
start
Initialize a1, b-5, c6
w (bb 4ac)
R1 (-b sqrt(w))/(2a) R2 (-b -
sqrt(w))/(2a)
End
26
Roots finding (cont.)
  • PROGRAM ROOTSFINDING
  • INTEGER a, b, c
  • REAL x, y, z, w, r1, r2
  • a1
  • b-5
  • c6
  • ! To calculate bb 4ac
  • x bb
  • y ac
  • z 4y
  • w x-z
  • r1 (-b SQRT(w))/(2a)
  • r2 (-b SQRT(w))/(2a)
  • WRITE(, ) r1, r2
  • END PROGRAM

27
Roots finding (cont.)
  • PROGRAM ROOTSFINDING
  • INTEGER a, b, c
  • REAL x, y, z, w, r1, r2
  • a1
  • b-5
  • c6
  • ! To calculate bb 4ac
  • x bb
  • y ac
  • z 4y
  • w x-z
  • r1 (-b SQRT(w))/(2a)
  • r2 (-b SQRT(w))/(2a)
  • WRITE(, ) r1, r2
  • END PROGRAM

28
Variables and constants
  • Constants (e.g., 1, -5, 6, 4, 2)
  • A variable (e.g., a, b, c, x, y, z, w) is a
    unique name which a FORTRAN program applies to a
    word of memory and uses to refer to it.
  • Naming convention
  • alphanumeric characters (letters, numerals and
    the underscore character)
  • The first character must be a letter.
  • No case sensitivity
  • Dont use keywords in Fortran as variables names

29
Variable data types
  • INTEGER
  • E.g., a, b, c
  • REAL
  • E.g., x, y, z, w
  • LOGICAL
  • COMPLEX
  • CHARACTER
  • Examples
  • Data type is important
  • INTEGERa1,b-5,c5
  • INTEGER r1, r2
  • IMPLICIT NONE needed to prevent errors.
  • Comment out IMPLICIT NONE
  • write(, ) r1, r3

30
Declarations
  • PROGRAM RootFinding
  • IMPLICIT NONE
  • INTEGER a, b, c
  • REAL x,y,z,w
  • REAL r1, r2
  • . . .
  • END PROGRAM RootFinding
  • Declarations tell the compiler
  • To allocate space in memory for a variable
  • What shape the memory cell should be (i.e. what
    type of value is to be placed there)
  • What name we will use to refer to that cell

31
Declare variables
  • INTEGER a, b, c
  • REAL x, y, z, w
  • A1
  • B-5
  • C6

same
32
Variable precision
1 byte 8 bits
  • INTEGER(KIND2)a OR INTEGER(2)a

11111111
KIND BITs Value range
1 8 -27 lt a lt 27 (i.e., 128)
2 16 -215 lt a lt 215 (i.e., 32767)
4(default) 32 -231 lt a lt 231
8 64 -263 lt a lt 263
33
Variable precision (cont.)
KIND BITs
4(default) 32
8(equivalent to DOUBLE PRECISION) 64
16 816
  • REAL(KIND4)
  • CHARACTER
  • KIND1 only
Write a Comment
User Comments (0)
About PowerShow.com