Advertisement
/ 15 []

Programming


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

Download Presentation

Programming HSPM J713 Programming languages and systems

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 only and may not be sold or licensed nor shared on other sites. SlideServe reserves the right to change this policy at anytime.While downloading, If for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.











- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -




Presentation Transcript


Programming l.jpg

Programming

HSPM J713


Programming languages and systems l.jpg

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.


Platform specific l.jpg

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


Assembly language l.jpg

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


Fortran l.jpg

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 1950’s.

Designed for math


Basic l.jpg

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


Basic unstructured interpreted l.jpg

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


Basic structured compiled l.jpg

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$ <> ""

Answer$ = LEFT$(Answer$, 1)

LOOP WHILE UCASE$(Answer$) = "Y"

PRINT "Goodbye "; UserName$


Slide9 l.jpg

C, C++

  • This Hello world program uses the C++ standard library stream facility to write a message to standard output:

    #include <iostream> // provides std::cout

    int main() {

    std::cout << "Hello, world!\n";

    }

    Uses “library” of code, callable with key words, to execute complex tasks

    Compiler for specific platform translates that into machine code.


Slide10 l.jpg

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 PC’s, Macintosh virtual machine on Macs, for example.

  • So compiled Java code can run on many platforms. Good for web applications.


Java resembles c in syntax l.jpg

Java resembles C in syntax

Class HelloWorld {

public static void main (String[] arguments) {

System.out.println(“Hello World!”);

}

}

Compiled using Java Development Kit


Java uses objects l.jpg

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();

if (value == 15) {

Reply.setText("Correct! 15 is right!");

}

else {

if (value > 15) Reply.setText(Entry.getText()+" is too high.");

if (value < 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);

}

}

Textentry example


Java uses objects13 l.jpg

Java uses objects

import java.applet.*;

import java.awt.*;

public class TextEntry extends Applet {

TextField Reply;

TextField Entry;

}


Java uses objects14 l.jpg

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);

}

}


Java uses objects15 l.jpg

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 > 15) Reply.setText(Entry.getText()+" is too high.");

if (value < 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);

}

}