CSCI130 - PowerPoint PPT Presentation

1 / 15
About This Presentation
Title:

CSCI130

Description:

Properties: status, color, model, make, year, manual/auto ... Tailor office applications. Can be used to link many applications together. Visually oriented ... – PowerPoint PPT presentation

Number of Views:35
Avg rating:3.0/5.0
Slides: 16
Provided by: imadr
Category:

less

Transcript and Presenter's Notes

Title: CSCI130


1
Lecture-10 (6.1-6.6)
  • CSCI130
  • Instructor Dr. Imad Rahal

2
Higher-level Programming Languages (PLs)
  • Solution to Assignment 3 and class exercise is up
  • Exam Chapters 1?5
  • Exam policy
  • Machine language programming
  • limited set of instructions
  • binary numbers
  • opcodes, absolute memory addresses and data
  • Assembly language
  • English mnemonics for binary opcodes
  • Variables for memory addresses
  • limited instruction set
  • Use human languages to program
  • Large vocabulary (space and time to search)
    opcode lookup
  • Synonyms
  • Homonyms
  • Context

3
Higher-level Programming Languages
  • High-level languages are in the middle
  • Use English-like phrases and mathematical
    notation
  • x x1
  • Do it in assembly?
  • A limited vocabulary with precise meaning
  • Make us think at a higher-level of abstraction
  • No attention to technical and hardware details
  • Like O.S.
  • Does not matter if we have a CISC or RISC
    architecture
  • Much larger instruction set for programmers
  • Multiplication

4
Translation Programs
  • Price for abstraction!
  • Unaware of hardware/low-level details
  • Higher-level require translation programs
  • An example?
  • Assembler for assembly
  • Fast
  • Must be translated to machine language
  • It is not trivial as with assembly
  • No 1-to-1 correspondence

5
Find the Larger of Two Numbers
  • READ
  • STOR X
  • READ
  • STOR Y
  • SUB X
  • JPOS Y_LARGER
  • LOAD X
  • WRITE
  • HALT
  • Y_LARGERLOAD Y
  • WRITE
  • HALT
  • X 0
  • Y 0
  • In higher-level programming languages, we could
    simply say (4 V.S. 14)
  • Read x
  • Read Y
  • If XgtY, WRITE X
  • Else, WRITE Y

6
Show All Numbers Between 1 and N
  • READ
  • STOR N
  • LOOP LOAD COUNT
  • ADD VALUE_ONE
  • STOR COUNT
  • WRITE
  • LOAD N
  • SUB COUNT
  • JPOS LOOP
  • HALT
  • N 0
  • COUNT 0
  • VALUE_ONE 1
  • Read N (4 V.S. 13)
  • For i1 to N
  • Write i
  • Loop

7
Translation Programs
  • Source code (high-level language) ? object code
    (machine language)
  • An interpreter does so on a line by line basis
  • Redone every time
  • Dont have to wait for whole program to be
    translated to see output
  • A compiler produces all object code for the given
    source code
  • Done once to produce object code
  • Must weight
  • Read about them in book

8
Algorithms Design
  • For the same problem we can have
  • Many algorithms to solve it
  • Count from 1 to N
  • If counter lt N ? loop (or redo)
  • If counter gt N ? stoop
  • Each implemented through many programs
  • Plan to solve a problem vs actual solution in a
    language understood by the computer
  • We need to design a clear algorithm
  • Pseudo-code (or Flow chart)
  • Compromise between English and programming
    language
  • Omits details
  • Gradual
  • Not likely to get it the first time

9
Algorithms Design
  • Finding the minimum in a list of numbers
  • 1-Find the minimum in 1st portion of the list, S1
  • 2-Find the minimum in the next portion of the
    list, S2
  • 3-Let S be the minimum of S1 and S2
  • 4-Repeat steps 2 and 3 until all portions have
    been covered
  • 5-S has the minimum
  • What is a portion? How do we get it?
  • We need more details
  • We can assume every position in the list to be a
    portion

10
Algorithms Design
  • Psuedocode
  • S first number in list
  • Do until end of list
  • S next number in list
  • If S gt S, then S S
  • Output S
  • Omitted details (depend on the programming
    language)
  • What is a list?
  • How to know the end of list?
  • Ho to go to the next number?
  • Now we have an algorithm, but is it right?
  • We need to test it

11
Algorithms Design
  • We usually test by tracing
  • Use some values to work thru the algorithm
  • 3 23 44 2 12 42 1
  • S S Output3 23 3 44 3 22 122 422 1 1

12
Computer Programming
  • Different types of high-level languages
  • The imperative programming paradigm
  • Machine language/assembly language
  • A program is a sequence of instructions
  • Object-oriented paradigm
  • Visual Basic or VB uses the OOP
  • Objects each having properties and functions
  • e.g. car or rabbit
  • Properties status, color, model, make, year,
    manual/auto
  • Actions turn on, speeds up, slows down, make
    accident, hit rabbit
  • An action taken by an object might affect (change
    some property) itself or other objects
  • Affect itself turn on CAR
  • ? status went from OFF to ON
  • Affect other objects hit rabbit
  • ? Rabbit is dead but the car is still OK

13
Object-Oriented Programming
  • Imagine a computer screen with several icons
  • Each is a task (object?) also desktop is an
    object
  • Each task has its own attributes and functions
  • Properties Icon picture/shape and color
  • functions
  • Single-clicked ? Darken Color (itself)
  • Double-clicked ?
  • Run corresponding program
  • Change desktop look (Desktop is another object)
  • The program is collection of interacting objects
  • In VB, functions are triggered by events
  • Done by users (interactive) e.g. CLICK or
    DOUBLE_CLICK
  • Objects sharing properties/methods are grouped
    into classes
  • Object My Documents, My Computer
  • Class Desktop Icon

14
Steps in Writing a Program
  • Read In Book
  • Steps in Writing a Program
  • OO Applications Development

15
Introduction
  • Basic is an imperative language developed in
    1960s
  • Visual Basic (VB) --- developed by Microsoft
  • OO version of Basic
  • Underlying ALL MS office programs
  • You could do a lot
  • Write your own programs
  • Tailor office applications
  • Can be used to link many applications together
  • Visually oriented
  • Programs have a GUI for input/output
  • Not a command prompt
  • First thing to do to build a VB program is to
    design the interface
Write a Comment
User Comments (0)
About PowerShow.com