Programming getting started
This presentation is the property of its rightful owner.
Sponsored Links
1 / 26

Programming Getting started PowerPoint PPT Presentation


  • 81 Views
  • Uploaded on
  • Presentation posted in: General

Programming Getting started. A computer program is a set of statements or instructions to be used directly or indirectly in a computer in order to bring about a certain result There are many languages that can be used to program a computer.

Download Presentation

Programming Getting started

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

ProgrammingGetting started

  • A computer program is a set of statements or instructions to be used directly or indirectly in a computer in order to bring about a certain result

  • There are many languages that can be used to program a computer.

    • Machine language (program written for one type of computers)

    • High-level language (general-purpose language, compatible with human language)


Programming getting started

There are three basic steps

  • A set of information, called the input data, is entered into the computer and stored.

  • The input data is then processed to produce certain desired results, known as the output data.

  • The output data are printed or displayed or saved on the computer.


Programming getting started

Example: write the required steps to calculate the area of a circle using πr2, given a numerical value for the radius r as input data

  • Read the numerical value for the radius of the circle

  • Calculate the value of the area using the given formula.

  • Print (display) the values of the radius and the corresponding area.

  • Stop


What you need to know is

What you need to know is:

  • Reading input…….

  • Displaying output …..

  • Processing data (Branching, looping, functions, subroutines….)

  • Processing a program


Operators

Operators

+ Addition

- Subtraction

* Multiplication

/ Division


Commands

Commands


Programming getting started

' {$STAMP BS2}

' {$PBASIC 2.5}

x VAR Byte

x=65

DEBUG "hello",CR

'DEBUG ? x

'DEBUG DEC x, CR

'DEBUG IBIN x,CR

'DEBUG IHEX x, CR

END

Run


Write a simple program to calculate the area and the perimeter of a 8x 4 rectangle

Write a simple program to calculate the area and the perimeter of a 8x 4 rectangle

  • Read the numerical value for the length and the width of the rectangle

  • Calculate the value of the area using the given formula.

  • Print (display) the values of the radius and the corresponding area.

  • Stop


Programming getting started

Start

Read l & W

Calculate

Area and Perimeter

Print area and perimeter

Stop


Programming getting started

length CON 8

width CON 4

area CON length*width

perimeter CON length+width* 2

DEBUG CR, “area= “

BEBUG DEC area

DEBUG CR, “perimeter= “

Debug DEC perimeter

END


Looping

Looping

  • Looping involves repeating some portion of the program either a specified number of times or until some particular condition has been satisfied

  • Do loop

  • For Next

  • Goto


Programming getting started

DO- LOOP: let a program execute a series of instructions indefinitely or until a specific condition terminates the loop.

DO

DEBUG “Hello”, CR

Loop


Programming getting started

  • DO-WHILE

    The program will not run if the condition is not satisfied.

    Length=15

    Height=4

    DO WHILE (height<10)

    area=length*height

    height= height+1

    loop


Programming getting started

' {$STAMP BS2}

' {$PBASIC 2.5}

length CON 15

height VAR Byte

height=4

area VAR Word

DO WHILE (height<10)

area=length*height

height=hight+1

LOOP

DEBUG DEC area


Programming getting started

  • DO-UNTIL

    The program will run until the condition is satisfied.

    Length=15

    Height=4

    DO

    area=length*height

    height= height+1

    Loop until (height=10)


Programming getting started

' {$STAMP BS2}

' {$PBASIC 2.5}

length CON 15

height VAR Byte

height=4

area VAR Word

DO

area=length*height

height=hight+1

DEBUG DEC area

Loop Until (height=10)


Programming getting started

  • FOR-NEXT

    Execute the statements between FOR and NEXT until the value of the counter passes the end value

    For height=6 to 10

    Length=10

    area=length*height

    Next


Programming getting started

' {$STAMP BS2}

' {$PBASIC 2.5}

length CON 15

height VAR Byte

area VAR Word

FOR height =6 TO 10

area=length*height

DEBUG DEC area, CR

NEXT


Programming getting started

Start

DO

Read r

Calculate

a

Print a and r

loop

Yes

NO

Stop


If then

IF-THEN

  • IF condition is trueTHEN(execute the following statement (s))

    IF x<20 Then

    area =x*y

  • IFcondition is trueTHEN

    (execute the following statement (s))

    ELSE

    (execute the following statement (s))


Programming getting started

  • IFcondition is trueTHEN

    (execute the following statement (s))

    ELSEIF condition is trueTHEN

    execute the following statement (s))

    ENDIF


Subroutines

Subroutines

  • To avoid repeated programming of the same calculations

  • Subroutines can be referenced (called) from other places in the program

  • GOSUB is used to redirect the program to the subroutine

  • RETURN causes the program to jump back to the line of code that follows the calling GOSUB


Example

Example

Main:

GOSUB Hello

GOSUB Goodbye

Hello:

DEBUG ”Hello There”, CR

RETURN

Goodbye:

DEBUG “Bye now”, CR

RETURN


Ascii code

ASCII Code

  • ASCII is acronym for the for American Standard Code for Information Interchange (Pronounced ask-ee ).

  • ASCII is a code for representing English characters as numbers, with each letter assigned a number from 0 to 127.

  • For example, the ASCII code for uppercaseM is 77.

  • Most computers use ASCII codes to represent text, which makes it possible to transfer data from one computer to another.


  • Login