Loading in 5 sec....

Programming Getting startedPowerPoint Presentation

Programming Getting started

- By
**len** - Follow User

- 106 Views
- Uploaded on

Download Presentation
## PowerPoint Slideshow about ' Programming Getting started' - len

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

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)

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

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:

- Reading input…….
- Displaying output …..
- Processing data (Branching, looping, functions, subroutines….)
- Processing a program

' {$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

- 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

Start perimeter of a 8x 4 rectangle

Read l & W

Calculate

Area and Perimeter

Print area and perimeter

Stop

length CON 8 perimeter of a 8x 4 rectangle

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 perimeter of a 8x 4 rectangle

- 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

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

DO

DEBUG “Hello”, CR

Loop

- DO-WHILE perimeter of a 8x 4 rectangle
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

' {$STAMP BS2} perimeter of a 8x 4 rectangle

' {$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

- DO-UNTIL perimeter of a 8x 4 rectangle
The program will run until the condition is satisfied.

Length=15

Height=4

DO

area=length*height

height= height+1

Loop until (height=10)

' {$STAMP BS2} perimeter of a 8x 4 rectangle

' {$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)

- FOR-NEXT perimeter of a 8x 4 rectangle
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

' {$STAMP BS2} perimeter of a 8x 4 rectangle

' {$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

IF-THEN perimeter of a 8x 4 rectangle

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

- IF perimeter of a 8x 4 rectanglecondition is trueTHEN
(execute the following statement (s))

ELSEIF condition is trueTHEN

execute the following statement (s))

ENDIF

Subroutines perimeter of a 8x 4 rectangle

- 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 perimeter of a 8x 4 rectangle

Main:

GOSUB Hello

GOSUB Goodbye

Hello:

DEBUG ”Hello There”, CR

RETURN

Goodbye:

DEBUG “Bye now”, CR

RETURN

ASCII Code perimeter of a 8x 4 rectangle

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

Download Presentation

Connecting to Server..