1 / 26

Programming Getting started

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.

len
Télécharger la présentation

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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

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

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

  4. What you need to know is: • Reading input……. • Displaying output ….. • Processing data (Branching, looping, functions, subroutines….) • Processing a program

  5. Operators + Addition - Subtraction * Multiplication / Division

  6. Commands

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

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

  9. Start Read l & W Calculate Area and Perimeter Print area and perimeter Stop

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

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

  12. DO- LOOP: let a program execute a series of instructions indefinitely or until a specific condition terminates the loop. DO DEBUG “Hello”, CR Loop

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

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

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

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

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

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

  19. Start DO Read r Calculate a Print a and r loop Yes NO Stop

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

  21. IFcondition is trueTHEN (execute the following statement (s)) ELSEIF condition is trueTHEN execute the following statement (s)) ENDIF

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

  23. Example Main: GOSUB Hello GOSUB Goodbye Hello: DEBUG ”Hello There”, CR RETURN Goodbye: DEBUG “Bye now”, CR RETURN

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

More Related