Programming - PowerPoint PPT Presentation

1 / 15
About This Presentation
Title:

Programming

Description:

BASIC. Beginner's All-purpose Symbolic Instruction Code. For students and general users ... BASIC unstructured, interpreted. 10 INPUT 'What is your name: ... – PowerPoint PPT presentation

Number of Views:29
Avg rating:3.0/5.0
Slides: 16
Provided by: samb9
Category:

less

Transcript and Presenter's Notes

Title: Programming


1
Programming
  • HSPM J713

2
Programming languages and systems
  • Programming languages generally come with
    programming system
  • The language part of a programming language is
    the key words, symbols, and syntax used to write
    code.
  • The system part translates the written code into
    machine instructions that computer executes. Can
    be a compiler or an interpreter.

3
Platform-specific
  • Language system works with specific hardware
  • The IBM-compatible PC or the Windows PC
  • All use the same
  • Machine instructions (which depends on chip
    architecture)
  • Memory, screen

4
Assembly language
  • mov ax, 1234h
  • mov bx, ax
  • Directly translates into machine code (binary
    numbers)
  • Compiler translates all instructions in program
    into machine code
  • Low level explicitly manipulates registers
    (places to hold data) on the CPU chip.
  • Each chip has its own assembly language

5
FORTRAN
  • Do 10 j 2 , 1000
  • B(j) A(j-1)
  • A(j-1)j
  • 10 continue
  • Compiled into machine language and then run
  • Used on mainframes since 1950s.
  • Designed for math

6
BASIC
  • Beginner's All-purpose Symbolic Instruction Code
  • For students and general users
  • Interpreted One line at a time is translated
    into machine code and executed

7
BASIC unstructured, interpreted
  • 10 INPUT "What is your name ", U
  • 20 PRINT "Hello " U
  • 30 INPUT "How many stars do you want ", N
  • 40 S ""
  • 50 FOR I 1 TO N
  • 60 S S ""
  • 70 NEXT I
  • 80 PRINT S
  • 90 INPUT "Do you want more stars? ", A
  • 100 IF LEN(A) 0 THEN 90
  • 110 A LEFT(A, 1)
  • 120 IF A "Y" OR A "y" THEN 30
  • 130 PRINT "Goodbye "U
  • 140 END

8
BASIC structured, compiled
  • INPUT "What is your name ", UserName
  • PRINT "Hello " UserName
  • DO
  • INPUT "How many stars do you want ", NumStars
  • Stars STRING(NumStars, "")
  • PRINT Stars
  • DO
  • INPUT "Do you want more stars? ", Answer
  • LOOP UNTIL Answer ltgt ""
  • Answer LEFT(Answer, 1)
  • LOOP WHILE UCASE(Answer) "Y"
  • PRINT "Goodbye " UserName

9
C, C
  • This Hello world program uses the C standard
    library stream facility to write a message to
    standard output
  • include ltiostreamgt // provides stdcout
  • int main()
  • stdcout ltlt "Hello, world!\n"
  • Uses library of code, callable with key words,
    to execute complex tasks
  • Compiler for specific platform translates that
    into machine code.

10
Java
  • Compiled code runs on Virtual Machine
  • A virtual machine is written for each platform.
  • The virtual machine for a platform translates
    virtual machine instructions into machine
    instructions for that platform
  • Java runs on PC virtual machine on PCs,
    Macintosh virtual machine on Macs, for example.
  • So compiled Java code can run on many platforms.
    Good for web applications.

11
Java resembles C in syntax
  • Class HelloWorld
  • public static void main (String arguments)
  • System.out.println(Hello World!)
  • Compiled using Java Development Kit

12
Java uses objects
  • import java.applet.
  • import java.awt.
  • public class TextEntry extends Applet
  • TextField Reply
  • TextField Entry
  • public void init()
  • setBackground(Color.white)
  • add("EntryLabel", new Label("Type your number
    in the small box and press Enter"))
  • add("Entry", Entry new TextField("", 5))
  • add("Reply", Reply new TextField("My reply
    will appear here.", 60))
  • Reply.setEditable(false)
  • public void compute()
  • int value
  • try
  • value Integer.valueOf(Entry.getText().trim())
    .intValue()

13
Java uses objects
  • import java.applet.
  • import java.awt.
  • public class TextEntry extends Applet
  • TextField Reply
  • TextField Entry

14
Java uses objects
  • public class TextEntry extends Applet
  • TextField Reply
  • TextField Entry
  • public void init()
  • setBackground(Color.white)
  • add("EntryLabel", new Label("Type your number
    in the small box and press Enter"))
  • add("Entry", Entry new TextField("", 5))
  • add("Reply", Reply new TextField("My reply
    will appear here.", 60))
  • Reply.setEditable(false)

15
Java uses objects
  • public void compute()
  • int value
  • try
  • value Integer.valueOf(Entry.getText().trim())
    .intValue()
  • if (value 15) Reply.setText("Correct!
    15 is right!")
  • else
  • if (value gt 15) Reply.setText(Entry.getText()
    " is too high.")
  • if (value lt 15) Reply.setText(Entry.getText()
    " is too low.")
  • catch(NumberFormatException e)
    Reply.setText(Entry.getText() " is not a
    number.")
  • public boolean action(Event e, Object dummy)
  • compute()
  • return(true)
Write a Comment
User Comments (0)
About PowerShow.com